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

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 (62) hide show
  1. package/README.md +2 -0
  2. package/package.json +1 -1
  3. package/plugins/huaweicloud-core/.claude-plugin/plugin.json +1 -1
  4. package/plugins/huaweicloud-core/.codex-plugin/plugin.json +1 -1
  5. package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +1 -1
  6. package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +1 -1
  7. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
  8. package/plugins/huaweicloud-core/dist/agents/codearts-work.js +4 -0
  9. package/plugins/huaweicloud-core/dist/agents/codearts.js +4 -0
  10. package/plugins/huaweicloud-core/dist/agents/officeace-sqlite.js +14 -4
  11. package/plugins/huaweicloud-core/dist/agents/opencode-config.js +5 -1
  12. package/plugins/huaweicloud-core/dist/approvals-cli.js +159 -0
  13. package/plugins/huaweicloud-core/dist/auth/s1-store.js +43 -22
  14. package/plugins/huaweicloud-core/dist/hcloud-plan.js +26 -4
  15. package/plugins/huaweicloud-core/dist/hcloud-run.js +4 -1
  16. package/plugins/huaweicloud-core/dist/lib/approval-tokens.js +135 -16
  17. package/plugins/huaweicloud-core/dist/lib/approvals-pin.js +128 -0
  18. package/plugins/huaweicloud-core/dist/lib/pack-state.js +23 -19
  19. package/plugins/huaweicloud-core/dist/lib/param-warnings.js +70 -0
  20. package/plugins/huaweicloud-core/dist/lib/state-dir.js +125 -0
  21. package/plugins/huaweicloud-core/dist/mcp-server.js +877 -595
  22. package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
  23. package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +27 -9
  24. package/plugins/huaweicloud-core/dist/payload-runtime-deps.js +11 -3
  25. package/plugins/huaweicloud-core/dist/safety/classify-text.js +13 -0
  26. package/plugins/huaweicloud-core/dist/safety/policy.js +1 -0
  27. package/plugins/huaweicloud-core/dist/setup-cli.js +23 -0
  28. package/plugins/huaweicloud-core/dist/tool-schemas.js +15 -0
  29. package/plugins/huaweicloud-core/dist/tools.js +36 -4
  30. package/plugins/huaweicloud-core/dist/update-registry.js +8 -2
  31. package/plugins/huaweicloud-core/dist/update-skip.js +5 -6
  32. package/plugins/huaweicloud-core/dist/update-upgrade.js +8 -1
  33. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +20 -1
  34. package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
  35. package/plugins/huaweicloud-core/safety/policy.json +8 -0
  36. package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +78 -2
  37. package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +4 -1
  38. package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +13 -6
  39. package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +47 -0
  40. package/plugins/huaweicloud-core/src/agents/codearts-work.ts +3 -0
  41. package/plugins/huaweicloud-core/src/agents/codearts.ts +4 -0
  42. package/plugins/huaweicloud-core/src/agents/officeace-sqlite.ts +14 -4
  43. package/plugins/huaweicloud-core/src/agents/opencode-config.ts +5 -1
  44. package/plugins/huaweicloud-core/src/approvals-cli.ts +187 -0
  45. package/plugins/huaweicloud-core/src/auth/s1-store.ts +41 -20
  46. package/plugins/huaweicloud-core/src/hcloud-plan.ts +44 -5
  47. package/plugins/huaweicloud-core/src/hcloud-run.ts +4 -1
  48. package/plugins/huaweicloud-core/src/lib/approval-tokens.ts +197 -16
  49. package/plugins/huaweicloud-core/src/lib/approvals-pin.ts +153 -0
  50. package/plugins/huaweicloud-core/src/lib/pack-state.ts +23 -20
  51. package/plugins/huaweicloud-core/src/lib/param-warnings.ts +69 -0
  52. package/plugins/huaweicloud-core/src/lib/state-dir.ts +128 -0
  53. package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +29 -9
  54. package/plugins/huaweicloud-core/src/payload-runtime-deps.ts +11 -3
  55. package/plugins/huaweicloud-core/src/safety/classify-text.ts +15 -0
  56. package/plugins/huaweicloud-core/src/safety/policy.ts +2 -0
  57. package/plugins/huaweicloud-core/src/setup-cli.ts +28 -0
  58. package/plugins/huaweicloud-core/src/tool-schemas.ts +16 -0
  59. package/plugins/huaweicloud-core/src/tools.ts +39 -4
  60. package/plugins/huaweicloud-core/src/update-registry.ts +8 -2
  61. package/plugins/huaweicloud-core/src/update-skip.ts +5 -6
  62. package/plugins/huaweicloud-core/src/update-upgrade.ts +8 -1
@@ -8539,7 +8539,7 @@ function isRef(value) {
8539
8539
  function cloneIssues(issues) {
8540
8540
  return issues.map((iss) => iss.path ? { ...iss, path: iss.path.slice() } : { ...iss });
8541
8541
  }
8542
- function isRecursive(inst, stack, resolve9) {
8542
+ function isRecursive(inst, stack, resolve10) {
8543
8543
  const cached2 = recursive.get(inst);
8544
8544
  if (cached2 !== void 0)
8545
8545
  return cached2 ? PROVEN : NONE;
@@ -8549,7 +8549,7 @@ function isRecursive(inst, stack, resolve9) {
8549
8549
  let result = NONE;
8550
8550
  const check2 = (child) => {
8551
8551
  if (result !== PROVEN && child?._zod) {
8552
- const answer = isRecursive(child, stack, resolve9);
8552
+ const answer = isRecursive(child, stack, resolve10);
8553
8553
  if (answer > result)
8554
8554
  result = answer;
8555
8555
  }
@@ -8560,7 +8560,7 @@ function isRecursive(inst, stack, resolve9) {
8560
8560
  const desc = Object.getOwnPropertyDescriptor(sh, key);
8561
8561
  if (spread && !desc.enumerable)
8562
8562
  continue;
8563
- const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve9) : NONE;
8563
+ const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve10) : NONE;
8564
8564
  if (child > answer)
8565
8565
  answer = child;
8566
8566
  }
@@ -8624,7 +8624,7 @@ function isRecursive(inst, stack, resolve9) {
8624
8624
  break;
8625
8625
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
8626
8626
  case "lazy": {
8627
- const inner = def._cachedInner ?? (resolve9 ? inst._zod.innerType : void 0);
8627
+ const inner = def._cachedInner ?? (resolve10 ? inst._zod.innerType : void 0);
8628
8628
  merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
8629
8629
  break;
8630
8630
  }
@@ -28419,7 +28419,7 @@ var init_protocol = __esm({
28419
28419
  return;
28420
28420
  }
28421
28421
  const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
28422
- await new Promise((resolve9) => setTimeout(resolve9, pollInterval));
28422
+ await new Promise((resolve10) => setTimeout(resolve10, pollInterval));
28423
28423
  options?.signal?.throwIfAborted();
28424
28424
  }
28425
28425
  } catch (error62) {
@@ -28436,7 +28436,7 @@ var init_protocol = __esm({
28436
28436
  */
28437
28437
  request(request, resultSchema, options) {
28438
28438
  const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
28439
- return new Promise((resolve9, reject) => {
28439
+ return new Promise((resolve10, reject) => {
28440
28440
  const earlyReject = (error62) => {
28441
28441
  reject(error62);
28442
28442
  };
@@ -28514,7 +28514,7 @@ var init_protocol = __esm({
28514
28514
  if (!parseResult.success) {
28515
28515
  reject(parseResult.error);
28516
28516
  } else {
28517
- resolve9(parseResult.data);
28517
+ resolve10(parseResult.data);
28518
28518
  }
28519
28519
  } catch (error62) {
28520
28520
  reject(error62);
@@ -28776,12 +28776,12 @@ var init_protocol = __esm({
28776
28776
  }
28777
28777
  } catch {
28778
28778
  }
28779
- return new Promise((resolve9, reject) => {
28779
+ return new Promise((resolve10, reject) => {
28780
28780
  if (signal.aborted) {
28781
28781
  reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
28782
28782
  return;
28783
28783
  }
28784
- const timeoutId = setTimeout(resolve9, interval);
28784
+ const timeoutId = setTimeout(resolve10, interval);
28785
28785
  signal.addEventListener("abort", () => {
28786
28786
  clearTimeout(timeoutId);
28787
28787
  reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
@@ -31808,7 +31808,7 @@ var require_compile = __commonJS({
31808
31808
  const schOrFunc = root.refs[ref];
31809
31809
  if (schOrFunc)
31810
31810
  return schOrFunc;
31811
- let _sch = resolve9.call(this, root, ref);
31811
+ let _sch = resolve10.call(this, root, ref);
31812
31812
  if (_sch === void 0) {
31813
31813
  const schema = (_a3 = root.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
31814
31814
  const { schemaId } = this.opts;
@@ -31835,7 +31835,7 @@ var require_compile = __commonJS({
31835
31835
  function sameSchemaEnv(s1, s2) {
31836
31836
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
31837
31837
  }
31838
- function resolve9(root, ref) {
31838
+ function resolve10(root, ref) {
31839
31839
  let sch;
31840
31840
  while (typeof (sch = this.refs[ref]) == "string")
31841
31841
  ref = sch;
@@ -32699,7 +32699,7 @@ var require_fast_uri = __commonJS({
32699
32699
  }
32700
32700
  return uri;
32701
32701
  }
32702
- function resolve9(baseURI, relativeURI, options) {
32702
+ function resolve10(baseURI, relativeURI, options) {
32703
32703
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
32704
32704
  const {
32705
32705
  parsed: baseParsed,
@@ -33090,7 +33090,7 @@ var require_fast_uri = __commonJS({
33090
33090
  var fastUri = {
33091
33091
  SCHEMES,
33092
33092
  normalize,
33093
- resolve: resolve9,
33093
+ resolve: resolve10,
33094
33094
  resolveComponent,
33095
33095
  equal,
33096
33096
  serialize,
@@ -38881,7 +38881,7 @@ var require_compile2 = __commonJS({
38881
38881
  const schOrFunc = root.refs[ref];
38882
38882
  if (schOrFunc)
38883
38883
  return schOrFunc;
38884
- let _sch = resolve9.call(this, root, ref);
38884
+ let _sch = resolve10.call(this, root, ref);
38885
38885
  if (_sch === void 0) {
38886
38886
  const schema = (_a3 = root.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
38887
38887
  const { schemaId } = this.opts;
@@ -38908,7 +38908,7 @@ var require_compile2 = __commonJS({
38908
38908
  function sameSchemaEnv(s1, s2) {
38909
38909
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
38910
38910
  }
38911
- function resolve9(root, ref) {
38911
+ function resolve10(root, ref) {
38912
38912
  let sch;
38913
38913
  while (typeof (sch = this.refs[ref]) == "string")
38914
38914
  ref = sch;
@@ -42943,7 +42943,7 @@ var init_mcp = __esm({
42943
42943
  let task = createTaskResult.task;
42944
42944
  const pollInterval = task.pollInterval ?? 5e3;
42945
42945
  while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
42946
- await new Promise((resolve9) => setTimeout(resolve9, pollInterval));
42946
+ await new Promise((resolve10) => setTimeout(resolve10, pollInterval));
42947
42947
  const updatedTask = await extra.taskStore.getTask(taskId);
42948
42948
  if (!updatedTask) {
42949
42949
  throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
@@ -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")
@@ -44469,13 +44470,13 @@ function windowsScriptArgAtRaw(args, idx) {
44469
44470
  return null;
44470
44471
  const payloadOf = (j2, glued) => {
44471
44472
  const strip = (s) => s.replace(/^['"]|['"]$/g, "");
44472
- const resolve9 = (s) => s.replace(/\\"/g, '"').replace(/\\\\/g, "\\");
44473
+ const resolve10 = (s) => s.replace(/\\"/g, '"').replace(/\\\\/g, "\\");
44473
44474
  const rest = args.slice(j2 + 1).map(String);
44474
44475
  if (glued !== null) {
44475
44476
  const g = strip(glued);
44476
- return resolve9(rest.length ? `${g} ${rest.join(" ")}` : g);
44477
+ return resolve10(rest.length ? `${g} ${rest.join(" ")}` : g);
44477
44478
  }
44478
- return rest.length ? resolve9(rest.join(" ")) : null;
44479
+ return rest.length ? resolve10(rest.join(" ")) : null;
44479
44480
  };
44480
44481
  if (isCmd) {
44481
44482
  for (let j2 = idx + 1; j2 < args.length; j2++) {
@@ -44501,8 +44502,8 @@ function windowsScriptArgAtRaw(args, idx) {
44501
44502
  return payloadOf(j2, null);
44502
44503
  const attached = m[2].replace(/^['"]|['"]$/g, "");
44503
44504
  const rest = args.slice(j2 + 1).map(String);
44504
- const resolve9 = (s) => s.replace(/\\"/g, '"').replace(/\\\\/g, "\\");
44505
- return resolve9(rest.length ? `${attached} ${rest.join(" ")}` : attached);
44505
+ const resolve10 = (s) => s.replace(/\\"/g, '"').replace(/\\\\/g, "\\");
44506
+ return resolve10(rest.length ? `${attached} ${rest.join(" ")}` : attached);
44506
44507
  }
44507
44508
  }
44508
44509
  let j = idx + 1;
@@ -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",
@@ -47376,6 +47384,187 @@ var init_invoke_value = __esm({
47376
47384
  }
47377
47385
  });
47378
47386
 
47387
+ // plugins/huaweicloud-core/dist.new/lib/state-dir.js
47388
+ import { existsSync as existsSync9, lstatSync, mkdirSync as mkdirSync3, rmSync as rmSync2 } from "node:fs";
47389
+ import { homedir as homedir8 } from "node:os";
47390
+ import { dirname as dirname7, isAbsolute, join as join9, resolve } from "node:path";
47391
+ function huaweiConfigBase(env = process.env) {
47392
+ return resolve(env.HUAWEICLOUD_HOME || homedir8(), ".config", "huaweicloud");
47393
+ }
47394
+ function agentHomeBase(env) {
47395
+ return resolve(env.HUAWEICLOUD_HOME || homedir8());
47396
+ }
47397
+ function nearestExisting(path) {
47398
+ let current = resolve(path);
47399
+ for (; ; ) {
47400
+ try {
47401
+ lstatSync(current);
47402
+ return current;
47403
+ } catch {
47404
+ const parent = dirname7(current);
47405
+ if (parent === current)
47406
+ return null;
47407
+ current = parent;
47408
+ }
47409
+ }
47410
+ }
47411
+ function probeWritableDir(path) {
47412
+ const anchor2 = nearestExisting(path);
47413
+ if (!anchor2)
47414
+ return false;
47415
+ const probe = join9(anchor2, `.devkit-write-probe-${process.pid}-${Math.random().toString(36).slice(2)}`);
47416
+ try {
47417
+ mkdirSync3(probe, { mode: 448 });
47418
+ return true;
47419
+ } catch {
47420
+ return false;
47421
+ } finally {
47422
+ try {
47423
+ rmSync2(probe, { recursive: true, force: true });
47424
+ } catch {
47425
+ }
47426
+ }
47427
+ }
47428
+ function codeArtsStateBase(env) {
47429
+ const home = agentHomeBase(env);
47430
+ for (const marker of AGENT_STATE_MARKERS) {
47431
+ const root = join9(home, marker);
47432
+ if (!existsSync9(root) || !probeWritableDir(root))
47433
+ continue;
47434
+ return join9(root, "devkit-state");
47435
+ }
47436
+ return null;
47437
+ }
47438
+ function explicitStateBase(env) {
47439
+ const value = (env[STATE_DIR_ENV] ?? "").trim();
47440
+ if (value === "")
47441
+ return null;
47442
+ if (!isAbsolute(value)) {
47443
+ throw new Error(`${STATE_DIR_ENV} must be an absolute path (got "${value}"): the CLI and the MCP server resolve relative paths against different working directories.`);
47444
+ }
47445
+ return resolve(value);
47446
+ }
47447
+ function devkitStateBase(env = process.env) {
47448
+ const explicit = explicitStateBase(env);
47449
+ if (explicit)
47450
+ return explicit;
47451
+ const configBase2 = huaweiConfigBase(env);
47452
+ const cached2 = stateBaseCache.get(configBase2);
47453
+ if (cached2)
47454
+ return cached2;
47455
+ const stateBase = probeWritableDir(configBase2) ? configBase2 : codeArtsStateBase(env) ?? configBase2;
47456
+ stateBaseCache.set(configBase2, stateBase);
47457
+ return stateBase;
47458
+ }
47459
+ var STATE_DIR_ENV, AGENT_STATE_MARKERS, stateBaseCache;
47460
+ var init_state_dir = __esm({
47461
+ "plugins/huaweicloud-core/dist.new/lib/state-dir.js"() {
47462
+ "use strict";
47463
+ STATE_DIR_ENV = "HUAWEICLOUD_STATE_DIR";
47464
+ AGENT_STATE_MARKERS = [".codearts", ".codeartswork", ".codeartsdoer"];
47465
+ stateBaseCache = /* @__PURE__ */ new Map();
47466
+ }
47467
+ });
47468
+
47469
+ // plugins/huaweicloud-core/dist.new/lib/pack-state.js
47470
+ import { chmodSync, lstatSync as lstatSync2, mkdirSync as mkdirSync4, realpathSync, writeFileSync as writeFileSync3 } from "node:fs";
47471
+ import { tmpdir } from "node:os";
47472
+ import { basename as basename2, dirname as dirname8, join as join10, resolve as resolve2, sep } from "node:path";
47473
+ function packStateDir(packId, env = process.env) {
47474
+ return join10(devkitStateBase(env), "packs", packId);
47475
+ }
47476
+ function ensurePackState(packId, fileNames, env = process.env) {
47477
+ const dir = packStateDir(packId, env);
47478
+ try {
47479
+ mkdirSync4(dir, { recursive: true, mode: 448 });
47480
+ chmodSync(dir, 448);
47481
+ } catch (error62) {
47482
+ throw new Error(`cannot provision pack state directory "${dir}": ${error62 instanceof Error ? error62.message : String(error62)}. Fix the permissions, or point HUAWEICLOUD_HOME at a writable location.`, { cause: error62 });
47483
+ }
47484
+ const files = {};
47485
+ for (const name of fileNames) {
47486
+ const path = join10(dir, name);
47487
+ try {
47488
+ try {
47489
+ writeFileSync3(path, "", { flag: "wx", mode: 384 });
47490
+ } catch (error62) {
47491
+ if (error62.code !== "EEXIST")
47492
+ throw error62;
47493
+ }
47494
+ chmodSync(path, 384);
47495
+ files[name] = path;
47496
+ } catch (error62) {
47497
+ throw new Error(`cannot provision pack state file "${path}": ${error62 instanceof Error ? error62.message : String(error62)}.`, { cause: error62 });
47498
+ }
47499
+ }
47500
+ return { dir, files };
47501
+ }
47502
+ function isRefusedByGuard(target) {
47503
+ if (process.platform === "win32" && /^[a-zA-Z]:[^\\/]/.test(target))
47504
+ return true;
47505
+ return target.split(/[\\/]/).includes("..");
47506
+ }
47507
+ function resolveForWrite(target) {
47508
+ const absolute = resolve2(tmpdir(), target);
47509
+ const tail = [];
47510
+ let current = absolute;
47511
+ for (; ; ) {
47512
+ try {
47513
+ lstatSync2(current);
47514
+ break;
47515
+ } catch {
47516
+ tail.unshift(basename2(current));
47517
+ const parent = dirname8(current);
47518
+ if (parent === current)
47519
+ break;
47520
+ current = parent;
47521
+ }
47522
+ }
47523
+ try {
47524
+ const real = realpathSync(current);
47525
+ return tail.length === 0 ? real : join10(real, ...tail);
47526
+ } catch {
47527
+ return null;
47528
+ }
47529
+ }
47530
+ function protectedTreeRoots(env = process.env) {
47531
+ const candidates = [huaweiConfigBase(env), devkitStateBase(env)];
47532
+ for (const key of ["HUAWEICLOUD_MCP_POLICY_FILE", "HUAWEICLOUD_MCP_AUDIT_FILE"]) {
47533
+ const value = (env[key] ?? "").trim();
47534
+ if (value !== "")
47535
+ candidates.push(value);
47536
+ }
47537
+ const roots = [];
47538
+ const seen = /* @__PURE__ */ new Set();
47539
+ for (const candidate of candidates) {
47540
+ const resolved = resolveForWrite(candidate);
47541
+ if (resolved === null)
47542
+ return null;
47543
+ if (seen.has(resolved))
47544
+ continue;
47545
+ seen.add(resolved);
47546
+ roots.push(resolved);
47547
+ }
47548
+ return roots;
47549
+ }
47550
+ function isInsideProtectedTree(target, env = process.env) {
47551
+ if (isRefusedByGuard(target))
47552
+ return true;
47553
+ const roots = protectedTreeRoots(env);
47554
+ if (roots === null)
47555
+ return true;
47556
+ const resolved = resolveForWrite(target);
47557
+ if (resolved === null)
47558
+ return true;
47559
+ return roots.some((root) => resolved === root || resolved.startsWith(root + sep));
47560
+ }
47561
+ var init_pack_state = __esm({
47562
+ "plugins/huaweicloud-core/dist.new/lib/pack-state.js"() {
47563
+ "use strict";
47564
+ init_state_dir();
47565
+ }
47566
+ });
47567
+
47379
47568
  // plugins/huaweicloud-core/dist.new/lib/pack-types.js
47380
47569
  var PACK_IDS;
47381
47570
  var init_pack_types = __esm({
@@ -47488,14 +47677,14 @@ var init_dependency_model = __esm({
47488
47677
  });
47489
47678
 
47490
47679
  // plugins/huaweicloud-core/dist.new/dep/receipts.js
47491
- import { existsSync as existsSync9, mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync10, renameSync as renameSync2, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
47492
- import { homedir as homedir8 } from "node:os";
47493
- import { join as join9 } from "node:path";
47494
- function receiptDir(base = process.env.HUAWEICLOUD_HOME || homedir8()) {
47495
- return join9(base, ".config", "huaweicloud", "deps");
47680
+ import { existsSync as existsSync10, mkdirSync as mkdirSync5, readdirSync, readFileSync as readFileSync10, renameSync as renameSync2, rmSync as rmSync3, statSync as statSync2, writeFileSync as writeFileSync4 } from "node:fs";
47681
+ import { homedir as homedir9 } from "node:os";
47682
+ import { join as join11 } from "node:path";
47683
+ function receiptDir(base = process.env.HUAWEICLOUD_HOME || homedir9()) {
47684
+ return join11(base, ".config", "huaweicloud", "deps");
47496
47685
  }
47497
47686
  function lockDirPath(dir) {
47498
- return join9(dir, LOCK_DIR_NAME);
47687
+ return join11(dir, LOCK_DIR_NAME);
47499
47688
  }
47500
47689
  function isPidAlive(pid) {
47501
47690
  if (process.platform === "linux") {
@@ -47517,10 +47706,10 @@ function sleepSync(ms) {
47517
47706
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
47518
47707
  }
47519
47708
  function readHolderPid(dir) {
47520
- return readPidAt(join9(lockDirPath(dir), LOCK_PID_FILE));
47709
+ return readPidAt(join11(lockDirPath(dir), LOCK_PID_FILE));
47521
47710
  }
47522
47711
  function readStashHolderPid(stashDir) {
47523
- return readPidAt(join9(stashDir, LOCK_PID_FILE));
47712
+ return readPidAt(join11(stashDir, LOCK_PID_FILE));
47524
47713
  }
47525
47714
  function readPidAt(pidFile) {
47526
47715
  try {
@@ -47534,22 +47723,22 @@ function sweepStaleStashes(dir) {
47534
47723
  try {
47535
47724
  for (const entry of readdirSync(dir)) {
47536
47725
  if (entry.startsWith(`${LOCK_DIR_NAME}.`) && (entry.endsWith(".takeover") || entry.endsWith(".release"))) {
47537
- rmSync2(join9(dir, entry), { recursive: true, force: true });
47726
+ rmSync3(join11(dir, entry), { recursive: true, force: true });
47538
47727
  }
47539
47728
  }
47540
47729
  } catch {
47541
47730
  }
47542
47731
  }
47543
47732
  function acquireLock(dir, takeoverMs = LOCK_TAKEOVER_MS) {
47544
- mkdirSync3(dir, { recursive: true });
47733
+ mkdirSync5(dir, { recursive: true });
47545
47734
  sweepStaleStashes(dir);
47546
47735
  const lock = lockDirPath(dir);
47547
47736
  const deadline = Date.now() + takeoverMs;
47548
47737
  for (; ; ) {
47549
47738
  try {
47550
- mkdirSync3(lock);
47739
+ mkdirSync5(lock);
47551
47740
  const claimed = statSync2(lock);
47552
- writeFileSync3(join9(lock, LOCK_PID_FILE), `${process.pid}
47741
+ writeFileSync4(join11(lock, LOCK_PID_FILE), `${process.pid}
47553
47742
  `);
47554
47743
  const rechecked = statSync2(lock);
47555
47744
  if (rechecked.ino !== claimed.ino || rechecked.birthtimeMs !== claimed.birthtimeMs) {
@@ -47566,7 +47755,7 @@ function acquireLock(dir, takeoverMs = LOCK_TAKEOVER_MS) {
47566
47755
  if (holder !== null && isPidAlive(holder)) {
47567
47756
  let claimIsFresh = true;
47568
47757
  try {
47569
- claimIsFresh = Date.now() - statSync2(join9(lock, LOCK_PID_FILE)).mtimeMs < takeoverMs;
47758
+ claimIsFresh = Date.now() - statSync2(join11(lock, LOCK_PID_FILE)).mtimeMs < takeoverMs;
47570
47759
  } catch {
47571
47760
  }
47572
47761
  if (claimIsFresh) {
@@ -47599,7 +47788,7 @@ function acquireLock(dir, takeoverMs = LOCK_TAKEOVER_MS) {
47599
47788
  sleepSync(LOCK_POLL_MS);
47600
47789
  continue;
47601
47790
  }
47602
- rmSync2(uniqueStash, { recursive: true, force: true });
47791
+ rmSync3(uniqueStash, { recursive: true, force: true });
47603
47792
  }
47604
47793
  }
47605
47794
  function releaseLock(dir) {
@@ -47611,7 +47800,7 @@ function releaseLock(dir) {
47611
47800
  return;
47612
47801
  }
47613
47802
  if (readStashHolderPid(stash) === process.pid) {
47614
- rmSync2(stash, { recursive: true, force: true });
47803
+ rmSync3(stash, { recursive: true, force: true });
47615
47804
  } else {
47616
47805
  try {
47617
47806
  renameSync2(stash, lock);
@@ -47716,12 +47905,12 @@ var init_refs = __esm({
47716
47905
 
47717
47906
  // plugins/huaweicloud-core/dist.new/lib/secret-vault/custody.js
47718
47907
  import { spawnSync } from "node:child_process";
47719
- import { existsSync as existsSync10, mkdirSync as mkdirSync4, readFileSync as readFileSync11, readdirSync as readdirSync2, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "node:fs";
47720
- import { join as join10 } from "node:path";
47721
- import { homedir as homedir9 } from "node:os";
47908
+ import { existsSync as existsSync11, mkdirSync as mkdirSync6, readFileSync as readFileSync11, readdirSync as readdirSync2, renameSync as renameSync3, writeFileSync as writeFileSync5 } from "node:fs";
47909
+ import { join as join12 } from "node:path";
47910
+ import { homedir as homedir10 } from "node:os";
47722
47911
  import { randomBytes } from "node:crypto";
47723
47912
  function defaultSecretsRoot() {
47724
- return join10(process.env.HUAWEICLOUD_HOME || homedir9(), ".config", "huaweicloud", "secrets");
47913
+ return join12(process.env.HUAWEICLOUD_HOME || homedir10(), ".config", "huaweicloud", "secrets");
47725
47914
  }
47726
47915
  function rootOf(options) {
47727
47916
  return options?.root ?? defaultSecretsRoot();
@@ -47730,7 +47919,7 @@ function spawnerOf(options) {
47730
47919
  return options?.spawnImpl ?? spawnSync;
47731
47920
  }
47732
47921
  function keyfilePath(root) {
47733
- return join10(root, ".master-key");
47922
+ return join12(root, ".master-key");
47734
47923
  }
47735
47924
  function masterKeyFromEnv() {
47736
47925
  const raw = process.env.HW_VAULT_MASTER_KEY;
@@ -47924,7 +48113,7 @@ function keychainTierName() {
47924
48113
  }
47925
48114
  function readKeyfile(root) {
47926
48115
  const file2 = keyfilePath(root);
47927
- if (!existsSync10(file2))
48116
+ if (!existsSync11(file2))
47928
48117
  return null;
47929
48118
  const key = decodeMasterKeyB64(readFileSync11(file2, "utf8"));
47930
48119
  if (!key) {
@@ -47961,10 +48150,10 @@ function resolveMasterKey(options) {
47961
48150
  return null;
47962
48151
  }
47963
48152
  function writeKeyfile(root, key) {
47964
- mkdirSync4(root, { recursive: true });
48153
+ mkdirSync6(root, { recursive: true });
47965
48154
  const file2 = keyfilePath(root);
47966
48155
  const tmp = `${file2}.${process.pid}.${Date.now()}.tmp`;
47967
- writeFileSync4(tmp, key.toString("base64"), { encoding: "utf8", mode: 384 });
48156
+ writeFileSync5(tmp, key.toString("base64"), { encoding: "utf8", mode: 384 });
47968
48157
  renameSync3(tmp, file2);
47969
48158
  const readBack = decodeMasterKeyB64(readFileSync11(file2, "utf8"));
47970
48159
  if (!readBack || !readBack.equals(key)) {
@@ -47976,7 +48165,7 @@ function storeHasRecords(root) {
47976
48165
  for (const entry of readdirSync2(root, { withFileTypes: true })) {
47977
48166
  if (!entry.isDirectory())
47978
48167
  continue;
47979
- if (readdirSync2(join10(root, entry.name)).some((file2) => file2.endsWith(".json")))
48168
+ if (readdirSync2(join12(root, entry.name)).some((file2) => file2.endsWith(".json")))
47980
48169
  return true;
47981
48170
  }
47982
48171
  } catch {
@@ -48052,16 +48241,16 @@ var init_custody = __esm({
48052
48241
 
48053
48242
  // plugins/huaweicloud-core/dist.new/lib/secret-vault/store.js
48054
48243
  import { createCipheriv, createDecipheriv, createHmac, randomBytes as randomBytes2 } from "node:crypto";
48055
- import { existsSync as existsSync11, mkdirSync as mkdirSync5, readdirSync as readdirSync3, readFileSync as readFileSync12, renameSync as renameSync4, rmSync as rmSync3, writeFileSync as writeFileSync5 } from "node:fs";
48056
- import { join as join11 } from "node:path";
48244
+ import { existsSync as existsSync12, mkdirSync as mkdirSync7, readdirSync as readdirSync3, readFileSync as readFileSync12, renameSync as renameSync4, rmSync as rmSync4, writeFileSync as writeFileSync6 } from "node:fs";
48245
+ import { join as join13 } from "node:path";
48057
48246
  function rootOf2(options) {
48058
48247
  return options?.root ?? defaultSecretsRoot();
48059
48248
  }
48060
48249
  function scopeDir(root, scope) {
48061
- return join11(root, scope);
48250
+ return join13(root, scope);
48062
48251
  }
48063
48252
  function secretFile(root, ref) {
48064
- return join11(scopeDir(root, ref.scope), `${ref.name}.json`);
48253
+ return join13(scopeDir(root, ref.scope), `${ref.name}.json`);
48065
48254
  }
48066
48255
  function fingerprintOf(masterKey, value) {
48067
48256
  return createHmac("sha256", masterKey).update(value, "utf8").digest("hex").slice(0, 16);
@@ -48088,7 +48277,7 @@ function decrypt(masterKey, ref, record2) {
48088
48277
  }
48089
48278
  }
48090
48279
  function readRecord(path) {
48091
- if (!existsSync11(path))
48280
+ if (!existsSync12(path))
48092
48281
  return null;
48093
48282
  let parsed;
48094
48283
  try {
@@ -48130,10 +48319,10 @@ function readRecord(path) {
48130
48319
  }
48131
48320
  function writeRecord(root, ref, record2) {
48132
48321
  const dir = scopeDir(root, ref.scope);
48133
- mkdirSync5(dir, { recursive: true });
48322
+ mkdirSync7(dir, { recursive: true });
48134
48323
  const file2 = secretFile(root, ref);
48135
48324
  const tmp = `${file2}.${process.pid}.${Date.now()}.tmp`;
48136
- writeFileSync5(tmp, JSON.stringify(record2, null, 2), { encoding: "utf8", mode: 384 });
48325
+ writeFileSync6(tmp, JSON.stringify(record2, null, 2), { encoding: "utf8", mode: 384 });
48137
48326
  renameSync4(tmp, file2);
48138
48327
  }
48139
48328
  function masterKeyForRead(options) {
@@ -48199,9 +48388,9 @@ function vaultDelete(refInput, options) {
48199
48388
  const root = rootOf2(options);
48200
48389
  return withDepLock(() => {
48201
48390
  const file2 = secretFile(root, ref);
48202
- if (!existsSync11(file2))
48391
+ if (!existsSync12(file2))
48203
48392
  return { removed: 0 };
48204
- rmSync3(file2, { force: true });
48393
+ rmSync4(file2, { force: true });
48205
48394
  return { removed: 1 };
48206
48395
  }, root);
48207
48396
  }
@@ -48212,7 +48401,7 @@ function vaultList(scope, options) {
48212
48401
  }
48213
48402
  const scopes = [];
48214
48403
  if (scope === void 0) {
48215
- if (!existsSync11(root))
48404
+ if (!existsSync12(root))
48216
48405
  return [];
48217
48406
  for (const entry of readdirSync3(root, { withFileTypes: true })) {
48218
48407
  if (!entry.isDirectory())
@@ -48227,13 +48416,13 @@ function vaultList(scope, options) {
48227
48416
  const out = [];
48228
48417
  for (const scopeName of scopes) {
48229
48418
  const dir = scopeDir(root, scopeName);
48230
- if (!existsSync11(dir))
48419
+ if (!existsSync12(dir))
48231
48420
  continue;
48232
48421
  for (const entry of readdirSync3(dir).sort((a, b) => a.localeCompare(b))) {
48233
48422
  if (!entry.endsWith(".json") || !isValidNameSegment(entry.slice(0, -".json".length)))
48234
48423
  continue;
48235
48424
  const name = entry.slice(0, -".json".length);
48236
- const record2 = readRecord(join11(dir, entry));
48425
+ const record2 = readRecord(join13(dir, entry));
48237
48426
  if (!record2)
48238
48427
  continue;
48239
48428
  out.push({
@@ -48270,14 +48459,13 @@ var init_store = __esm({
48270
48459
  });
48271
48460
 
48272
48461
  // plugins/huaweicloud-core/dist.new/auth/s1-store.js
48273
- import { chmodSync, copyFileSync, existsSync as existsSync12, mkdirSync as mkdirSync6, readFileSync as readFileSync13, statSync as statSync3, writeFileSync as writeFileSync6 } from "node:fs";
48274
- import { dirname as dirname7, join as join12 } from "node:path";
48275
- import { homedir as homedir10 } from "node:os";
48462
+ import { chmodSync as chmodSync2, copyFileSync, existsSync as existsSync13, mkdirSync as mkdirSync8, readFileSync as readFileSync13, statSync as statSync3, writeFileSync as writeFileSync7 } from "node:fs";
48463
+ import { dirname as dirname9, join as join14 } from "node:path";
48276
48464
  function ensurePrivateMode(path) {
48277
48465
  if (process.platform === "win32")
48278
48466
  return;
48279
48467
  try {
48280
- chmodSync(path, 384);
48468
+ chmodSync2(path, 384);
48281
48469
  } catch {
48282
48470
  }
48283
48471
  try {
@@ -48291,15 +48479,14 @@ function ensurePrivateMode(path) {
48291
48479
  } catch {
48292
48480
  }
48293
48481
  }
48294
- function baseHome2() {
48295
- return process.env.HUAWEICLOUD_HOME || homedir10();
48296
- }
48297
48482
  function globalCredentialsPath() {
48298
- return join12(baseHome2(), ".config", "huaweicloud", "credentials.json");
48483
+ return join14(devkitStateBase(), "credentials.json");
48299
48484
  }
48300
- function readGlobalCredentials() {
48301
- const path = globalCredentialsPath();
48302
- if (!existsSync12(path))
48485
+ function legacyGlobalCredentialsPath() {
48486
+ return join14(huaweiConfigBase(), "credentials.json");
48487
+ }
48488
+ function readJsonObject(path) {
48489
+ if (!existsSync13(path))
48303
48490
  return null;
48304
48491
  try {
48305
48492
  const parsed = JSON.parse(readFileSync13(path, "utf8"));
@@ -48308,6 +48495,18 @@ function readGlobalCredentials() {
48308
48495
  return null;
48309
48496
  }
48310
48497
  }
48498
+ function readGlobalCredentials() {
48499
+ const primary = globalCredentialsPath();
48500
+ const stored = readJsonObject(primary);
48501
+ if (stored)
48502
+ return stored;
48503
+ if (!existsSync13(primary)) {
48504
+ const legacy = legacyGlobalCredentialsPath();
48505
+ if (legacy !== primary)
48506
+ return readJsonObject(legacy);
48507
+ }
48508
+ return null;
48509
+ }
48311
48510
  function resolveStoredRefs(stored) {
48312
48511
  if (!stored)
48313
48512
  return null;
@@ -48336,7 +48535,7 @@ function readGlobalCredentialsStrict() {
48336
48535
  }
48337
48536
  function writeGlobalCredentials(credentials = {}) {
48338
48537
  const path = globalCredentialsPath();
48339
- mkdirSync6(dirname7(path), { recursive: true });
48538
+ mkdirSync8(dirname9(path), { recursive: true });
48340
48539
  const payload = {
48341
48540
  ak: asText(credentials.ak || ""),
48342
48541
  sk: asText(credentials.sk || ""),
@@ -48344,7 +48543,7 @@ function writeGlobalCredentials(credentials = {}) {
48344
48543
  region: asText(credentials.region || ""),
48345
48544
  ...credentials.configuredBySession === void 0 ? {} : { configuredBySession: Boolean(credentials.configuredBySession) }
48346
48545
  };
48347
- writeFileSync6(path, JSON.stringify(payload, null, 2), { encoding: "utf8", mode: 384 });
48546
+ writeFileSync7(path, JSON.stringify(payload, null, 2), { encoding: "utf8", mode: 384 });
48348
48547
  ensurePrivateMode(path);
48349
48548
  return path;
48350
48549
  }
@@ -48354,37 +48553,43 @@ function setConfiguredBySession(flag) {
48354
48553
  writeGlobalCredentials(next);
48355
48554
  }
48356
48555
  function lastSyncPath() {
48357
- return join12(baseHome2(), ".config", "huaweicloud", ".last_sync");
48556
+ return join14(devkitStateBase(), ".last_sync");
48557
+ }
48558
+ function readLastSyncFile(path) {
48559
+ return readJsonObject(path);
48358
48560
  }
48359
48561
  function readLastSync() {
48360
- const path = lastSyncPath();
48361
- if (!existsSync12(path))
48362
- return null;
48363
- try {
48364
- const parsed = JSON.parse(readFileSync13(path, "utf8"));
48365
- return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
48366
- } catch {
48367
- return null;
48562
+ const primary = lastSyncPath();
48563
+ const stored = readLastSyncFile(primary);
48564
+ if (stored)
48565
+ return stored;
48566
+ if (!existsSync13(primary)) {
48567
+ const legacy = join14(huaweiConfigBase(), ".last_sync");
48568
+ if (legacy !== primary)
48569
+ return readLastSyncFile(legacy);
48368
48570
  }
48571
+ return null;
48369
48572
  }
48370
48573
  function writeLastSync(metadata = {}) {
48371
48574
  const path = lastSyncPath();
48372
- mkdirSync6(dirname7(path), { recursive: true });
48575
+ mkdirSync8(dirname9(path), { recursive: true });
48373
48576
  const payload = {
48374
48577
  ts: Date.now(),
48375
48578
  ...metadata.kooCliProfile ? { kooCliProfile: asText(metadata.kooCliProfile) } : {},
48376
48579
  ...metadata.s1Fingerprint ? { s1Fingerprint: asText(metadata.s1Fingerprint) } : {}
48377
48580
  };
48378
- writeFileSync6(path, JSON.stringify(payload), { encoding: "utf8", mode: 384 });
48581
+ writeFileSync7(path, JSON.stringify(payload), { encoding: "utf8", mode: 384 });
48379
48582
  ensurePrivateMode(path);
48380
48583
  }
48381
48584
  function backupGlobalCredentials() {
48382
- const path = globalCredentialsPath();
48383
- if (!existsSync12(path))
48585
+ const target = globalCredentialsPath();
48586
+ const source = existsSync13(target) ? target : legacyGlobalCredentialsPath();
48587
+ if (!existsSync13(source))
48384
48588
  return null;
48385
- const bakPath = `${path}.bak`;
48589
+ const bakPath = `${target}.bak`;
48386
48590
  try {
48387
- copyFileSync(path, bakPath);
48591
+ mkdirSync8(dirname9(bakPath), { recursive: true });
48592
+ copyFileSync(source, bakPath);
48388
48593
  ensurePrivateMode(bakPath);
48389
48594
  return bakPath;
48390
48595
  } catch {
@@ -48395,6 +48600,7 @@ var init_s1_store = __esm({
48395
48600
  "plugins/huaweicloud-core/dist.new/auth/s1-store.js"() {
48396
48601
  "use strict";
48397
48602
  init_as_text();
48603
+ init_pack_state();
48398
48604
  init_store();
48399
48605
  }
48400
48606
  });
@@ -48427,8 +48633,8 @@ var init_credential_placeholder = __esm({
48427
48633
  });
48428
48634
 
48429
48635
  // plugins/huaweicloud-core/dist.new/auth/codearts-context.js
48430
- import { existsSync as existsSync13, readFileSync as readFileSync14, readlinkSync } from "node:fs";
48431
- import { join as join13 } from "node:path";
48636
+ import { existsSync as existsSync14, readFileSync as readFileSync14, readlinkSync } from "node:fs";
48637
+ import { join as join15 } from "node:path";
48432
48638
  import { homedir as homedir11 } from "node:os";
48433
48639
  function pickDevkitMcpServer(mcpMap) {
48434
48640
  const map2 = asRecord(mcpMap);
@@ -48476,7 +48682,7 @@ function getParentCwd() {
48476
48682
  }
48477
48683
  }
48478
48684
  function isCodeArtsContext() {
48479
- return existsSync13(join13(process.cwd(), ".codeartsdoer")) || existsSync13(join13(homedir11(), ".codeartsdoer")) || existsSync13(join13(homedir11(), ".codeartswork")) || existsSync13(join13(homedir11(), ".codearts"));
48685
+ return existsSync14(join15(process.cwd(), ".codeartsdoer")) || existsSync14(join15(homedir11(), ".codeartsdoer")) || existsSync14(join15(homedir11(), ".codeartswork")) || existsSync14(join15(homedir11(), ".codearts"));
48480
48686
  }
48481
48687
  function readCodeArtsCredentials() {
48482
48688
  const parentCwd = getParentCwd();
@@ -48484,9 +48690,9 @@ function readCodeArtsCredentials() {
48484
48690
  for (const dir of searchDirs) {
48485
48691
  if (!dir)
48486
48692
  continue;
48487
- const path = join13(dir, ".codeartsdoer", "mcp", "mcp_settings.json");
48693
+ const path = join15(dir, ".codeartsdoer", "mcp", "mcp_settings.json");
48488
48694
  try {
48489
- if (!existsSync13(path))
48695
+ if (!existsSync14(path))
48490
48696
  continue;
48491
48697
  const config2 = JSON.parse(readFileSync14(path, "utf8"));
48492
48698
  const server = pickDevkitMcpServer(asRecord(config2).mcpServers);
@@ -48508,12 +48714,12 @@ function readCodeArtsCredentials() {
48508
48714
  }
48509
48715
  }
48510
48716
  const workPaths = [
48511
- join13(homedir11(), ".codearts", "mcp", "mcp_settings.json"),
48512
- join13(homedir11(), ".codeartswork", "mcp", "mcp_settings.json")
48717
+ join15(homedir11(), ".codearts", "mcp", "mcp_settings.json"),
48718
+ join15(homedir11(), ".codeartswork", "mcp", "mcp_settings.json")
48513
48719
  ];
48514
48720
  for (const path of workPaths) {
48515
48721
  try {
48516
- if (!existsSync13(path))
48722
+ if (!existsSync14(path))
48517
48723
  continue;
48518
48724
  const config2 = JSON.parse(readFileSync14(path, "utf8"));
48519
48725
  const entry = readWorkEnvironmentEntry(config2);
@@ -48592,7 +48798,7 @@ var init_sts_expiry = __esm({
48592
48798
 
48593
48799
  // plugins/huaweicloud-core/dist.new/auth/error-table.js
48594
48800
  import { homedir as homedir12 } from "node:os";
48595
- import { join as join14 } from "node:path";
48801
+ import { join as join16 } from "node:path";
48596
48802
  function buildOnboardingSteps(scenario, { codearts = false } = {}) {
48597
48803
  switch (scenario) {
48598
48804
  case 3: {
@@ -48603,7 +48809,7 @@ function buildOnboardingSteps(scenario, { codearts = false } = {}) {
48603
48809
  {
48604
48810
  order: 2,
48605
48811
  action: "write-import",
48606
- target: join14(homedir12(), ".config", "huaweicloud", "creds-import.json"),
48812
+ target: join16(homedir12(), ".config", "huaweicloud", "creds-import.json"),
48607
48813
  label: "\u628A AK/SK \u5199\u5165 creds-import.json"
48608
48814
  },
48609
48815
  {
@@ -48710,11 +48916,11 @@ var init_error_table = __esm({
48710
48916
  });
48711
48917
 
48712
48918
  // plugins/huaweicloud-core/dist.new/auth/obs-config.js
48713
- import { writeFileSync as writeFileSync7 } from "node:fs";
48714
- import { join as join15 } from "node:path";
48919
+ import { writeFileSync as writeFileSync8 } from "node:fs";
48920
+ import { join as join17 } from "node:path";
48715
48921
  import { homedir as homedir13 } from "node:os";
48716
48922
  function obsConfigPath() {
48717
- return process.env.HCLOUD_OBS_CONFIG_PATH || join15(homedir13(), ".obsutilconfig");
48923
+ return process.env.HCLOUD_OBS_CONFIG_PATH || join17(homedir13(), ".obsutilconfig");
48718
48924
  }
48719
48925
  function writeObsConfig(credentials = {}) {
48720
48926
  const region = asText(credentials.region || "");
@@ -48731,7 +48937,7 @@ ak=${ak}
48731
48937
  sk=${sk}${securityToken ? `
48732
48938
  token=${securityToken}` : ""}
48733
48939
  `;
48734
- writeFileSync7(path, content, { encoding: "utf8", mode: 384 });
48940
+ writeFileSync8(path, content, { encoding: "utf8", mode: 384 });
48735
48941
  ensurePrivateMode(path);
48736
48942
  return { path, endpoint };
48737
48943
  }
@@ -49271,10 +49477,10 @@ var init_update_semver = __esm({
49271
49477
 
49272
49478
  // plugins/huaweicloud-core/dist.new/update-installed.js
49273
49479
  import { readFileSync as readFileSync15 } from "node:fs";
49274
- import { join as join16, dirname as dirname8, resolve } from "node:path";
49480
+ import { join as join18, dirname as dirname10, resolve as resolve3 } from "node:path";
49275
49481
  import { fileURLToPath as fileURLToPath4 } from "node:url";
49276
49482
  function selfDir() {
49277
- return dirname8(fileURLToPath4(import.meta.url));
49483
+ return dirname10(fileURLToPath4(import.meta.url));
49278
49484
  }
49279
49485
  function readJsonVersion(file2) {
49280
49486
  try {
@@ -49288,15 +49494,15 @@ function readJsonVersion(file2) {
49288
49494
  }
49289
49495
  }
49290
49496
  function readInstalledVersion() {
49291
- const pluginRoot = resolve(selfDir(), "..");
49292
- const packageRoot = resolve(pluginRoot, "..", "..");
49497
+ const pluginRoot = resolve3(selfDir(), "..");
49498
+ const packageRoot = resolve3(pluginRoot, "..", "..");
49293
49499
  for (const base of [pluginRoot, packageRoot]) {
49294
- const version2 = readJsonVersion(join16(base, "package.json"));
49500
+ const version2 = readJsonVersion(join18(base, "package.json"));
49295
49501
  if (version2)
49296
49502
  return version2;
49297
49503
  }
49298
49504
  for (const rel of VERSION_MANIFEST_RELS) {
49299
- const version2 = readJsonVersion(join16(pluginRoot, rel));
49505
+ const version2 = readJsonVersion(join18(pluginRoot, rel));
49300
49506
  if (version2)
49301
49507
  return version2;
49302
49508
  }
@@ -49318,15 +49524,13 @@ var init_update_installed = __esm({
49318
49524
  });
49319
49525
 
49320
49526
  // plugins/huaweicloud-core/dist.new/update-skip.js
49321
- import { existsSync as existsSync14, readFileSync as readFileSync16, writeFileSync as writeFileSync8, renameSync as renameSync5, mkdirSync as mkdirSync7, rmSync as rmSync4 } from "node:fs";
49322
- import { join as join17, dirname as dirname9, resolve as resolve2 } from "node:path";
49323
- import { homedir as homedir14 } from "node:os";
49527
+ import { existsSync as existsSync15, readFileSync as readFileSync16, writeFileSync as writeFileSync9, renameSync as renameSync5, mkdirSync as mkdirSync9, rmSync as rmSync5 } from "node:fs";
49528
+ import { join as join19, dirname as dirname11, resolve as resolve4 } from "node:path";
49324
49529
  function skipFilePath() {
49325
- return join17(resolve2(selfDir(), ".."), ".update-skip.json");
49530
+ return join19(resolve4(selfDir(), ".."), ".update-skip.json");
49326
49531
  }
49327
49532
  function fallbackSkipFilePath() {
49328
- const base = process.env.HUAWEICLOUD_HOME || homedir14();
49329
- return join17(base, ".config", "huaweicloud", "devkit-skip.json");
49533
+ return join19(devkitStateBase(), "devkit-skip.json");
49330
49534
  }
49331
49535
  function sanitizeSessionId(sessionId) {
49332
49536
  return asText(sessionId || "").replace(/[^0-9a-zA-Z-]/g, "_");
@@ -49334,7 +49538,7 @@ function sanitizeSessionId(sessionId) {
49334
49538
  function resolveSkipFilePath(sessionId = null) {
49335
49539
  let base;
49336
49540
  try {
49337
- if (existsSync14(join17(dirname9(skipFilePath()), "package.json"))) {
49541
+ if (existsSync15(join19(dirname11(skipFilePath()), "package.json"))) {
49338
49542
  base = skipFilePath();
49339
49543
  } else {
49340
49544
  base = fallbackSkipFilePath();
@@ -49347,7 +49551,7 @@ function resolveSkipFilePath(sessionId = null) {
49347
49551
  return `${base}.${sanitizeSessionId(sessionId)}`;
49348
49552
  }
49349
49553
  function readSkipState(file2) {
49350
- if (!existsSync14(file2))
49554
+ if (!existsSync15(file2))
49351
49555
  return null;
49352
49556
  try {
49353
49557
  const parsed = JSON.parse(readFileSync16(file2, "utf8"));
@@ -49372,13 +49576,13 @@ function writeSkipState(file2, dismissedVersion, { at = Date.now(), days = COOLD
49372
49576
  dismissedAt: new Date(at).toISOString(),
49373
49577
  expireAt: new Date(at + days * 24 * 60 * 60 * 1e3).toISOString()
49374
49578
  };
49375
- mkdirSync7(dirname9(file2), { recursive: true });
49579
+ mkdirSync9(dirname11(file2), { recursive: true });
49376
49580
  const tmp = `${file2}.${process.pid}.${Date.now()}.tmp`;
49377
- writeFileSync8(tmp, JSON.stringify(state2, null, 2), "utf8");
49581
+ writeFileSync9(tmp, JSON.stringify(state2, null, 2), "utf8");
49378
49582
  try {
49379
49583
  renameSync5(tmp, file2);
49380
49584
  } catch (error62) {
49381
- rmSync4(tmp, { force: true });
49585
+ rmSync5(tmp, { force: true });
49382
49586
  throw error62;
49383
49587
  }
49384
49588
  return state2;
@@ -49388,6 +49592,7 @@ var init_update_skip = __esm({
49388
49592
  "plugins/huaweicloud-core/dist.new/update-skip.js"() {
49389
49593
  "use strict";
49390
49594
  init_as_text();
49595
+ init_pack_state();
49391
49596
  init_update_installed();
49392
49597
  COOLDOWN_DAYS = 3;
49393
49598
  }
@@ -49500,17 +49705,17 @@ function queryDistTags({ timeoutMs = 15e3, cwd } = {}) {
49500
49705
  if (process.env.HUAWEICLOUD_NPM_REGISTRY) {
49501
49706
  return queryDistTagsFetch({ timeoutMs });
49502
49707
  }
49503
- return new Promise((resolve9) => {
49708
+ return new Promise((resolve10) => {
49504
49709
  let child;
49505
49710
  try {
49506
- child = spawn(NPM_BIN, ["view", "huaweicloud-devkit", "dist-tags", "--json"], {
49711
+ child = spawn(`${NPM_BIN} view huaweicloud-devkit dist-tags --json`, {
49507
49712
  windowsHide: true,
49508
49713
  cwd,
49509
49714
  shell: true
49510
49715
  });
49511
49716
  } catch (error62) {
49512
49717
  debugLog2(`queryDistTags: ${errorMessage(error62) || String(error62)}`);
49513
- resolve9(null);
49718
+ resolve10(null);
49514
49719
  return;
49515
49720
  }
49516
49721
  const timer = setTimeout(() => {
@@ -49519,7 +49724,7 @@ function queryDistTags({ timeoutMs = 15e3, cwd } = {}) {
49519
49724
  } catch {
49520
49725
  }
49521
49726
  debugLog2(`queryDistTags: timed out after ${timeoutMs}ms`);
49522
- resolve9(null);
49727
+ resolve10(null);
49523
49728
  }, timeoutMs);
49524
49729
  let stdout = "";
49525
49730
  child.stdout.on("data", (d) => {
@@ -49528,15 +49733,15 @@ function queryDistTags({ timeoutMs = 15e3, cwd } = {}) {
49528
49733
  child.on("error", (error62) => {
49529
49734
  clearTimeout(timer);
49530
49735
  debugLog2(`queryDistTags: ${errorMessage(error62) || String(error62)}`);
49531
- resolve9(null);
49736
+ resolve10(null);
49532
49737
  });
49533
49738
  child.on("close", (code) => {
49534
49739
  clearTimeout(timer);
49535
49740
  if (code === 0) {
49536
- resolve9(parseDistTagsOutput(stdout));
49741
+ resolve10(parseDistTagsOutput(stdout));
49537
49742
  } else {
49538
49743
  debugLog2(`queryDistTags: npm view exited with code ${code}`);
49539
- resolve9(null);
49744
+ resolve10(null);
49540
49745
  }
49541
49746
  });
49542
49747
  });
@@ -49633,17 +49838,17 @@ var init_update_cache = __esm({
49633
49838
 
49634
49839
  // plugins/huaweicloud-core/dist.new/lib/dep-resolve.js
49635
49840
  import { spawnSync as spawnSync3 } from "node:child_process";
49636
- import { existsSync as existsSync15 } from "node:fs";
49637
- import { homedir as homedir15 } from "node:os";
49638
- import { basename as basename2, join as join18 } from "node:path";
49841
+ import { existsSync as existsSync16 } from "node:fs";
49842
+ import { homedir as homedir14 } from "node:os";
49843
+ import { basename as basename3, join as join20 } from "node:path";
49639
49844
  function platformHome(env) {
49640
- return process.platform === "win32" ? env.USERPROFILE || homedir15() : env.HOME || homedir15();
49845
+ return process.platform === "win32" ? env.USERPROFILE || homedir14() : env.HOME || homedir14();
49641
49846
  }
49642
49847
  function pathLookupName(resolution) {
49643
49848
  const candidates = process.platform === "win32" ? resolution.candidates.win32 : resolution.candidates.unix;
49644
49849
  if (candidates.length === 0)
49645
49850
  return null;
49646
- const raw = basename2(candidates[0]);
49851
+ const raw = basename3(candidates[0]);
49647
49852
  return process.platform === "win32" && raw.endsWith(".exe") ? raw.slice(0, -4) : raw;
49648
49853
  }
49649
49854
  function lookupOnPath(name, env) {
@@ -49653,13 +49858,13 @@ function lookupOnPath(name, env) {
49653
49858
  }
49654
49859
  function resolveDependencyCommand(resolution, env = process.env) {
49655
49860
  const envBin = env[resolution.envBin];
49656
- if (envBin && existsSync15(envBin))
49861
+ if (envBin && existsSync16(envBin))
49657
49862
  return { command: envBin, argsPrefix: [], tier: "env" };
49658
49863
  const home = platformHome(env);
49659
49864
  const candidates = process.platform === "win32" ? resolution.candidates.win32 : resolution.candidates.unix;
49660
49865
  for (const candidate of candidates) {
49661
- const expanded = candidate.startsWith("~") ? join18(home, candidate.slice(1)) : candidate;
49662
- if (existsSync15(expanded))
49866
+ const expanded = candidate.startsWith("~") ? join20(home, candidate.slice(1)) : candidate;
49867
+ if (existsSync16(expanded))
49663
49868
  return { command: expanded, argsPrefix: [], tier: "candidate" };
49664
49869
  }
49665
49870
  const name = pathLookupName(resolution);
@@ -49668,8 +49873,8 @@ function resolveDependencyCommand(resolution, env = process.env) {
49668
49873
  return { command: onPath, argsPrefix: [], tier: "path" };
49669
49874
  if (resolution.fallback) {
49670
49875
  const exeSuffix = process.platform === "win32" ? ".exe" : "";
49671
- const localCandidate = join18(home, ".local", "bin", `${resolution.fallback.command}${exeSuffix}`);
49672
- const fallbackCommand = existsSync15(localCandidate) ? localCandidate : lookupOnPath(resolution.fallback.command, env);
49876
+ const localCandidate = join20(home, ".local", "bin", `${resolution.fallback.command}${exeSuffix}`);
49877
+ const fallbackCommand = existsSync16(localCandidate) ? localCandidate : lookupOnPath(resolution.fallback.command, env);
49673
49878
  if (fallbackCommand) {
49674
49879
  return { command: fallbackCommand, argsPrefix: resolution.fallback.argsPrefix, tier: "fallback" };
49675
49880
  }
@@ -49685,10 +49890,10 @@ var init_dep_resolve = __esm({
49685
49890
  // plugins/huaweicloud-core/dist.new/codex-probe.js
49686
49891
  import { spawnSync as spawnSync4 } from "node:child_process";
49687
49892
  import { readFileSync as readFileSync17 } from "node:fs";
49688
- import { dirname as dirname10, join as join19, resolve as resolve3 } from "node:path";
49893
+ import { dirname as dirname12, join as join21, resolve as resolve5 } from "node:path";
49689
49894
  import { fileURLToPath as fileURLToPath5 } from "node:url";
49690
49895
  function getCodexPluginName() {
49691
- const marketplacePath = join19(PACKAGE_ROOT, ".agents", "plugins", "marketplace.json");
49896
+ const marketplacePath = join21(PACKAGE_ROOT, ".agents", "plugins", "marketplace.json");
49692
49897
  try {
49693
49898
  const marketplace = asRecord(JSON.parse(readFileSync17(marketplacePath, "utf8")));
49694
49899
  const plugins = Array.isArray(marketplace.plugins) ? marketplace.plugins : [];
@@ -49697,7 +49902,7 @@ function getCodexPluginName() {
49697
49902
  return pluginName;
49698
49903
  } catch {
49699
49904
  }
49700
- const codexManifestPath = join19(PLUGIN_ROOT, ".codex-plugin", "plugin.json");
49905
+ const codexManifestPath = join21(PLUGIN_ROOT, ".codex-plugin", "plugin.json");
49701
49906
  try {
49702
49907
  const manifest = asRecord(JSON.parse(readFileSync17(codexManifestPath, "utf8")));
49703
49908
  if (typeof manifest.name === "string" && manifest.name)
@@ -49740,15 +49945,15 @@ var init_codex_probe = __esm({
49740
49945
  "use strict";
49741
49946
  init_dep_resolve();
49742
49947
  init_as_record();
49743
- __dirname3 = dirname10(fileURLToPath5(import.meta.url));
49744
- PLUGIN_ROOT = resolve3(__dirname3, "..");
49745
- PACKAGE_ROOT = resolve3(PLUGIN_ROOT, "..", "..");
49948
+ __dirname3 = dirname12(fileURLToPath5(import.meta.url));
49949
+ PLUGIN_ROOT = resolve5(__dirname3, "..");
49950
+ PACKAGE_ROOT = resolve5(PLUGIN_ROOT, "..", "..");
49746
49951
  }
49747
49952
  });
49748
49953
 
49749
49954
  // plugins/huaweicloud-core/dist.new/officeace-paths.js
49750
- import { join as join20, resolve as resolve4, dirname as dirname11 } from "node:path";
49751
- import { homedir as homedir16, platform } from "node:os";
49955
+ import { join as join22, resolve as resolve6, dirname as dirname13 } from "node:path";
49956
+ import { homedir as homedir15, platform } from "node:os";
49752
49957
  import { spawnSync as spawnSync5 } from "node:child_process";
49753
49958
  function readOfficeaceRegistryInstallDir() {
49754
49959
  if (platform() !== "win32")
@@ -49771,18 +49976,18 @@ function readOfficeaceRegistryInstallDir() {
49771
49976
  function probeOfficeaceSystemDirs(rootUsable) {
49772
49977
  const regDir = readOfficeaceRegistryInstallDir();
49773
49978
  if (regDir) {
49774
- const dir = join20(regDir, ".office-claw");
49979
+ const dir = join22(regDir, ".office-claw");
49775
49980
  if (rootUsable(dir))
49776
49981
  return dir;
49777
49982
  }
49778
49983
  if (platform() === "win32") {
49779
49984
  const bases = [process.env.ProgramFiles, "C:\\Program Files", "D:\\Program Files"];
49780
49985
  if (process.env.LOCALAPPDATA)
49781
- bases.push(join20(process.env.LOCALAPPDATA, "Programs"));
49986
+ bases.push(join22(process.env.LOCALAPPDATA, "Programs"));
49782
49987
  for (const base of bases) {
49783
49988
  if (!base)
49784
49989
  continue;
49785
- const dir = join20(base, "OfficeAce", ".office-claw");
49990
+ const dir = join22(base, "OfficeAce", ".office-claw");
49786
49991
  if (rootUsable(dir))
49787
49992
  return dir;
49788
49993
  }
@@ -49796,22 +50001,22 @@ var init_officeace_paths = __esm({
49796
50001
  });
49797
50002
 
49798
50003
  // plugins/huaweicloud-core/dist.new/auth/agent-registration.js
49799
- import { existsSync as existsSync16, readFileSync as readFileSync18 } from "node:fs";
49800
- import { isAbsolute, join as join21, resolve as resolve5 } from "node:path";
49801
- import { homedir as homedir17 } from "node:os";
50004
+ import { existsSync as existsSync17, readFileSync as readFileSync18 } from "node:fs";
50005
+ import { isAbsolute as isAbsolute2, join as join23, resolve as resolve7 } from "node:path";
50006
+ import { homedir as homedir16 } from "node:os";
49802
50007
  import { createRequire } from "node:module";
49803
50008
  function xdgConfigHome() {
49804
50009
  const xdg = process.env.XDG_CONFIG_HOME;
49805
- return xdg && isAbsolute(xdg) ? xdg : join21(homedir17(), ".config");
50010
+ return xdg && isAbsolute2(xdg) ? xdg : join23(homedir16(), ".config");
49806
50011
  }
49807
50012
  function opencodeConfigFile() {
49808
- const jsonc = join21(xdgConfigHome(), "opencode", "opencode.jsonc");
49809
- if (existsSync16(jsonc))
50013
+ const jsonc = join23(xdgConfigHome(), "opencode", "opencode.jsonc");
50014
+ if (existsSync17(jsonc))
49810
50015
  return jsonc;
49811
- return join21(xdgConfigHome(), "opencode", "opencode.json");
50016
+ return join23(xdgConfigHome(), "opencode", "opencode.json");
49812
50017
  }
49813
50018
  function readJsonSafe(path) {
49814
- if (!existsSync16(path))
50019
+ if (!existsSync17(path))
49815
50020
  return null;
49816
50021
  try {
49817
50022
  return JSON.parse(readFileSync18(path, "utf8"));
@@ -49825,10 +50030,10 @@ function opencodeRegistered() {
49825
50030
  return Boolean(asRecord(cfg.mcp)["huaweicloud-devkit"]);
49826
50031
  }
49827
50032
  function codexDesktopRegistered() {
49828
- if (existsSync16(join21(homedir17(), "plugins", "huaweicloud-devkit", "dist", "mcp-server.js")))
50033
+ if (existsSync17(join23(homedir16(), "plugins", "huaweicloud-devkit", "dist", "mcp-server.js")))
49829
50034
  return true;
49830
- const legacyPath = join21(homedir17(), ".codex", "config.toml");
49831
- if (!existsSync16(legacyPath))
50035
+ const legacyPath = join23(homedir16(), ".codex", "config.toml");
50036
+ if (!existsSync17(legacyPath))
49832
50037
  return false;
49833
50038
  try {
49834
50039
  return readFileSync18(legacyPath, "utf8").includes("[mcp_servers.huaweicloud-devkit]");
@@ -49842,8 +50047,8 @@ function codexCliRegistered() {
49842
50047
  }
49843
50048
  function codeartsRegistered() {
49844
50049
  const paths2 = [
49845
- join21(homedir17(), ".codeartsdoer", "mcp", "mcp_settings.json"),
49846
- join21(process.cwd(), ".codeartsdoer", "mcp", "mcp_settings.json")
50050
+ join23(homedir16(), ".codeartsdoer", "mcp", "mcp_settings.json"),
50051
+ join23(process.cwd(), ".codeartsdoer", "mcp", "mcp_settings.json")
49847
50052
  ];
49848
50053
  return paths2.some((path) => {
49849
50054
  const cfg = asRecord(readJsonSafe(path));
@@ -49851,20 +50056,20 @@ function codeartsRegistered() {
49851
50056
  });
49852
50057
  }
49853
50058
  function codeartsWorkRegistered() {
49854
- const path = join21(homedir17(), ".codeartswork", "mcp", "mcp_settings.json");
50059
+ const path = join23(homedir16(), ".codeartswork", "mcp", "mcp_settings.json");
49855
50060
  const cfg = asRecord(readJsonSafe(path));
49856
50061
  return Boolean(asRecord(cfg.mcp)["huaweicloud-devkit"]);
49857
50062
  }
49858
50063
  function workbuddyRegistered() {
49859
- const cfg = asRecord(readJsonSafe(join21(homedir17(), ".workbuddy", "mcp.json")));
50064
+ const cfg = asRecord(readJsonSafe(join23(homedir16(), ".workbuddy", "mcp.json")));
49860
50065
  return Boolean(asRecord(cfg.mcpServers)["huaweicloud-devkit"]);
49861
50066
  }
49862
50067
  function dshRoot() {
49863
- return process.env.DSH_HOME || join21(homedir17(), ".dsh");
50068
+ return process.env.DSH_HOME || join23(homedir16(), ".dsh");
49864
50069
  }
49865
50070
  function dshRegistered() {
49866
- const patchPath = join21(dshRoot(), "profiles", "web", "cordis.patch.yml");
49867
- if (!existsSync16(patchPath))
50071
+ const patchPath = join23(dshRoot(), "profiles", "web", "cordis.patch.yml");
50072
+ if (!existsSync17(patchPath))
49868
50073
  return false;
49869
50074
  try {
49870
50075
  const patch = readFileSync18(patchPath, "utf8");
@@ -49875,16 +50080,16 @@ function dshRegistered() {
49875
50080
  }
49876
50081
  function officeaceCapabilitiesDir() {
49877
50082
  const configRoot = process.env.OFFICE_CLAW_CONFIG_ROOT;
49878
- if (configRoot && existsSync16(join21(configRoot, "capabilities.json")))
50083
+ if (configRoot && existsSync17(join23(configRoot, "capabilities.json")))
49879
50084
  return configRoot;
49880
- return probeOfficeaceSystemDirs((dir) => existsSync16(join21(dir, "capabilities.json")));
50085
+ return probeOfficeaceSystemDirs((dir) => existsSync17(join23(dir, "capabilities.json")));
49881
50086
  }
49882
50087
  function officeaceCapabilitiesDirSafe() {
49883
- return officeaceCapabilitiesDir() || join21(homedir17(), ".office-claw");
50088
+ return officeaceCapabilitiesDir() || join23(homedir16(), ".office-claw");
49884
50089
  }
49885
50090
  function officeaceSqlitePath() {
49886
50091
  const capDir = officeaceCapabilitiesDirSafe();
49887
- return join21(resolve5(capDir, ".."), "data", "mcp-connectors.sqlite");
50092
+ return join23(resolve7(capDir, ".."), "data", "mcp-connectors.sqlite");
49888
50093
  }
49889
50094
  function toSqliteModule(value) {
49890
50095
  if (!value || typeof value !== "object")
@@ -49895,7 +50100,7 @@ function toSqliteModule(value) {
49895
50100
  function officeaceRegistered() {
49896
50101
  let hasMcp = false;
49897
50102
  const dbPath = officeaceSqlitePath();
49898
- if (existsSync16(dbPath)) {
50103
+ if (existsSync17(dbPath)) {
49899
50104
  const nodeMajor = Number(process.versions.node.split(".")[0]);
49900
50105
  if (nodeMajor >= 22) {
49901
50106
  try {
@@ -49910,7 +50115,7 @@ function officeaceRegistered() {
49910
50115
  }
49911
50116
  }
49912
50117
  }
49913
- const capFile = join21(officeaceCapabilitiesDirSafe(), "capabilities.json");
50118
+ const capFile = join23(officeaceCapabilitiesDirSafe(), "capabilities.json");
49914
50119
  const cfg = asRecord(readJsonSafe(capFile));
49915
50120
  const capabilities = Array.isArray(cfg.capabilities) ? cfg.capabilities : [];
49916
50121
  const hasSkills = capabilities.some((c) => {
@@ -49920,10 +50125,10 @@ function officeaceRegistered() {
49920
50125
  return hasMcp || hasSkills;
49921
50126
  }
49922
50127
  function atomcodeHome() {
49923
- return process.env.ATOMCODE_HOME || join21(homedir17(), ".atomcode");
50128
+ return process.env.ATOMCODE_HOME || join23(homedir16(), ".atomcode");
49924
50129
  }
49925
50130
  function atomcodeRegistered() {
49926
- const cfg = asRecord(readJsonSafe(join21(atomcodeHome(), "mcp.json")));
50131
+ const cfg = asRecord(readJsonSafe(join23(atomcodeHome(), "mcp.json")));
49927
50132
  return Boolean(asRecord(cfg.mcpServers)["huaweicloud-devkit"]);
49928
50133
  }
49929
50134
  function openclawMcpConfigured(cfg) {
@@ -49937,20 +50142,20 @@ function openclawMcpConfigured(cfg) {
49937
50142
  return false;
49938
50143
  }
49939
50144
  function openclawRegistered() {
49940
- const pluginCfg = readJsonSafe(join21(homedir17(), ".agents", "huaweicloud-plugins", ".mcp.json"));
50145
+ const pluginCfg = readJsonSafe(join23(homedir16(), ".agents", "huaweicloud-plugins", ".mcp.json"));
49941
50146
  if (openclawMcpConfigured(pluginCfg))
49942
50147
  return true;
49943
- const nativeCfg = readJsonSafe(join21(homedir17(), ".openclaw", "openclaw.json"));
50148
+ const nativeCfg = readJsonSafe(join23(homedir16(), ".openclaw", "openclaw.json"));
49944
50149
  return openclawMcpConfigured(nativeCfg);
49945
50150
  }
49946
50151
  function hermesHome() {
49947
50152
  if (process.env.HERMES_HOME)
49948
50153
  return process.env.HERMES_HOME;
49949
- return join21(homedir17(), ".hermes");
50154
+ return join23(homedir16(), ".hermes");
49950
50155
  }
49951
50156
  function hermesRegistered() {
49952
- const configPath = join21(hermesHome(), "config.yaml");
49953
- if (!existsSync16(configPath))
50157
+ const configPath = join23(hermesHome(), "config.yaml");
50158
+ if (!existsSync17(configPath))
49954
50159
  return false;
49955
50160
  try {
49956
50161
  const content = readFileSync18(configPath, "utf8");
@@ -50016,7 +50221,7 @@ var init_agent_registration = __esm({
50016
50221
  // plugins/huaweicloud-core/dist.new/update-upgrade.js
50017
50222
  import { spawnSync as spawnSync6 } from "node:child_process";
50018
50223
  function defaultSpawn(command, args, options) {
50019
- return spawnSync6(command, args, options);
50224
+ return spawnSync6([command, ...args].join(" "), options);
50020
50225
  }
50021
50226
  function restartMessage(target) {
50022
50227
  if (target === "officeace") {
@@ -50390,18 +50595,18 @@ var init_sandbox_output = __esm({
50390
50595
  });
50391
50596
 
50392
50597
  // plugins/huaweicloud-core/dist.new/sandbox/ws-exec-loader.js
50393
- import { existsSync as existsSync17 } from "node:fs";
50394
- import { dirname as dirname12, join as join22 } from "node:path";
50598
+ import { existsSync as existsSync18 } from "node:fs";
50599
+ import { dirname as dirname14, join as join24 } from "node:path";
50395
50600
  import { fileURLToPath as fileURLToPath6, pathToFileURL } from "node:url";
50396
50601
  function firstExisting(...candidates) {
50397
50602
  for (const candidate of candidates) {
50398
- if (existsSync17(candidate))
50603
+ if (existsSync18(candidate))
50399
50604
  return candidate;
50400
50605
  }
50401
50606
  return candidates[candidates.length - 1];
50402
50607
  }
50403
50608
  function resolveWsExecIndexUrl() {
50404
- const barrel = firstExisting(join22(__dirname4, "..", "ws-exec", "index.js"), join22(__dirname4, "ws-exec", "index.js"), join22(__dirname4, "..", "ws-exec", "index.ts"));
50609
+ const barrel = firstExisting(join24(__dirname4, "..", "ws-exec", "index.js"), join24(__dirname4, "ws-exec", "index.js"), join24(__dirname4, "..", "ws-exec", "index.ts"));
50405
50610
  return pathToFileURL(barrel).href;
50406
50611
  }
50407
50612
  async function loadWsExec() {
@@ -50419,7 +50624,7 @@ var init_ws_exec_loader = __esm({
50419
50624
  }
50420
50625
  return path;
50421
50626
  };
50422
- __dirname4 = dirname12(fileURLToPath6(import.meta.url));
50627
+ __dirname4 = dirname14(fileURLToPath6(import.meta.url));
50423
50628
  }
50424
50629
  });
50425
50630
 
@@ -50542,7 +50747,7 @@ async function createConnection(envId, ak, sk, securitytoken, { maxRetries = 3,
50542
50747
  const wait2 = backoff[Math.min(attempt - 2, backoff.length - 1)] ?? 1e3;
50543
50748
  process.stderr.write(`createConnection: retryable error (${lastFailure.kind}) \u2014 retry ${attempt - 1}/${maxRetries} in ${wait2}ms
50544
50749
  `);
50545
- await new Promise((resolve9) => setTimeout(resolve9, wait2));
50750
+ await new Promise((resolve10) => setTimeout(resolve10, wait2));
50546
50751
  }
50547
50752
  const { status, data } = await apiPost(`/open-api-public/v1/devenvs/${envId}/connections`, { source: "CLI" }, ak, sk, securitytoken);
50548
50753
  const payload = asRecord(data);
@@ -50586,7 +50791,7 @@ async function waitForConnection(connectionId, envId, ak, sk, securitytoken) {
50586
50791
  source: extensions.source
50587
50792
  };
50588
50793
  }
50589
- await new Promise((resolve9) => setTimeout(resolve9, 1e3));
50794
+ await new Promise((resolve10) => setTimeout(resolve10, 1e3));
50590
50795
  }
50591
50796
  throw new Error(`Timed out waiting for connection ${connectionId}`);
50592
50797
  }
@@ -50649,7 +50854,7 @@ async function getSession(workspaceId2, username2, timeoutMs) {
50649
50854
  async function createTunnelSession(workspaceId2, username2, timeoutMs = 3e4) {
50650
50855
  const { wsUrl, source, WebSocketImpl, wsExec } = await openHwlinkConnection(workspaceId2);
50651
50856
  const mux = new wsExec.HwlinkWebSocketMultiplexer(wsUrl, source, { WebSocketImpl, protocol: "devenv" });
50652
- await new Promise((resolve9, reject) => {
50857
+ await new Promise((resolve10, reject) => {
50653
50858
  const timer = setTimeout(() => {
50654
50859
  clearInterval(interval);
50655
50860
  reject(new Error("tunnel session WebSocket open timeout"));
@@ -50658,7 +50863,7 @@ async function createTunnelSession(workspaceId2, username2, timeoutMs = 3e4) {
50658
50863
  if (mux.readyState === 1) {
50659
50864
  clearTimeout(timer);
50660
50865
  clearInterval(interval);
50661
- resolve9();
50866
+ resolve10();
50662
50867
  } else if (mux.readyState === 3) {
50663
50868
  clearTimeout(timer);
50664
50869
  clearInterval(interval);
@@ -50721,9 +50926,9 @@ var init_hwlink_connection = __esm({
50721
50926
  });
50722
50927
 
50723
50928
  // plugins/huaweicloud-core/dist.new/sandbox/upload-file.js
50724
- import { existsSync as existsSync18, readFileSync as readFileSync19, statSync as statSync4 } from "node:fs";
50725
- import { dirname as dirname13 } from "node:path";
50726
- import { tmpdir } from "node:os";
50929
+ import { existsSync as existsSync19, readFileSync as readFileSync19, statSync as statSync4 } from "node:fs";
50930
+ import { dirname as dirname15 } from "node:path";
50931
+ import { tmpdir as tmpdir2 } from "node:os";
50727
50932
  import { createHash as createHash3 } from "node:crypto";
50728
50933
  function splitBase64Chunks(base643, chunkSize = UPLOAD_CHUNK_SIZE) {
50729
50934
  const chunks = [];
@@ -50735,7 +50940,7 @@ function splitBase64Chunks(base643, chunkSize = UPLOAD_CHUNK_SIZE) {
50735
50940
  function classifyLocalUploadPath(localPath, kind = "file") {
50736
50941
  const expected = kind === "directory" ? "directory" : "regular file";
50737
50942
  const prefix = kind === "directory" ? "sandbox upload project" : "sandbox upload";
50738
- if (existsSync18(localPath)) {
50943
+ if (existsSync19(localPath)) {
50739
50944
  const stat = statSync4(localPath);
50740
50945
  const matches = kind === "directory" ? stat.isDirectory() : stat.isFile();
50741
50946
  if (!matches) {
@@ -50743,9 +50948,9 @@ function classifyLocalUploadPath(localPath, kind = "file") {
50743
50948
  }
50744
50949
  return null;
50745
50950
  }
50746
- const parent = dirname13(localPath);
50747
- if (!existsSync18(parent)) {
50748
- return new Error(`${prefix}: directory not found: ${parent}. The DevKit MCP server reads files from the machine it runs on. Verify the path, or first copy the ${expected} to the local temp directory (${tmpdir()}) and upload from there.`);
50951
+ const parent = dirname15(localPath);
50952
+ if (!existsSync19(parent)) {
50953
+ return new Error(`${prefix}: directory not found: ${parent}. The DevKit MCP server reads files from the machine it runs on. Verify the path, or first copy the ${expected} to the local temp directory (${tmpdir2()}) and upload from there.`);
50749
50954
  }
50750
50955
  return new Error(`${prefix}: local ${expected} not found: ${localPath}`);
50751
50956
  }
@@ -50827,9 +51032,9 @@ var init_upload_file = __esm({
50827
51032
  });
50828
51033
 
50829
51034
  // plugins/huaweicloud-core/dist.new/sandbox/upload-diagnostics.js
50830
- import { appendFileSync as appendFileSync3, existsSync as existsSync19, statSync as statSync5, unlinkSync as unlinkSync3 } from "node:fs";
50831
- import { join as join23 } from "node:path";
50832
- import { tmpdir as tmpdir2 } from "node:os";
51035
+ import { appendFileSync as appendFileSync3, existsSync as existsSync20, statSync as statSync5, unlinkSync as unlinkSync3 } from "node:fs";
51036
+ import { join as join25 } from "node:path";
51037
+ import { tmpdir as tmpdir3 } from "node:os";
50833
51038
  function errorMessage2(error62) {
50834
51039
  if (error62 instanceof Error && error62.message)
50835
51040
  return error62.message;
@@ -50852,7 +51057,7 @@ function uploadLog(message) {
50852
51057
  }
50853
51058
  function rotateUploadLog(maxBytes = 100 * 1024) {
50854
51059
  try {
50855
- if (existsSync19(UPLOAD_LOG_PATH)) {
51060
+ if (existsSync20(UPLOAD_LOG_PATH)) {
50856
51061
  const stat = statSync5(UPLOAD_LOG_PATH);
50857
51062
  if (stat.size > maxBytes) {
50858
51063
  unlinkSync3(UPLOAD_LOG_PATH);
@@ -50865,7 +51070,7 @@ var UPLOAD_LOG_PATH;
50865
51070
  var init_upload_diagnostics = __esm({
50866
51071
  "plugins/huaweicloud-core/dist.new/sandbox/upload-diagnostics.js"() {
50867
51072
  "use strict";
50868
- UPLOAD_LOG_PATH = join23(tmpdir2(), "sandbox-upload.log");
51073
+ UPLOAD_LOG_PATH = join25(tmpdir3(), "sandbox-upload.log");
50869
51074
  }
50870
51075
  });
50871
51076
 
@@ -50885,7 +51090,7 @@ async function uploadViaTunnel(localPort, archivePath, archiveSize, archiveRemot
50885
51090
  "",
50886
51091
  ""
50887
51092
  ].join("\r\n");
50888
- return new Promise((resolve9, reject) => {
51093
+ return new Promise((resolve10, reject) => {
50889
51094
  let settled = false;
50890
51095
  const done = (fn) => {
50891
51096
  if (!settled) {
@@ -50912,7 +51117,7 @@ async function uploadViaTunnel(localPort, archivePath, archiveSize, archiveRemot
50912
51117
  return;
50913
51118
  }
50914
51119
  try {
50915
- resolve9(asRecord(JSON.parse(body)));
51120
+ resolve10(asRecord(JSON.parse(body)));
50916
51121
  } catch {
50917
51122
  reject(new Error(`invalid JSON response: ${body.slice(0, 200)}`));
50918
51123
  }
@@ -50958,13 +51163,13 @@ async function waitForServerReady(localPort) {
50958
51163
  for (let i = 0; i < SERVER_HEALTH_MAX_RETRIES; i++) {
50959
51164
  try {
50960
51165
  uploadLog(`waitForServerReady: attempt ${i + 1}, checking http://localhost:${localPort}/health`);
50961
- const ok = await new Promise((resolve9) => {
51166
+ const ok = await new Promise((resolve10) => {
50962
51167
  let settled = false;
50963
51168
  const done = (val) => {
50964
51169
  if (!settled) {
50965
51170
  settled = true;
50966
51171
  sock.destroy();
50967
- resolve9(val);
51172
+ resolve10(val);
50968
51173
  }
50969
51174
  };
50970
51175
  const sock = netConnect({ host: "127.0.0.1", port: localPort }, () => {
@@ -51006,7 +51211,7 @@ var init_tunnel_http = __esm({
51006
51211
  // plugins/huaweicloud-core/dist.new/sandbox/upload-transport.js
51007
51212
  import { readFileSync as readFileSync21, statSync as statSync6 } from "node:fs";
51008
51213
  import { randomBytes as randomBytes3 } from "node:crypto";
51009
- import { dirname as dirname14, join as join24 } from "node:path";
51214
+ import { dirname as dirname16, join as join26 } from "node:path";
51010
51215
  import { fileURLToPath as fileURLToPath7 } from "node:url";
51011
51216
  function generateUploadToken() {
51012
51217
  return randomBytes3(16).toString("hex");
@@ -51081,8 +51286,8 @@ var init_upload_transport = __esm({
51081
51286
  init_ws_exec_loader();
51082
51287
  init_upload_diagnostics();
51083
51288
  init_tunnel_http();
51084
- __dirname5 = dirname14(fileURLToPath7(import.meta.url));
51085
- SANDBOX_FILE_SERVER_SCRIPT = readFileSync21(firstExisting(join24(__dirname5, "sandbox-file-server.py"), join24(__dirname5, "sandbox", "sandbox-file-server.py")), "utf8");
51289
+ __dirname5 = dirname16(fileURLToPath7(import.meta.url));
51290
+ SANDBOX_FILE_SERVER_SCRIPT = readFileSync21(firstExisting(join26(__dirname5, "sandbox-file-server.py"), join26(__dirname5, "sandbox", "sandbox-file-server.py")), "utf8");
51086
51291
  TUNNEL_READY_TIMEOUT_MS = 3e4;
51087
51292
  }
51088
51293
  });
@@ -51090,10 +51295,10 @@ var init_upload_transport = __esm({
51090
51295
  // plugins/huaweicloud-core/dist.new/sandbox/upload-project.js
51091
51296
  import { execFile } from "node:child_process";
51092
51297
  import { promisify } from "node:util";
51093
- import { existsSync as existsSync20, mkdirSync as mkdirSync8, rmSync as rmSync5, statSync as statSync7, createReadStream } from "node:fs";
51298
+ import { existsSync as existsSync21, mkdirSync as mkdirSync10, rmSync as rmSync6, statSync as statSync7, createReadStream } from "node:fs";
51094
51299
  import { createHash as createHash4 } from "node:crypto";
51095
- import { basename as basename3, dirname as dirname15, join as join25 } from "node:path";
51096
- import { tmpdir as tmpdir3 } from "node:os";
51300
+ import { basename as basename4, dirname as dirname17, join as join27 } from "node:path";
51301
+ import { tmpdir as tmpdir4 } from "node:os";
51097
51302
  function errorLabel(error62) {
51098
51303
  if (error62 && typeof error62 === "object" && !Array.isArray(error62)) {
51099
51304
  const record2 = error62;
@@ -51107,18 +51312,18 @@ function errorLabel(error62) {
51107
51312
  return "unknown";
51108
51313
  }
51109
51314
  async function createTarGz(localDir, exclude = []) {
51110
- const archiveName = `${basename3(localDir)}.tar.gz`;
51111
- const archiveDir = join25(tmpdir3(), `sandbox-upload-${Date.now()}`);
51112
- mkdirSync8(archiveDir, { recursive: true });
51113
- const archivePath = join25(archiveDir, archiveName);
51114
- const hasGit = existsSync20(join25(localDir, ".git"));
51315
+ const archiveName = `${basename4(localDir)}.tar.gz`;
51316
+ const archiveDir = join27(tmpdir4(), `sandbox-upload-${Date.now()}`);
51317
+ mkdirSync10(archiveDir, { recursive: true });
51318
+ const archivePath = join27(archiveDir, archiveName);
51319
+ const hasGit = existsSync21(join27(localDir, ".git"));
51115
51320
  if (hasGit) {
51116
51321
  await execFileAsync("git", [
51117
51322
  "-C",
51118
51323
  localDir,
51119
51324
  "archive",
51120
51325
  "--format=tar.gz",
51121
- `--prefix=${basename3(localDir)}/`,
51326
+ `--prefix=${basename4(localDir)}/`,
51122
51327
  `--output=${archivePath}`,
51123
51328
  "HEAD"
51124
51329
  ]);
@@ -51135,20 +51340,20 @@ async function createTarGz(localDir, exclude = []) {
51135
51340
  args.push("--exclude", pattern);
51136
51341
  }
51137
51342
  }
51138
- args.push("-czf", archivePath, "-C", dirname15(localDir), basename3(localDir));
51343
+ args.push("-czf", archivePath, "-C", dirname17(localDir), basename4(localDir));
51139
51344
  await execFileAsync("tar", args);
51140
51345
  }
51141
51346
  return archivePath;
51142
51347
  }
51143
51348
  async function computeMd5(filePath) {
51144
- return new Promise((resolve9, reject) => {
51349
+ return new Promise((resolve10, reject) => {
51145
51350
  const hash2 = createHash4("md5");
51146
- createReadStream(filePath).on("data", (chunk) => hash2.update(chunk)).on("end", () => resolve9(hash2.digest("hex"))).on("error", reject);
51351
+ createReadStream(filePath).on("data", (chunk) => hash2.update(chunk)).on("end", () => resolve10(hash2.digest("hex"))).on("error", reject);
51147
51352
  });
51148
51353
  }
51149
51354
  function cleanupLocalArchive(archivePath) {
51150
51355
  try {
51151
- rmSync5(dirname15(archivePath), { recursive: true, force: true });
51356
+ rmSync6(dirname17(archivePath), { recursive: true, force: true });
51152
51357
  } catch {
51153
51358
  }
51154
51359
  }
@@ -51161,7 +51366,7 @@ async function uploadProjectWithSession(workspaceId2, localDir, remoteDir, usern
51161
51366
  throw localError;
51162
51367
  }
51163
51368
  rotateUploadLog();
51164
- const projectName = basename3(localDir);
51369
+ const projectName = basename4(localDir);
51165
51370
  const targetParentDir = remoteDir || "/workspace";
51166
51371
  const archiveRemotePath = `${targetParentDir}/${projectName}.tar.gz`;
51167
51372
  const archivePath = await createTarGz(localDir, options.exclude);
@@ -51706,14 +51911,14 @@ var init_session_manager = __esm({
51706
51911
  });
51707
51912
 
51708
51913
  // plugins/huaweicloud-core/dist.new/lib/hdkit/sandbox-pool.js
51709
- import { readFileSync as readFileSync22, writeFileSync as writeFileSync9, mkdirSync as mkdirSync9, renameSync as renameSync6 } from "node:fs";
51710
- import { join as join26, dirname as dirname16 } from "node:path";
51711
- import { homedir as homedir18 } from "node:os";
51914
+ import { readFileSync as readFileSync22, writeFileSync as writeFileSync10, mkdirSync as mkdirSync11, renameSync as renameSync6 } from "node:fs";
51915
+ import { join as join28, dirname as dirname18 } from "node:path";
51916
+ import { homedir as homedir17 } from "node:os";
51712
51917
  function isPoolType(value) {
51713
51918
  return POOL_TYPES.has(value);
51714
51919
  }
51715
51920
  function cachePath() {
51716
- return process.env.HW_SANDBOX_POOL_CACHE_PATH || join26(homedir18(), ".config", "huaweicloud", "sandbox-pools.json");
51921
+ return process.env.HW_SANDBOX_POOL_CACHE_PATH || join28(homedir17(), ".config", "huaweicloud", "sandbox-pools.json");
51717
51922
  }
51718
51923
  function validatePoolType(raw) {
51719
51924
  if (raw === void 0 || raw === null || raw === "")
@@ -51781,17 +51986,17 @@ function persistCache() {
51781
51986
  try {
51782
51987
  ensureCacheLoaded();
51783
51988
  const file2 = cachePath();
51784
- mkdirSync9(dirname16(file2), { recursive: true, mode: 448 });
51989
+ mkdirSync11(dirname18(file2), { recursive: true, mode: 448 });
51785
51990
  const workspaces = {};
51786
51991
  for (const [wsId, entry] of workspacePool)
51787
51992
  workspaces[wsId] = entry;
51788
51993
  const payload = JSON.stringify({ workspaces }, null, 2);
51789
51994
  const tmp = `${file2}.tmp`;
51790
- writeFileSync9(tmp, payload, { mode: 384 });
51995
+ writeFileSync10(tmp, payload, { mode: 384 });
51791
51996
  try {
51792
51997
  renameSync6(tmp, file2);
51793
51998
  } catch {
51794
- writeFileSync9(file2, payload, { mode: 384 });
51999
+ writeFileSync10(file2, payload, { mode: 384 });
51795
52000
  }
51796
52001
  } catch {
51797
52002
  }
@@ -53168,9 +53373,9 @@ var init_hdkitservice_api = __esm({
53168
53373
  });
53169
53374
 
53170
53375
  // plugins/huaweicloud-core/dist.new/sandbox/devbridge-key.js
53171
- import { readFileSync as readFileSync23, writeFileSync as writeFileSync10, mkdirSync as mkdirSync10, existsSync as existsSync21, chmodSync as chmodSync2 } from "node:fs";
53172
- import { join as join27, dirname as dirname17 } from "node:path";
53173
- import { homedir as homedir19 } from "node:os";
53376
+ import { readFileSync as readFileSync23, writeFileSync as writeFileSync11, mkdirSync as mkdirSync12, existsSync as existsSync22, chmodSync as chmodSync3 } from "node:fs";
53377
+ import { join as join29, dirname as dirname19 } from "node:path";
53378
+ import { homedir as homedir18 } from "node:os";
53174
53379
  import { createHash as createHash5 } from "node:crypto";
53175
53380
  function keyNameForPool(poolType) {
53176
53381
  if (poolType === "ephemeral" || poolType === "persistent")
@@ -53189,12 +53394,12 @@ function readCache() {
53189
53394
  }
53190
53395
  }
53191
53396
  function writeCache(cache2) {
53192
- const dir = dirname17(CACHE_FILE);
53193
- if (!existsSync21(dir))
53194
- mkdirSync10(dir, { recursive: true });
53195
- writeFileSync10(CACHE_FILE, JSON.stringify(cache2, null, 2), { mode: 384 });
53397
+ const dir = dirname19(CACHE_FILE);
53398
+ if (!existsSync22(dir))
53399
+ mkdirSync12(dir, { recursive: true });
53400
+ writeFileSync11(CACHE_FILE, JSON.stringify(cache2, null, 2), { mode: 384 });
53196
53401
  try {
53197
- chmodSync2(CACHE_FILE, 384);
53402
+ chmodSync3(CACHE_FILE, 384);
53198
53403
  } catch {
53199
53404
  }
53200
53405
  }
@@ -53292,7 +53497,7 @@ var init_devbridge_key = __esm({
53292
53497
  persistent: "devkit-persistent"
53293
53498
  };
53294
53499
  DEFAULT_POOL = "ephemeral";
53295
- CACHE_FILE = join27(homedir19(), ".config", "huaweicloud", "devbridge-api-keys.json");
53500
+ CACHE_FILE = join29(homedir18(), ".config", "huaweicloud", "devbridge-api-keys.json");
53296
53501
  }
53297
53502
  });
53298
53503
 
@@ -53356,9 +53561,9 @@ var init_handlers_tunnel = __esm({
53356
53561
 
53357
53562
  // plugins/huaweicloud-core/dist.new/packs/sandbox/git-transfer.js
53358
53563
  import { execFile as execFile2 } from "node:child_process";
53359
- import { tmpdir as tmpdir4 } from "node:os";
53360
- import { mkdirSync as mkdirSync11, rmSync as rmSync6 } from "node:fs";
53361
- import { basename as basename4, dirname as dirname18, join as join28 } from "node:path";
53564
+ import { tmpdir as tmpdir5 } from "node:os";
53565
+ import { mkdirSync as mkdirSync13, rmSync as rmSync7 } from "node:fs";
53566
+ import { basename as basename5, dirname as dirname20, join as join30 } from "node:path";
53362
53567
  import { promisify as promisify2 } from "node:util";
53363
53568
  async function isGitAvailable() {
53364
53569
  try {
@@ -53369,9 +53574,9 @@ async function isGitAvailable() {
53369
53574
  }
53370
53575
  }
53371
53576
  async function gitCloneToLocal(repoUrl, branch, targetBasename) {
53372
- const tempRoot = join28(tmpdir4(), `hw-sandbox-git-${Date.now()}`);
53373
- const cloneDir = join28(tempRoot, targetBasename);
53374
- mkdirSync11(tempRoot, { recursive: true });
53577
+ const tempRoot = join30(tmpdir5(), `hw-sandbox-git-${Date.now()}`);
53578
+ const cloneDir = join30(tempRoot, targetBasename);
53579
+ mkdirSync13(tempRoot, { recursive: true });
53375
53580
  const args = ["clone", "--depth", "1"];
53376
53581
  if (branch)
53377
53582
  args.push("-b", branch);
@@ -53396,10 +53601,10 @@ async function transferGitRepo(args, devStageId, connectResult) {
53396
53601
  if (hasGit) {
53397
53602
  let tempRoot = null;
53398
53603
  try {
53399
- const targetName = basename4(target_path);
53604
+ const targetName = basename5(target_path);
53400
53605
  const { cloneDir, tempRoot: root } = await gitCloneToLocal(repo_url, repo_branch, targetName);
53401
53606
  tempRoot = root;
53402
- await uploadProjectWithSession(devStageId, cloneDir, dirname18(target_path), "root", 3e5, {
53607
+ await uploadProjectWithSession(devStageId, cloneDir, dirname20(target_path), "root", 3e5, {
53403
53608
  extract: true,
53404
53609
  exclude: [".git", "node_modules"]
53405
53610
  });
@@ -53409,7 +53614,7 @@ async function transferGitRepo(args, devStageId, connectResult) {
53409
53614
  } finally {
53410
53615
  if (tempRoot) {
53411
53616
  try {
53412
- rmSync6(tempRoot, { recursive: true, force: true });
53617
+ rmSync7(tempRoot, { recursive: true, force: true });
53413
53618
  } catch {
53414
53619
  }
53415
53620
  }
@@ -53615,7 +53820,7 @@ var init_credential_validator = __esm({
53615
53820
 
53616
53821
  // plugins/huaweicloud-core/dist.new/koocli-version.js
53617
53822
  import { readFileSync as readFileSync24 } from "node:fs";
53618
- import { resolve as resolve6, dirname as dirname19 } from "node:path";
53823
+ import { resolve as resolve8, dirname as dirname21 } from "node:path";
53619
53824
  import { fileURLToPath as fileURLToPath8 } from "node:url";
53620
53825
  function getKooCliVersion() {
53621
53826
  try {
@@ -53669,24 +53874,24 @@ var init_koocli_version = __esm({
53669
53874
  "plugins/huaweicloud-core/dist.new/koocli-version.js"() {
53670
53875
  "use strict";
53671
53876
  init_as_text();
53672
- __dirname6 = dirname19(fileURLToPath8(import.meta.url));
53673
- PACKAGE_JSON = resolve6(__dirname6, "..", "..", "..", "package.json");
53877
+ __dirname6 = dirname21(fileURLToPath8(import.meta.url));
53878
+ PACKAGE_JSON = resolve8(__dirname6, "..", "..", "..", "package.json");
53674
53879
  VERSION_RE = /\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?/;
53675
53880
  KOOCLI_UPDATE_BANNER_PREFIX = /^\s*(?:可执行|可以执行|请执行)?\s*hcloud\s+update\s+(?:更新至|update to)\s*\d[\w.-]*[\s。!!]*/;
53676
53881
  }
53677
53882
  });
53678
53883
 
53679
53884
  // plugins/huaweicloud-core/dist.new/lib/koocli-paths.js
53680
- import { homedir as homedir20 } from "node:os";
53681
- import { join as join29 } from "node:path";
53885
+ import { homedir as homedir19 } from "node:os";
53886
+ import { join as join31 } from "node:path";
53682
53887
  function configBase() {
53683
- return process.env.HUAWEICLOUD_HOME || homedir20();
53888
+ return process.env.HUAWEICLOUD_HOME || homedir19();
53684
53889
  }
53685
53890
  function kooCliInstallLogPath() {
53686
- return join29(configBase(), ".config", "huaweicloud", "logs", "koocli-install.log");
53891
+ return join31(configBase(), ".config", "huaweicloud", "logs", "koocli-install.log");
53687
53892
  }
53688
53893
  function kooCliInstallLockPath() {
53689
- return join29(configBase(), ".config", "huaweicloud", ".koocli-install.lock");
53894
+ return join31(configBase(), ".config", "huaweicloud", ".koocli-install.lock");
53690
53895
  }
53691
53896
  var init_koocli_paths = __esm({
53692
53897
  "plugins/huaweicloud-core/dist.new/lib/koocli-paths.js"() {
@@ -53839,15 +54044,15 @@ __export(reconcile_exports, {
53839
54044
  scanState: () => scanState
53840
54045
  });
53841
54046
  import { createHash as createHash6 } from "node:crypto";
53842
- import { existsSync as existsSync22, readFileSync as readFileSync25, statSync as statSync8 } from "node:fs";
53843
- import { join as join30 } from "node:path";
53844
- import { homedir as homedir21 } from "node:os";
54047
+ import { existsSync as existsSync23, readFileSync as readFileSync25, statSync as statSync8 } from "node:fs";
54048
+ import { join as join32 } from "node:path";
54049
+ import { homedir as homedir20 } from "node:os";
53845
54050
  import { spawnSync as spawnSync8 } from "node:child_process";
53846
54051
  function toLastSync(value) {
53847
54052
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
53848
54053
  }
53849
54054
  function kooCliConfigPath() {
53850
- return process.env.HCLOUD_CONFIG_PATH || join30(homedir21(), ".hcloud", "config.json");
54055
+ return process.env.HCLOUD_CONFIG_PATH || join32(homedir20(), ".hcloud", "config.json");
53851
54056
  }
53852
54057
  function fingerprint(ak, sk) {
53853
54058
  if (!ak || !sk)
@@ -53855,7 +54060,7 @@ function fingerprint(ak, sk) {
53855
54060
  return createHash6("sha256").update(`${asText(ak)}${asText(sk)}`).digest("hex").slice(0, 8);
53856
54061
  }
53857
54062
  function isManualModified(path) {
53858
- if (!existsSync22(path))
54063
+ if (!existsSync23(path))
53859
54064
  return false;
53860
54065
  const lastSyncRaw = readLastSync();
53861
54066
  try {
@@ -53869,7 +54074,7 @@ function isManualModified(path) {
53869
54074
  }
53870
54075
  function readKooCliProfiles() {
53871
54076
  const configPath = kooCliConfigPath();
53872
- if (!existsSync22(configPath)) {
54077
+ if (!existsSync23(configPath)) {
53873
54078
  const e = errorFromTable("HDKIT_KOOCLI_NOT_READY", "KooCLI config not found");
53874
54079
  return { error: e.messageZh, code: e.code, messageZh: e.messageZh, action: e.action, nextStep: e.nextStep };
53875
54080
  }
@@ -53949,7 +54154,7 @@ function scanState() {
53949
54154
  const s2SyncedByDevkit = s1Fingerprint ? s2CurrentMatchesLastDevkitSync(kooCli, s1, s1Fingerprint) : false;
53950
54155
  const effectiveCurrentFp = s2SyncedByDevkit ? s1Fingerprint : currentFp;
53951
54156
  const envFingerprint = fingerprint(envAk, envSk);
53952
- const s3 = existsSync22(obsConfigPath()) ? parseS3ObsConfig(obsConfigPath()) : null;
54157
+ const s3 = existsSync23(obsConfigPath()) ? parseS3ObsConfig(obsConfigPath()) : null;
53953
54158
  const s3Fingerprint = s3 ? fingerprint(s3.ak, s3.sk) : null;
53954
54159
  let hasRuntime = false;
53955
54160
  let runtimeFingerprint = null;
@@ -54060,11 +54265,11 @@ var init_reconcile = __esm({
54060
54265
  });
54061
54266
 
54062
54267
  // plugins/huaweicloud-core/dist.new/auth/project-id.js
54063
- import { existsSync as existsSync23 } from "node:fs";
54268
+ import { existsSync as existsSync24 } from "node:fs";
54064
54269
  import { spawnSync as spawnSync9 } from "node:child_process";
54065
54270
  function hcloudCommand(args) {
54066
54271
  const { executable, argsPrefix } = resolveHcloudCommand();
54067
- if (/\.(mjs|cjs|js)$/i.test(executable) && existsSync23(executable)) {
54272
+ if (/\.(mjs|cjs|js)$/i.test(executable) && existsSync24(executable)) {
54068
54273
  return { file: process.execPath, args: [executable, ...argsPrefix, ...args] };
54069
54274
  }
54070
54275
  return { file: executable, args: [...argsPrefix, ...args] };
@@ -54134,8 +54339,8 @@ var init_project_id = __esm({
54134
54339
  });
54135
54340
 
54136
54341
  // plugins/huaweicloud-core/dist.new/lib/credentials.js
54137
- import { readFileSync as readFileSync26, existsSync as existsSync24, rmSync as rmSync7 } from "node:fs";
54138
- import { join as join31, dirname as dirname20 } from "node:path";
54342
+ import { readFileSync as readFileSync26, existsSync as existsSync25, rmSync as rmSync8 } from "node:fs";
54343
+ import { join as join33, dirname as dirname22 } from "node:path";
54139
54344
  function asCredentialRecord(value) {
54140
54345
  if (!value || typeof value !== "object" || Array.isArray(value))
54141
54346
  return null;
@@ -54152,9 +54357,9 @@ function asCredentialRecord(value) {
54152
54357
  return result;
54153
54358
  }
54154
54359
  function readImportFile() {
54155
- const path = join31(dirname20(globalCredentialsPath()), "creds-import.json");
54360
+ const path = join33(dirname22(globalCredentialsPath()), "creds-import.json");
54156
54361
  try {
54157
- if (!existsSync24(path))
54362
+ if (!existsSync25(path))
54158
54363
  return null;
54159
54364
  const data = JSON.parse(readFileSync26(path, "utf8"));
54160
54365
  const record2 = asRecord(data);
@@ -54166,16 +54371,16 @@ function readImportFile() {
54166
54371
  };
54167
54372
  } catch {
54168
54373
  try {
54169
- rmSync7(path, { force: true });
54374
+ rmSync8(path, { force: true });
54170
54375
  } catch {
54171
54376
  }
54172
54377
  return null;
54173
54378
  }
54174
54379
  }
54175
54380
  function clearImportFile() {
54176
- const path = join31(dirname20(globalCredentialsPath()), "creds-import.json");
54381
+ const path = join33(dirname22(globalCredentialsPath()), "creds-import.json");
54177
54382
  try {
54178
- rmSync7(path, { force: true });
54383
+ rmSync8(path, { force: true });
54179
54384
  } catch {
54180
54385
  }
54181
54386
  }
@@ -54543,7 +54748,7 @@ var init_pack2 = __esm({
54543
54748
  });
54544
54749
 
54545
54750
  // plugins/huaweicloud-core/dist.new/auth/service.js
54546
- import { existsSync as existsSync25 } from "node:fs";
54751
+ import { existsSync as existsSync26 } from "node:fs";
54547
54752
  function asCredentialRecord2(value) {
54548
54753
  if (!value || typeof value !== "object" || Array.isArray(value))
54549
54754
  return null;
@@ -54722,7 +54927,7 @@ function getAuthStatus(target = "all") {
54722
54927
  mcpSettingsSource: s4Creds ? "codearts" : null,
54723
54928
  stsExpiry,
54724
54929
  credentialPanel,
54725
- obsConfigured: existsSync25(obsConfigPath()),
54930
+ obsConfigured: existsSync26(obsConfigPath()),
54726
54931
  obsConfigPath: obsConfigPath(),
54727
54932
  kooCliInstalled: hcloud.installed,
54728
54933
  kooCliStatus: hcloud.status,
@@ -54856,109 +55061,12 @@ var init_service = __esm({
54856
55061
  }
54857
55062
  });
54858
55063
 
54859
- // plugins/huaweicloud-core/dist.new/lib/pack-state.js
54860
- import { chmodSync as chmodSync3, lstatSync, mkdirSync as mkdirSync12, realpathSync, writeFileSync as writeFileSync11 } from "node:fs";
54861
- import { homedir as homedir22, tmpdir as tmpdir5 } from "node:os";
54862
- import { basename as basename5, dirname as dirname21, join as join32, resolve as resolve7, sep } from "node:path";
54863
- function huaweiConfigBase(env = process.env) {
54864
- return resolve7(env.HUAWEICLOUD_HOME || homedir22(), ".config", "huaweicloud");
54865
- }
54866
- function packStateDir(packId, env = process.env) {
54867
- return join32(huaweiConfigBase(env), "packs", packId);
54868
- }
54869
- function ensurePackState(packId, fileNames, env = process.env) {
54870
- const dir = packStateDir(packId, env);
54871
- try {
54872
- mkdirSync12(dir, { recursive: true, mode: 448 });
54873
- chmodSync3(dir, 448);
54874
- } catch (error62) {
54875
- throw new Error(`cannot provision pack state directory "${dir}": ${error62 instanceof Error ? error62.message : String(error62)}. Fix the permissions, or point HUAWEICLOUD_HOME at a writable location.`, { cause: error62 });
54876
- }
54877
- const files = {};
54878
- for (const name of fileNames) {
54879
- const path = join32(dir, name);
54880
- try {
54881
- try {
54882
- writeFileSync11(path, "", { flag: "wx", mode: 384 });
54883
- } catch (error62) {
54884
- if (error62.code !== "EEXIST")
54885
- throw error62;
54886
- }
54887
- chmodSync3(path, 384);
54888
- files[name] = path;
54889
- } catch (error62) {
54890
- throw new Error(`cannot provision pack state file "${path}": ${error62 instanceof Error ? error62.message : String(error62)}.`, { cause: error62 });
54891
- }
54892
- }
54893
- return { dir, files };
54894
- }
54895
- function isRefusedByGuard(target) {
54896
- if (process.platform === "win32" && /^[a-zA-Z]:[^\\/]/.test(target))
54897
- return true;
54898
- return target.split(/[\\/]/).includes("..");
54899
- }
54900
- function resolveForWrite(target) {
54901
- const absolute = resolve7(tmpdir5(), target);
54902
- const tail = [];
54903
- let current = absolute;
54904
- for (; ; ) {
54905
- try {
54906
- lstatSync(current);
54907
- break;
54908
- } catch {
54909
- tail.unshift(basename5(current));
54910
- const parent = dirname21(current);
54911
- if (parent === current)
54912
- break;
54913
- current = parent;
54914
- }
54915
- }
54916
- try {
54917
- const real = realpathSync(current);
54918
- return tail.length === 0 ? real : join32(real, ...tail);
54919
- } catch {
54920
- return null;
54921
- }
54922
- }
54923
- function protectedTreeRoots(env = process.env) {
54924
- const candidates = [huaweiConfigBase(env)];
54925
- for (const key of ["HUAWEICLOUD_MCP_POLICY_FILE", "HUAWEICLOUD_MCP_AUDIT_FILE"]) {
54926
- const value = (env[key] ?? "").trim();
54927
- if (value !== "")
54928
- candidates.push(value);
54929
- }
54930
- const roots = [];
54931
- for (const candidate of candidates) {
54932
- const resolved = resolveForWrite(candidate);
54933
- if (resolved === null)
54934
- return null;
54935
- roots.push(resolved);
54936
- }
54937
- return roots;
54938
- }
54939
- function isInsideProtectedTree(target, env = process.env) {
54940
- if (isRefusedByGuard(target))
54941
- return true;
54942
- const roots = protectedTreeRoots(env);
54943
- if (roots === null)
54944
- return true;
54945
- const resolved = resolveForWrite(target);
54946
- if (resolved === null)
54947
- return true;
54948
- return roots.some((root) => resolved === root || resolved.startsWith(root + sep));
54949
- }
54950
- var init_pack_state = __esm({
54951
- "plugins/huaweicloud-core/dist.new/lib/pack-state.js"() {
54952
- "use strict";
54953
- }
54954
- });
54955
-
54956
55064
  // plugins/huaweicloud-core/dist.new/lib/approval-tokens.js
54957
- import { createHash as createHash7, randomUUID as randomUUID2 } from "node:crypto";
54958
- 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
- import { dirname as dirname22, join as join33 } from "node:path";
55065
+ import { createHash as createHash7, createHmac as createHmac3, randomUUID as randomUUID2, timingSafeEqual } from "node:crypto";
55066
+ import { existsSync as existsSync27, mkdirSync as mkdirSync14, readdirSync as readdirSync4, readFileSync as readFileSync27, renameSync as renameSync7, statSync as statSync9, unlinkSync as unlinkSync4, writeFileSync as writeFileSync12 } from "node:fs";
55067
+ import { dirname as dirname23, join as join34 } from "node:path";
54960
55068
  function approvalFilePath() {
54961
- return join33(huaweiConfigBase(), "approvals.json");
55069
+ return join34(devkitStateBase(), "approvals.json");
54962
55070
  }
54963
55071
  function sha256Hex2(data) {
54964
55072
  return createHash7("sha256").update(data).digest("hex");
@@ -54997,7 +55105,7 @@ function hashArgs(args) {
54997
55105
  function readApprovals() {
54998
55106
  try {
54999
55107
  const path = approvalFilePath();
55000
- if (!existsSync26(path))
55108
+ if (!existsSync27(path))
55001
55109
  return {};
55002
55110
  const parsed = JSON.parse(readFileSync27(path, "utf8"));
55003
55111
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
@@ -55018,7 +55126,9 @@ function readApprovals() {
55018
55126
  argsRedacted: entry.argsRedacted,
55019
55127
  createdAt: entry.createdAt,
55020
55128
  ...entry.secretsSubstitutable === true ? { secretsSubstitutable: true } : {},
55021
- ...entry.argsPinView !== void 0 ? { argsPinView: entry.argsPinView } : {}
55129
+ ...entry.argsPinView !== void 0 ? { argsPinView: entry.argsPinView } : {},
55130
+ ...isApprovalEntryState(entry.state) ? { state: entry.state } : {},
55131
+ ...isConfirmGrant(entry.confirmGrant) ? { confirmGrant: { confirmedAt: entry.confirmGrant.confirmedAt, mac: entry.confirmGrant.mac } } : {}
55022
55132
  };
55023
55133
  }
55024
55134
  return result;
@@ -55026,10 +55136,19 @@ function readApprovals() {
55026
55136
  return {};
55027
55137
  }
55028
55138
  }
55139
+ function isApprovalEntryState(value) {
55140
+ return value === "awaiting_user" || value === "user_confirmed";
55141
+ }
55142
+ function isConfirmGrant(value) {
55143
+ if (!value || typeof value !== "object" || Array.isArray(value))
55144
+ return false;
55145
+ const grant = value;
55146
+ return typeof grant.confirmedAt === "number" && typeof grant.mac === "string";
55147
+ }
55029
55148
  function writeApprovals(map2) {
55030
55149
  try {
55031
55150
  const path = approvalFilePath();
55032
- mkdirSync13(dirname22(path), { recursive: true });
55151
+ mkdirSync14(dirname23(path), { recursive: true });
55033
55152
  const tmp = `${path}.${process.pid}.tmp`;
55034
55153
  writeFileSync12(tmp, JSON.stringify(map2), { encoding: "utf8", mode: 384 });
55035
55154
  renameSync7(tmp, path);
@@ -55047,12 +55166,12 @@ function pruneStale(map2, now = Date.now()) {
55047
55166
  return changed;
55048
55167
  }
55049
55168
  function consumedMarkerDir() {
55050
- return join33(huaweiConfigBase(), "approvals-consumed");
55169
+ return join34(devkitStateBase(), "approvals-consumed");
55051
55170
  }
55052
55171
  function claimSingleUse(token) {
55053
55172
  try {
55054
- mkdirSync13(consumedMarkerDir(), { recursive: true, mode: 448 });
55055
- writeFileSync12(join33(consumedMarkerDir(), `${token}.claimed`), "", { flag: "wx", mode: 384 });
55173
+ mkdirSync14(consumedMarkerDir(), { recursive: true, mode: 448 });
55174
+ writeFileSync12(join34(consumedMarkerDir(), `${token}.claimed`), "", { flag: "wx", mode: 384 });
55056
55175
  return true;
55057
55176
  } catch (error62) {
55058
55177
  return error62.code !== "EEXIST";
@@ -55062,7 +55181,7 @@ function pruneConsumedMarkers(now = Date.now()) {
55062
55181
  try {
55063
55182
  const dir = consumedMarkerDir();
55064
55183
  for (const name of readdirSync4(dir)) {
55065
- const path = join33(dir, name);
55184
+ const path = join34(dir, name);
55066
55185
  try {
55067
55186
  if (now - statSync9(path).mtimeMs > APPROVAL_TTL_MS * 4)
55068
55187
  unlinkSync4(path);
@@ -55080,7 +55199,8 @@ function createApprovalToken(rawArgs, opts = {}) {
55080
55199
  argsRedacted: redactSecrets(rawArgs),
55081
55200
  createdAt: Date.now(),
55082
55201
  ...opts.secretsSubstitutable === true ? { secretsSubstitutable: true } : {},
55083
- ...opts.argsPinView !== void 0 ? { argsPinView: opts.argsPinView } : {}
55202
+ ...opts.argsPinView !== void 0 ? { argsPinView: opts.argsPinView } : {},
55203
+ state: "awaiting_user"
55084
55204
  };
55085
55205
  pruneStale(map2);
55086
55206
  pruneConsumedMarkers();
@@ -55103,32 +55223,78 @@ function inspectApprovalToken(token) {
55103
55223
  return { state: "expired" };
55104
55224
  return { state: "valid", entry };
55105
55225
  }
55106
- function consumeApprovalToken(token) {
55226
+ function consumeApprovalToken(token, opts = {}) {
55107
55227
  if (!TOKEN_SHAPE.test(token))
55108
- return null;
55228
+ return { status: "gone" };
55109
55229
  const map2 = readApprovals();
55110
55230
  const entry = map2[token];
55111
55231
  if (!entry || isTombstone(entry))
55112
- return null;
55232
+ return { status: "gone" };
55113
55233
  if (Date.now() - entry.createdAt > APPROVAL_TTL_MS) {
55114
55234
  delete map2[token];
55115
55235
  writeApprovals(map2);
55116
- return null;
55236
+ return { status: "gone" };
55237
+ }
55238
+ if (opts.requireGrant) {
55239
+ const grant = verifyConfirmationGrant(entry, token);
55240
+ if (!grant.ok)
55241
+ return { status: "grant_required", reason: grant.reason };
55117
55242
  }
55118
55243
  if (!claimSingleUse(token))
55119
- return null;
55244
+ return { status: "gone" };
55120
55245
  map2[token] = { consumedAt: Date.now(), createdAt: entry.createdAt };
55121
55246
  writeApprovals(map2);
55122
- return entry;
55247
+ return { status: "consumed", entry };
55248
+ }
55249
+ function grantMac(masterKey, token, entry, confirmedAt) {
55250
+ const shapeDigest = hashArgs({
55251
+ argsHash: entry.argsHash,
55252
+ argsPinView: entry.argsPinView,
55253
+ argsRedacted: entry.argsRedacted,
55254
+ secretsSubstitutable: entry.secretsSubstitutable,
55255
+ createdAt: entry.createdAt
55256
+ });
55257
+ return createHmac3("sha256", masterKey).update(`${GRANT_MAC_DOMAIN}\0${token}\0${shapeDigest}\0${String(confirmedAt)}`).digest("hex");
55123
55258
  }
55124
- var APPROVAL_TTL_MS, TOKEN_SHAPE;
55259
+ function resolveVerificationMasterKey() {
55260
+ try {
55261
+ const master = resolveMasterKey();
55262
+ if (!master)
55263
+ return { failure: "vault master key unavailable" };
55264
+ return { key: master.key };
55265
+ } catch (error62) {
55266
+ const message = error62 instanceof Error ? error62.message : String(error62);
55267
+ return { failure: `vault master key unreadable: ${message}` };
55268
+ }
55269
+ }
55270
+ function verifyConfirmationGrant(entry, token) {
55271
+ if (entry.state !== "user_confirmed") {
55272
+ return { ok: false, reason: "token is awaiting user confirmation" };
55273
+ }
55274
+ const grant = entry.confirmGrant;
55275
+ if (!isConfirmGrant(grant)) {
55276
+ return { ok: false, reason: "confirmation grant is missing or malformed" };
55277
+ }
55278
+ const master = resolveVerificationMasterKey();
55279
+ if ("failure" in master)
55280
+ return { ok: false, reason: master.failure };
55281
+ if (!/^[0-9a-f]{64}$/.test(grant.mac)) {
55282
+ return { ok: false, reason: "confirmation grant mac is malformed" };
55283
+ }
55284
+ const expected = grantMac(master.key, token, entry, grant.confirmedAt);
55285
+ const matches = timingSafeEqual(Buffer.from(expected, "hex"), Buffer.from(grant.mac, "hex"));
55286
+ return matches ? { ok: true } : { ok: false, reason: "confirmation grant does not verify" };
55287
+ }
55288
+ var APPROVAL_TTL_MS, TOKEN_SHAPE, GRANT_MAC_DOMAIN;
55125
55289
  var init_approval_tokens = __esm({
55126
55290
  "plugins/huaweicloud-core/dist.new/lib/approval-tokens.js"() {
55127
55291
  "use strict";
55128
55292
  init_safety_policy();
55293
+ init_custody();
55129
55294
  init_pack_state();
55130
55295
  APPROVAL_TTL_MS = 5 * 6e4;
55131
55296
  TOKEN_SHAPE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
55297
+ GRANT_MAC_DOMAIN = "huaweicloud-approval-grant";
55132
55298
  }
55133
55299
  });
55134
55300
 
@@ -55423,6 +55589,10 @@ var init_hcloud_sg_preflight = __esm({
55423
55589
  });
55424
55590
 
55425
55591
  // plugins/huaweicloud-core/dist.new/hcloud-plan.js
55592
+ function needsUserConfirmation(args, options = {}) {
55593
+ const strict = classifyHcloudArgs(args, { ...options, allowWrites: false });
55594
+ return strict.decision === "deny" && (strict.risk === "write" || strict.risk === "execution");
55595
+ }
55426
55596
  function quoteShellArg(value) {
55427
55597
  const text = String(value);
55428
55598
  if (!text)
@@ -55565,6 +55735,11 @@ function planHcloudCommand(args, options = {}) {
55565
55735
  warnings.push(`${triage.message} ${triage.nextStep}`);
55566
55736
  }
55567
55737
  }
55738
+ const approvalToken = options.mintApprovalToken === false ? void 0 : createApprovalToken(normalizedArgs, {
55739
+ secretsSubstitutable: secretsSubstitutable(normalizedArgs),
55740
+ argsPinView: pinViewArgs(normalizedArgs)
55741
+ });
55742
+ const needsConfirmation = needsUserConfirmation(normalizedArgs, options);
55568
55743
  return {
55569
55744
  executable: "hcloud",
55570
55745
  args: normalizedArgs.map((arg) => redactSecrets(arg)),
@@ -55577,10 +55752,13 @@ function planHcloudCommand(args, options = {}) {
55577
55752
  warnings,
55578
55753
  classification: applyPreflightFindings(effectiveClassification, sgFindings),
55579
55754
  sgFindings,
55580
- approvalToken: createApprovalToken(normalizedArgs, {
55581
- secretsSubstitutable: secretsSubstitutable(normalizedArgs),
55582
- argsPinView: pinViewArgs(normalizedArgs)
55583
- }),
55755
+ ...approvalToken !== void 0 ? { approvalToken } : {},
55756
+ // `command` exists only where a token was minted: a run-path plan stays
55757
+ // silent rather than name a line for a token the run cannot offer.
55758
+ userConfirmation: needsConfirmation ? {
55759
+ needed: true,
55760
+ ...approvalToken !== void 0 ? { command: `npx huaweicloud-devkit approve ${approvalToken}` } : {}
55761
+ } : { needed: false },
55584
55762
  safeToRun: effectiveClassification.decision === "allow"
55585
55763
  };
55586
55764
  }
@@ -55629,14 +55807,14 @@ var init_hcloud_plan = __esm({
55629
55807
 
55630
55808
  // plugins/huaweicloud-core/dist.new/hcloud-run-once.js
55631
55809
  import { spawn as spawn2 } from "node:child_process";
55632
- import { mkdirSync as mkdirSync14, writeFileSync as writeFileSync13 } from "node:fs";
55633
- import { join as join34 } from "node:path";
55810
+ import { mkdirSync as mkdirSync15, writeFileSync as writeFileSync13 } from "node:fs";
55811
+ import { join as join35 } from "node:path";
55634
55812
  function saveLargeOutput(rawStdout) {
55635
55813
  if (rawStdout.length <= LARGE_OUTPUT_THRESHOLD)
55636
55814
  return null;
55637
55815
  try {
55638
- mkdirSync14(OUTPUT_DIR, { recursive: true });
55639
- const filePath = join34(OUTPUT_DIR, `output-${Date.now()}.json`);
55816
+ mkdirSync15(OUTPUT_DIR, { recursive: true });
55817
+ const filePath = join35(OUTPUT_DIR, `output-${Date.now()}.json`);
55640
55818
  writeFileSync13(filePath, rawStdout, { encoding: "utf8" });
55641
55819
  return filePath;
55642
55820
  } catch {
@@ -55656,7 +55834,7 @@ function runHcloudOnce(plan, options) {
55656
55834
  const childOptions = { ...options };
55657
55835
  delete childOptions.metaDir;
55658
55836
  const childEnv = { ...process.env, ...childOptions.env };
55659
- return new Promise((resolve9) => {
55837
+ return new Promise((resolve10) => {
55660
55838
  const proxySettings = getProxySettings();
55661
55839
  const proxyEnv = {};
55662
55840
  if (proxySettings) {
@@ -55715,7 +55893,7 @@ function runHcloudOnce(plan, options) {
55715
55893
  };
55716
55894
  result.plan = redactedPlan;
55717
55895
  }
55718
- resolve9(result);
55896
+ resolve10(result);
55719
55897
  }
55720
55898
  const timer = setTimeout(() => {
55721
55899
  timedOut = true;
@@ -55823,7 +56001,7 @@ var init_hcloud_run_once = __esm({
55823
56001
  DEFAULT_TIMEOUT_MS = 6e4;
55824
56002
  DEFAULT_FORCE_KILL_AFTER_MS = 2e3;
55825
56003
  LARGE_OUTPUT_THRESHOLD = 5e4;
55826
- OUTPUT_DIR = join34("/tmp", "huaweicloud-devkit");
56004
+ OUTPUT_DIR = join35("/tmp", "huaweicloud-devkit");
55827
56005
  }
55828
56006
  });
55829
56007
 
@@ -55832,7 +56010,7 @@ async function runHcloud2(args, options = {}) {
55832
56010
  const inputArgs = Array.isArray(args) ? args.map(String) : [];
55833
56011
  const { args: normalizedArgs } = stripLeadingHcloudBinArgs(inputArgs);
55834
56012
  const plan = {
55835
- ...planHcloudCommand(normalizedArgs, options),
56013
+ ...planHcloudCommand(normalizedArgs, { ...options, mintApprovalToken: false }),
55836
56014
  rawArgs: normalizedArgs
55837
56015
  };
55838
56016
  assertAllowed(plan.classification);
@@ -55904,7 +56082,7 @@ ${result.stderr || ""}`;
55904
56082
  return /\[NETWORK_ERROR\]|connection timed out|ECONNRESET|ETIMEDOUT|temporary failure|TLS handshake timeout/i.test(text);
55905
56083
  }
55906
56084
  function wait(ms) {
55907
- return new Promise((resolve9) => setTimeout(resolve9, ms));
56085
+ return new Promise((resolve10) => setTimeout(resolve10, ms));
55908
56086
  }
55909
56087
  var DEFAULT_MAX_RETRIES;
55910
56088
  var init_hcloud_run = __esm({
@@ -56305,10 +56483,10 @@ var init_pack3 = __esm({
56305
56483
  });
56306
56484
 
56307
56485
  // plugins/huaweicloud-core/dist.new/packs/obs/tools.js
56308
- import { existsSync as existsSync27, writeFileSync as writeFileSync14 } from "node:fs";
56309
- import { homedir as homedir23 } from "node:os";
56310
- import { join as join35 } from "node:path";
56311
- import { createHash as createHash8, createHmac as createHmac3 } from "node:crypto";
56486
+ import { existsSync as existsSync28, writeFileSync as writeFileSync14 } from "node:fs";
56487
+ import { homedir as homedir21 } from "node:os";
56488
+ import { join as join36 } from "node:path";
56489
+ import { createHash as createHash8, createHmac as createHmac4 } from "node:crypto";
56312
56490
  function pickString(...values) {
56313
56491
  for (const value of values) {
56314
56492
  if (typeof value === "string" && value)
@@ -56346,8 +56524,8 @@ async function setupObsConfig(profile) {
56346
56524
  return setupObsConfigFromHcloud(profile);
56347
56525
  }
56348
56526
  async function setupObsConfigFromHcloud(profile) {
56349
- const obsConfigPath2 = join35(homedir23(), ".obsutilconfig");
56350
- if (existsSync27(obsConfigPath2)) {
56527
+ const obsConfigPath2 = join36(homedir21(), ".obsutilconfig");
56528
+ if (existsSync28(obsConfigPath2)) {
56351
56529
  return {
56352
56530
  ok: true,
56353
56531
  existed: true,
@@ -56578,11 +56756,11 @@ x-amz-date:${amzDate}
56578
56756
  credentialScope,
56579
56757
  createHash8("sha256").update(canonicalRequest).digest("hex")
56580
56758
  ].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");
56759
+ const kDate = createHmac4("sha256", "AWS4" + creds.sk).update(dateStamp).digest();
56760
+ const kRegion = createHmac4("sha256", kDate).update(region).digest();
56761
+ const kService = createHmac4("sha256", kRegion).update("s3").digest();
56762
+ const kSigning = createHmac4("sha256", kService).update("aws4_request").digest();
56763
+ const signature = createHmac4("sha256", kSigning).update(stringToSign).digest("hex");
56586
56764
  const authorization = `AWS4-HMAC-SHA256 Credential=${creds.ak}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
56587
56765
  const headers = {
56588
56766
  Host: url2.host,
@@ -57026,7 +57204,7 @@ var init_search_market = __esm({
57026
57204
 
57027
57205
  // plugins/huaweicloud-core/dist.new/icon-library.js
57028
57206
  import { readFileSync as readFileSync28 } from "node:fs";
57029
- import { join as join36, dirname as dirname23 } from "node:path";
57207
+ import { join as join37, dirname as dirname24 } from "node:path";
57030
57208
  import { fileURLToPath as fileURLToPath9 } from "node:url";
57031
57209
  function toIconLogo(value) {
57032
57210
  const raw = asRecord(value);
@@ -57213,8 +57391,8 @@ var init_icon_library = __esm({
57213
57391
  "use strict";
57214
57392
  init_proxy_agent();
57215
57393
  init_as_record();
57216
- __dirname7 = dirname23(fileURLToPath9(import.meta.url));
57217
- SNAPSHOT_PATH = join36(__dirname7, "data", "icons-manifest.v1.json");
57394
+ __dirname7 = dirname24(fileURLToPath9(import.meta.url));
57395
+ SNAPSHOT_PATH = join37(__dirname7, "data", "icons-manifest.v1.json");
57218
57396
  MANIFEST_URL = "https://open.huaweicloud.com/openplatform/icons/manifest.v1.json";
57219
57397
  ICONS_PAGE_URL = "https://open.huaweicloud.com/openplatform/icons.html";
57220
57398
  HTTP_TIMEOUT_MS2 = 1e4;
@@ -57224,11 +57402,11 @@ var init_icon_library = __esm({
57224
57402
  });
57225
57403
 
57226
57404
  // plugins/huaweicloud-core/dist.new/detect-framework-pkg.js
57227
- import { existsSync as existsSync28, readFileSync as readFileSync29 } from "node:fs";
57228
- import { join as join37 } from "node:path";
57405
+ import { existsSync as existsSync29, readFileSync as readFileSync29 } from "node:fs";
57406
+ import { join as join38 } from "node:path";
57229
57407
  function readPkg(projectPath) {
57230
- const pkgPath = join37(projectPath, "package.json");
57231
- if (!existsSync28(pkgPath))
57408
+ const pkgPath = join38(projectPath, "package.json");
57409
+ if (!existsSync29(pkgPath))
57232
57410
  return null;
57233
57411
  try {
57234
57412
  const parsed = JSON.parse(readFileSync29(pkgPath, "utf8"));
@@ -57240,13 +57418,13 @@ function readPkg(projectPath) {
57240
57418
  }
57241
57419
  }
57242
57420
  function detectPackageManager(projectPath, pkg) {
57243
- if (existsSync28(join37(projectPath, "pnpm-lock.yaml")))
57421
+ if (existsSync29(join38(projectPath, "pnpm-lock.yaml")))
57244
57422
  return "pnpm";
57245
- if (existsSync28(join37(projectPath, "yarn.lock")))
57423
+ if (existsSync29(join38(projectPath, "yarn.lock")))
57246
57424
  return "yarn";
57247
- if (existsSync28(join37(projectPath, "package-lock.json")))
57425
+ if (existsSync29(join38(projectPath, "package-lock.json")))
57248
57426
  return "npm";
57249
- if (existsSync28(join37(projectPath, "bun.lockb")))
57427
+ if (existsSync29(join38(projectPath, "bun.lockb")))
57250
57428
  return "bun";
57251
57429
  const declaredValue = pkg?.packageManager;
57252
57430
  const declared = typeof declaredValue === "string" ? declaredValue.split("@")[0] : "";
@@ -57262,8 +57440,8 @@ function collectDeps(pkg) {
57262
57440
  function readVitepressOutDir(projectPath) {
57263
57441
  const configFiles = ["config.mts", "config.ts", "config.mjs", "config.js"];
57264
57442
  for (const cf of configFiles) {
57265
- const configPath = join37(projectPath, ".vitepress", cf);
57266
- if (!existsSync28(configPath))
57443
+ const configPath = join38(projectPath, ".vitepress", cf);
57444
+ if (!existsSync29(configPath))
57267
57445
  continue;
57268
57446
  try {
57269
57447
  const content = readFileSync29(configPath, "utf8");
@@ -57277,8 +57455,8 @@ function readVitepressOutDir(projectPath) {
57277
57455
  }
57278
57456
  function resolveAngularOutput(projectPath, pkg) {
57279
57457
  try {
57280
- const angularJson = join37(projectPath, "angular.json");
57281
- if (existsSync28(angularJson)) {
57458
+ const angularJson = join38(projectPath, "angular.json");
57459
+ if (existsSync29(angularJson)) {
57282
57460
  const config2 = asRecord(JSON.parse(readFileSync29(angularJson, "utf8")));
57283
57461
  const projects = asRecord(config2.projects);
57284
57462
  const defaultProjectValue = config2.defaultProject;
@@ -57458,13 +57636,13 @@ var init_detect_framework_table = __esm({
57458
57636
  });
57459
57637
 
57460
57638
  // plugins/huaweicloud-core/dist.new/detect-framework-match.js
57461
- import { existsSync as existsSync29 } from "node:fs";
57462
- import { join as join38 } from "node:path";
57639
+ import { existsSync as existsSync30 } from "node:fs";
57640
+ import { join as join39 } from "node:path";
57463
57641
  function matchFrameworkSpec(projectPath, pkg, deps) {
57464
- if (existsSync29(join38(projectPath, "next.config.js")) || existsSync29(join38(projectPath, "next.config.mjs")) || existsSync29(join38(projectPath, "next.config.ts")) || existsSync29(join38(projectPath, "next.config.cjs"))) {
57642
+ if (existsSync30(join39(projectPath, "next.config.js")) || existsSync30(join39(projectPath, "next.config.mjs")) || existsSync30(join39(projectPath, "next.config.ts")) || existsSync30(join39(projectPath, "next.config.cjs"))) {
57465
57643
  return FRAMEWORKS.nextjs;
57466
57644
  }
57467
- if (existsSync29(join38(projectPath, "nuxt.config.js")) || existsSync29(join38(projectPath, "nuxt.config.mjs")) || existsSync29(join38(projectPath, "nuxt.config.ts")) || existsSync29(join38(projectPath, "nuxt.config.cjs")) || existsSync29(join38(projectPath, "nuxt.config.mts"))) {
57645
+ if (existsSync30(join39(projectPath, "nuxt.config.js")) || existsSync30(join39(projectPath, "nuxt.config.mjs")) || existsSync30(join39(projectPath, "nuxt.config.ts")) || existsSync30(join39(projectPath, "nuxt.config.cjs")) || existsSync30(join39(projectPath, "nuxt.config.mts"))) {
57468
57646
  return FRAMEWORKS.nuxt;
57469
57647
  }
57470
57648
  if ("@tarojs/taro" in deps) {
@@ -57473,35 +57651,35 @@ function matchFrameworkSpec(projectPath, pkg, deps) {
57473
57651
  if ("@dcloudio/uni-app" in deps || "uni-app" in deps) {
57474
57652
  return FRAMEWORKS.uniapp;
57475
57653
  }
57476
- if (existsSync29(join38(projectPath, ".vitepress"))) {
57654
+ if (existsSync30(join39(projectPath, ".vitepress"))) {
57477
57655
  const outDir = readVitepressOutDir(projectPath);
57478
57656
  return outDir ? { ...FRAMEWORKS.vitepress, outputDir: outDir } : FRAMEWORKS.vitepress;
57479
57657
  }
57480
- if (existsSync29(join38(projectPath, "docusaurus.config.js")) || existsSync29(join38(projectPath, "docusaurus.config.ts")) || existsSync29(join38(projectPath, "docusaurus.config.mjs")) || existsSync29(join38(projectPath, "docusaurus.config.cjs"))) {
57658
+ if (existsSync30(join39(projectPath, "docusaurus.config.js")) || existsSync30(join39(projectPath, "docusaurus.config.ts")) || existsSync30(join39(projectPath, "docusaurus.config.mjs")) || existsSync30(join39(projectPath, "docusaurus.config.cjs"))) {
57481
57659
  return FRAMEWORKS.docusaurus;
57482
57660
  }
57483
- if (existsSync29(join38(projectPath, "hugo.toml")) || existsSync29(join38(projectPath, "config.toml"))) {
57661
+ if (existsSync30(join39(projectPath, "hugo.toml")) || existsSync30(join39(projectPath, "config.toml"))) {
57484
57662
  return FRAMEWORKS.hugo;
57485
57663
  }
57486
- if (existsSync29(join38(projectPath, "_config.yml"))) {
57664
+ if (existsSync30(join39(projectPath, "_config.yml"))) {
57487
57665
  return FRAMEWORKS.hexo;
57488
57666
  }
57489
- if (existsSync29(join38(projectPath, "angular.json"))) {
57667
+ if (existsSync30(join39(projectPath, "angular.json"))) {
57490
57668
  const outputDir = resolveAngularOutput(projectPath, pkg);
57491
57669
  return { ...FRAMEWORKS.angular, outputDir };
57492
57670
  }
57493
- if (existsSync29(join38(projectPath, "vite.config.js")) || existsSync29(join38(projectPath, "vite.config.mjs")) || existsSync29(join38(projectPath, "vite.config.ts")) || existsSync29(join38(projectPath, "vite.config.cjs")) || existsSync29(join38(projectPath, "vite.config.mts"))) {
57671
+ if (existsSync30(join39(projectPath, "vite.config.js")) || existsSync30(join39(projectPath, "vite.config.mjs")) || existsSync30(join39(projectPath, "vite.config.ts")) || existsSync30(join39(projectPath, "vite.config.cjs")) || existsSync30(join39(projectPath, "vite.config.mts"))) {
57494
57672
  return FRAMEWORKS.vite;
57495
57673
  }
57496
57674
  if ("@vue/cli-service" in deps) {
57497
57675
  return FRAMEWORKS.vueCli;
57498
57676
  }
57499
57677
  if ("react-scripts" in deps || "react" in deps || "@angular/core" in deps || "vue" in deps || "svelte" in deps || "solid-js" in deps) {
57500
- if (existsSync29(join38(projectPath, "public", "index.html")) || existsSync29(join38(projectPath, "index.html"))) {
57678
+ if (existsSync30(join39(projectPath, "public", "index.html")) || existsSync30(join39(projectPath, "index.html"))) {
57501
57679
  return FRAMEWORKS.cra;
57502
57680
  }
57503
57681
  }
57504
- if (existsSync29(join38(projectPath, "index.html")) || existsSync29(join38(projectPath, "public", "index.html")) || existsSync29(join38(projectPath, "src", "index.html"))) {
57682
+ if (existsSync30(join39(projectPath, "index.html")) || existsSync30(join39(projectPath, "public", "index.html")) || existsSync30(join39(projectPath, "src", "index.html"))) {
57505
57683
  return FRAMEWORKS.static;
57506
57684
  }
57507
57685
  if (pkg) {
@@ -57518,7 +57696,7 @@ function matchFrameworkSpec(projectPath, pkg, deps) {
57518
57696
  "src/index.jsx",
57519
57697
  "src/index.tsx"
57520
57698
  ];
57521
- const hasEntry = entryPoints.some((p) => existsSync29(join38(projectPath, p)));
57699
+ const hasEntry = entryPoints.some((p) => existsSync30(join39(projectPath, p)));
57522
57700
  if (hasEntry) {
57523
57701
  if ("vue" in deps || "@vue/cli-service" in deps) {
57524
57702
  return FRAMEWORKS.vueCli;
@@ -57542,20 +57720,20 @@ var init_detect_framework_match = __esm({
57542
57720
  });
57543
57721
 
57544
57722
  // plugins/huaweicloud-core/dist.new/detect-framework-scan.js
57545
- import { existsSync as existsSync30, readdirSync as readdirSync5 } from "node:fs";
57546
- import { join as join39 } from "node:path";
57723
+ import { existsSync as existsSync31, readdirSync as readdirSync5 } from "node:fs";
57724
+ import { join as join40 } from "node:path";
57547
57725
  function scanSubApps(projectPath) {
57548
57726
  const apps = [];
57549
57727
  for (const dir of ["apps", "packages"]) {
57550
- const dirPath = join39(projectPath, dir);
57551
- if (!existsSync30(dirPath))
57728
+ const dirPath = join40(projectPath, dir);
57729
+ if (!existsSync31(dirPath))
57552
57730
  continue;
57553
57731
  try {
57554
57732
  const entries = readdirSync5(dirPath, { withFileTypes: true });
57555
57733
  for (const entry of entries) {
57556
57734
  if (!entry.isDirectory())
57557
57735
  continue;
57558
- const subPath = join39(dirPath, entry.name);
57736
+ const subPath = join40(dirPath, entry.name);
57559
57737
  const subPkg = readPkg(subPath);
57560
57738
  if (!subPkg)
57561
57739
  continue;
@@ -57603,12 +57781,12 @@ function detectFramework(projectPath) {
57603
57781
  const pkg = readPkg(projectPath);
57604
57782
  const deps = collectDeps(pkg);
57605
57783
  const pm = detectPackageManager(projectPath, pkg);
57606
- if (existsSync30(join39(projectPath, "pnpm-workspace.yaml")) || existsSync30(join39(projectPath, "turbo.json")) || existsSync30(join39(projectPath, "nx.json")) || existsSync30(join39(projectPath, "lerna.json"))) {
57784
+ if (existsSync31(join40(projectPath, "pnpm-workspace.yaml")) || existsSync31(join40(projectPath, "turbo.json")) || existsSync31(join40(projectPath, "nx.json")) || existsSync31(join40(projectPath, "lerna.json"))) {
57607
57785
  const monorepoSubApps = scanSubApps(projectPath);
57608
57786
  return {
57609
57787
  type: "monorepo",
57610
57788
  framework: "Monorepo",
57611
- monorepoTool: existsSync30(join39(projectPath, "turbo.json")) ? "Turborepo" : existsSync30(join39(projectPath, "nx.json")) ? "Nx" : existsSync30(join39(projectPath, "lerna.json")) ? "Lerna" : "pnpm Workspace",
57789
+ monorepoTool: existsSync31(join40(projectPath, "turbo.json")) ? "Turborepo" : existsSync31(join40(projectPath, "nx.json")) ? "Nx" : existsSync31(join40(projectPath, "lerna.json")) ? "Lerna" : "pnpm Workspace",
57612
57790
  subApps: monorepoSubApps,
57613
57791
  packageManager: pm,
57614
57792
  rootDir: projectPath
@@ -57842,13 +58020,22 @@ async function runApprovedCommand(args = {}) {
57842
58020
  if (placeholderArg) {
57843
58021
  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
58022
  }
57845
- const stored = consumeApprovalToken(token);
57846
- if (!stored) {
58023
+ const strictPlan = planHcloudCommand(effectiveArgs, { allowWrites: false, mintApprovalToken: false });
58024
+ const consumed = consumeApprovalToken(token, { requireGrant: strictPlan.userConfirmation.needed });
58025
+ if (consumed.status === "grant_required") {
58026
+ return {
58027
+ status: "rejected",
58028
+ code: "USER_CONFIRMATION_REQUIRED",
58029
+ nextStep: 'Ask the user to run "npx huaweicloud-devkit approve <this approvalToken>" in their own terminal, then retry this exact call.'
58030
+ };
58031
+ }
58032
+ if (consumed.status === "gone") {
57847
58033
  const recheck = inspectApprovalToken(token);
57848
58034
  if (recheck.state === "expired")
57849
58035
  return { status: "rejected", code: "CONFIRM_TOKEN_EXPIRED" };
57850
58036
  return { status: "ok", outcome: "already_processed" };
57851
58037
  }
58038
+ const stored = consumed.entry;
57852
58039
  if (hashArgs(effectiveArgs) !== stored.argsHash) {
57853
58040
  const storedView = JSON.stringify(stored.argsPinView ?? stored.argsRedacted);
57854
58041
  const providedView = JSON.stringify(pinViewArgs(effectiveArgs));
@@ -57859,7 +58046,6 @@ async function runApprovedCommand(args = {}) {
57859
58046
  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
58047
  }
57861
58048
  }
57862
- const strictPlan = planHcloudCommand(effectiveArgs, { allowWrites: false });
57863
58049
  const result = await runHcloud2(effectiveArgs, {
57864
58050
  allowWrites: true,
57865
58051
  timeoutMs: args.timeoutMs,
@@ -58036,7 +58222,7 @@ var init_tools7 = __esm({
58036
58222
  },
58037
58223
  {
58038
58224
  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.",
58225
+ 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
58226
  schema: planCliCommandSchema,
58041
58227
  handler: handlePlanCliCommand
58042
58228
  },
@@ -58054,7 +58240,7 @@ var init_tools7 = __esm({
58054
58240
  },
58055
58241
  {
58056
58242
  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.",
58243
+ 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
58244
  schema: runApprovedCommandSchema,
58059
58245
  handler: handleRunApprovedCommand
58060
58246
  },
@@ -58131,9 +58317,9 @@ var init_pack7 = __esm({
58131
58317
 
58132
58318
  // plugins/huaweicloud-core/dist.new/packs/huaweicloud-open-mcp/sidecar.js
58133
58319
  import { spawn as spawn3 } from "node:child_process";
58134
- import { mkdtempSync, rmSync as rmSync8 } from "node:fs";
58320
+ import { mkdtempSync, rmSync as rmSync9 } from "node:fs";
58135
58321
  import { tmpdir as tmpdir6 } from "node:os";
58136
- import { isAbsolute as isAbsolute2, join as join40 } from "node:path";
58322
+ import { isAbsolute as isAbsolute3, join as join41 } from "node:path";
58137
58323
  function resolveGatewayCommand(env = process.env) {
58138
58324
  const resolved = resolveDependencyCommand(DEPENDENCIES["open-mcp-gateway"].resolution, env);
58139
58325
  if (!resolved)
@@ -58143,7 +58329,7 @@ function resolveGatewayCommand(env = process.env) {
58143
58329
  function resolveGatewaySpawnArgs(env = process.env) {
58144
58330
  for (const key of ["HUAWEICLOUD_MCP_POLICY_FILE", "HUAWEICLOUD_MCP_AUDIT_FILE"]) {
58145
58331
  const value = (env[key] ?? "").trim();
58146
- if (value !== "" && !isAbsolute2(value)) {
58332
+ if (value !== "" && !isAbsolute3(value)) {
58147
58333
  throw new Error(`${key} must be an absolute path (got "${value}"): the gateway child, this server, and the protected-tree guard each resolve relative paths against different working directories.`);
58148
58334
  }
58149
58335
  }
@@ -58162,18 +58348,18 @@ function resolveGatewaySpawnArgs(env = process.env) {
58162
58348
  let provision = null;
58163
58349
  if (policyEnv === "") {
58164
58350
  const dir = packStateDir("huaweicloud-open-mcp", env);
58165
- provision = { dir, policyPath: join40(dir, POLICY_FILE) };
58351
+ provision = { dir, policyPath: join41(dir, POLICY_FILE) };
58166
58352
  args.push("--policy", provision.policyPath);
58167
58353
  }
58168
58354
  if (!(env.HUAWEICLOUD_MCP_LOG_FILE ?? "").trim()) {
58169
- args.push("--log-file", join40(tmpdir6(), "huaweicloud-open-mcp.log"));
58355
+ args.push("--log-file", join41(tmpdir6(), "huaweicloud-open-mcp.log"));
58170
58356
  }
58171
58357
  return { args, provision };
58172
58358
  }
58173
58359
  function removeScratchCwd(dir) {
58174
58360
  scratchCwds.delete(dir);
58175
58361
  try {
58176
- rmSync8(dir, { recursive: true, force: true });
58362
+ rmSync9(dir, { recursive: true, force: true });
58177
58363
  } catch {
58178
58364
  }
58179
58365
  }
@@ -58186,7 +58372,7 @@ async function spawnSidecar() {
58186
58372
  if (plan.provision) {
58187
58373
  ensurePackState("huaweicloud-open-mcp", [POLICY_FILE]);
58188
58374
  }
58189
- const scratchCwd = mkdtempSync(join40(tmpdir6(), "openmcp-gw-"));
58375
+ const scratchCwd = mkdtempSync(join41(tmpdir6(), "openmcp-gw-"));
58190
58376
  scratchCwds.add(scratchCwd);
58191
58377
  if (!scratchExitSweepInstalled) {
58192
58378
  scratchExitSweepInstalled = true;
@@ -58390,12 +58576,12 @@ var init_sidecar = __esm({
58390
58576
  return Promise.reject(new Error("open-mcp gateway sidecar is dead; the next call respawns it"));
58391
58577
  }
58392
58578
  const id = this.nextId++;
58393
- return new Promise((resolve9, reject) => {
58579
+ return new Promise((resolve10, reject) => {
58394
58580
  const timer = setTimeout(() => {
58395
58581
  this.pending.delete(id);
58396
58582
  reject(new Error(`open-mcp gateway ${method} timed out after ${timeoutMs}ms`));
58397
58583
  }, timeoutMs);
58398
- this.pending.set(id, { resolve: resolve9, reject, timer });
58584
+ this.pending.set(id, { resolve: resolve10, reject, timer });
58399
58585
  this.child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}
58400
58586
  `);
58401
58587
  });
@@ -58424,11 +58610,11 @@ var init_sidecar = __esm({
58424
58610
  if (!this.alive)
58425
58611
  return;
58426
58612
  this.kill();
58427
- await new Promise((resolve9) => {
58428
- const bound = setTimeout(resolve9, 4500);
58613
+ await new Promise((resolve10) => {
58614
+ const bound = setTimeout(resolve10, 4500);
58429
58615
  this.child.once("exit", () => {
58430
58616
  clearTimeout(bound);
58431
- resolve9();
58617
+ resolve10();
58432
58618
  });
58433
58619
  });
58434
58620
  }
@@ -58454,18 +58640,18 @@ var init_sidecar = __esm({
58454
58640
  });
58455
58641
 
58456
58642
  // plugins/huaweicloud-core/dist.new/packs/huaweicloud-open-mcp/approval.js
58457
- import { join as join41 } from "node:path";
58643
+ import { join as join42 } from "node:path";
58458
58644
  function resolveApprovalMode(env = process.env) {
58459
58645
  const value = (env.HUAWEICLOUD_OPENMCP_APPROVAL ?? "").trim();
58460
58646
  if (value === "")
58461
58647
  return;
58462
58648
  const operatorPath = (env.HUAWEICLOUD_MCP_POLICY_FILE ?? "").trim();
58463
- const policyFile = operatorPath !== "" ? operatorPath : join41(packStateDir("huaweicloud-open-mcp", env), POLICY_FILE);
58649
+ const policyFile = operatorPath !== "" ? operatorPath : join42(packStateDir("huaweicloud-open-mcp", env), POLICY_FILE);
58464
58650
  throw new Error(`HUAWEICLOUD_OPENMCP_APPROVAL is retired (was set to "${value}"): gateway tool approval is delegated to the gateway's own policy engine. Manage consent in the operator policy file (${policyFile}); it hot-reloads, so edits take effect without a restart. See docs/safety-model.md for the delegation contract and the floors this face still enforces.`);
58465
58651
  }
58466
58652
  function permanentGrantReason() {
58467
58653
  const operatorPath = (process.env.HUAWEICLOUD_MCP_POLICY_FILE ?? "").trim();
58468
- const path = operatorPath !== "" ? operatorPath : join41(packStateDir("huaweicloud-open-mcp"), POLICY_FILE);
58654
+ const path = operatorPath !== "" ? operatorPath : join42(packStateDir("huaweicloud-open-mcp"), POLICY_FILE);
58469
58655
  return `permanent-scope grants are an operator gesture, not an agent action: edit the policy file directly (${path}); it hot-reloads, so the change takes effect without a restart`;
58470
58656
  }
58471
58657
  function classify(tool, toolArgs) {
@@ -58989,13 +59175,13 @@ var init_registry = __esm({
58989
59175
  });
58990
59176
 
58991
59177
  // plugins/huaweicloud-core/dist.new/lib/skill-tree.js
58992
- import { existsSync as existsSync31, readdirSync as readdirSync6, readFileSync as readFileSync31 } from "node:fs";
58993
- import { join as join42 } from "node:path";
59178
+ import { existsSync as existsSync32, readdirSync as readdirSync6, readFileSync as readFileSync31 } from "node:fs";
59179
+ import { join as join43 } from "node:path";
58994
59180
  function listSkillDirs(root) {
58995
- if (!existsSync31(root))
59181
+ if (!existsSync32(root))
58996
59182
  return [];
58997
59183
  try {
58998
- return readdirSync6(root, { withFileTypes: true }).filter((d) => (d.isDirectory() || d.isSymbolicLink()) && existsSync31(join42(root, d.name, "SKILL.md"))).map((d) => d.name);
59184
+ return readdirSync6(root, { withFileTypes: true }).filter((d) => (d.isDirectory() || d.isSymbolicLink()) && existsSync32(join43(root, d.name, "SKILL.md"))).map((d) => d.name);
58999
59185
  } catch {
59000
59186
  return [];
59001
59187
  }
@@ -59006,8 +59192,74 @@ var init_skill_tree = __esm({
59006
59192
  }
59007
59193
  });
59008
59194
 
59195
+ // plugins/huaweicloud-core/dist.new/lib/param-warnings.js
59196
+ function levenshtein(a, b) {
59197
+ const rows = a.length + 1;
59198
+ const cols = b.length + 1;
59199
+ const previous = new Array(cols);
59200
+ const current = new Array(cols);
59201
+ for (let j = 0; j < cols; j++)
59202
+ previous[j] = j;
59203
+ for (let i = 1; i < rows; i++) {
59204
+ current[0] = i;
59205
+ for (let j = 1; j < cols; j++) {
59206
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
59207
+ current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + cost);
59208
+ }
59209
+ for (let j = 0; j < cols; j++)
59210
+ previous[j] = current[j];
59211
+ }
59212
+ return previous[cols - 1];
59213
+ }
59214
+ function suggestParam(key, knownKeys) {
59215
+ let best = null;
59216
+ let bestDistance = SUGGESTION_DISTANCE + 1;
59217
+ const lowerKey = key.toLowerCase();
59218
+ for (const candidate of knownKeys) {
59219
+ if (candidate === key)
59220
+ continue;
59221
+ const distance = levenshtein(lowerKey, candidate.toLowerCase());
59222
+ if (distance > SUGGESTION_DISTANCE)
59223
+ continue;
59224
+ if (distance < bestDistance || distance === bestDistance && best !== null && candidate < best) {
59225
+ best = candidate;
59226
+ bestDistance = distance;
59227
+ }
59228
+ }
59229
+ return best;
59230
+ }
59231
+ function unknownParamWarnings(args, knownKeys) {
59232
+ const unknown2 = Object.keys(args).filter((key) => !knownKeys.has(key)).sort((a, b) => a.localeCompare(b));
59233
+ return unknown2.slice(0, MAX_WARNINGS).map((key) => {
59234
+ const suggestion = suggestParam(key, knownKeys);
59235
+ return suggestion ? `Unknown parameter "${key}" was ignored. Did you mean "${suggestion}"?` : `Unknown parameter "${key}" was ignored (no matching parameter).`;
59236
+ });
59237
+ }
59238
+ function attachParamWarnings(result, warnings) {
59239
+ if (warnings.length === 0)
59240
+ return result;
59241
+ if (result === null || typeof result !== "object" || Array.isArray(result))
59242
+ return result;
59243
+ const record2 = result;
59244
+ if (Array.isArray(record2.warnings)) {
59245
+ return { ...record2, warnings: [...record2.warnings, ...warnings] };
59246
+ }
59247
+ if (record2.warnings === void 0) {
59248
+ return { ...record2, warnings };
59249
+ }
59250
+ return { ...record2, paramWarnings: warnings };
59251
+ }
59252
+ var MAX_WARNINGS, SUGGESTION_DISTANCE;
59253
+ var init_param_warnings = __esm({
59254
+ "plugins/huaweicloud-core/dist.new/lib/param-warnings.js"() {
59255
+ "use strict";
59256
+ MAX_WARNINGS = 5;
59257
+ SUGGESTION_DISTANCE = 2;
59258
+ }
59259
+ });
59260
+
59009
59261
  // plugins/huaweicloud-core/dist.new/lib/call-trace.js
59010
- import { appendFileSync as appendFileSync4, existsSync as existsSync32, writeFileSync as writeFileSync15 } from "node:fs";
59262
+ import { appendFileSync as appendFileSync4, existsSync as existsSync33, writeFileSync as writeFileSync15 } from "node:fs";
59011
59263
  function redactSupplemental(value) {
59012
59264
  if (Array.isArray(value))
59013
59265
  return value.map((item) => redactSupplemental(item));
@@ -59032,7 +59284,7 @@ function appendRecord(record2) {
59032
59284
  try {
59033
59285
  const line = `${JSON.stringify(record2)}
59034
59286
  `;
59035
- if (existsSync32(path)) {
59287
+ if (existsSync33(path)) {
59036
59288
  appendFileSync4(path, line, "utf8");
59037
59289
  } else {
59038
59290
  writeFileSync15(path, line, { mode: 384, encoding: "utf8" });
@@ -59364,88 +59616,6 @@ var init_tool_definitions = __esm({
59364
59616
  }
59365
59617
  });
59366
59618
 
59367
- // plugins/huaweicloud-core/dist.new/vendor-gate.js
59368
- function vendorChallengeEnabled() {
59369
- return process.env.HUAWEICLOUD_VENDOR_CHALLENGE !== "off";
59370
- }
59371
- function enforceVendorGate(args, opts) {
59372
- const quote = args.vendorConfirmed;
59373
- if (typeof quote !== "string" || quote.trim().length === 0) {
59374
- throw new Error(VENDOR_GATE_MESSAGE);
59375
- }
59376
- const challengeKey = opts.sessionId || "default";
59377
- if (vendorChallengeEnabled() && !vendorChallengeConsumed.get(challengeKey)) {
59378
- vendorChallengeConsumed.set(challengeKey, true);
59379
- throw new Error(VENDOR_CHALLENGE_MESSAGE);
59380
- }
59381
- }
59382
- var VENDOR_GATED_TOOLS, VENDOR_GATE_MESSAGE, VENDOR_CHALLENGE_MESSAGE, vendorChallengeConsumed;
59383
- var init_vendor_gate = __esm({
59384
- "plugins/huaweicloud-core/dist.new/vendor-gate.js"() {
59385
- "use strict";
59386
- VENDOR_GATED_TOOLS = /* @__PURE__ */ new Set([
59387
- "huaweicloud_auth_status",
59388
- "huaweicloud_auth_init",
59389
- "huaweicloud_auth_switch",
59390
- "huaweicloud_check_cli",
59391
- "huaweicloud_show_profile_redacted",
59392
- "huaweicloud_list_operations",
59393
- "huaweicloud_list_regions",
59394
- "huaweicloud_run_readonly_command",
59395
- "huaweicloud_plan_cli_command",
59396
- "huaweicloud_run_approved_command",
59397
- "huaweicloud_service_catalog",
59398
- "huaweicloud_sandbox_connect",
59399
- "huaweicloud_voucher_claim",
59400
- "huaweicloud_competition_voucher_claim"
59401
- ]);
59402
- VENDOR_GATE_MESSAGE = "Vendor gate: this tool operates on Huawei Cloud. Pass vendorConfirmed with the user's establishing words \u2014 the quote where they named Huawei Cloud, an hcloud artifact, a myhuaweicloud endpoint, a Huawei region ID, or an earlier confirmation. The devkit being installed is NOT confirmation. If you cannot quote the user, ask which cloud they mean, then retry once established.";
59403
- VENDOR_CHALLENGE_MESSAGE = "Vendor challenge: first Huawei Cloud tool call this session \u2014 is the vendorConfirmed quote the user's actual words, or invented? An invented quote is a fabricated user statement. If invented, or the vendor was only assumed, ask which cloud they mean now. Retry the same call to proceed; this challenge appears once per session.";
59404
- vendorChallengeConsumed = /* @__PURE__ */ new Map();
59405
- }
59406
- });
59407
-
59408
- // plugins/huaweicloud-core/dist.new/packs/enable.js
59409
- function setRuntimePacksOverride(raw) {
59410
- const parsed = parseDevkitPacks(raw);
59411
- if (!parsed.raw) {
59412
- throw new Error("Runtime pack override cannot be blank. Clear it with reset instead.");
59413
- }
59414
- if (parsed.unknown.length > 0) {
59415
- throw new Error(`Runtime pack override contains unknown pack id(s): ${parsed.unknown.join(", ")}. Valid pack ids: ${VALID_IDS.join(", ")}.`);
59416
- }
59417
- runtimeOverride = parsed;
59418
- return parsed;
59419
- }
59420
- function clearRuntimePacksOverride() {
59421
- runtimeOverride = null;
59422
- }
59423
- function runtimePacksOverride() {
59424
- return runtimeOverride;
59425
- }
59426
- function resolveEnabledPacks(env = process.env) {
59427
- if (runtimeOverride)
59428
- return runtimeOverride.enabled;
59429
- const raw = (env.DEVKIT_PACKS ?? "").trim();
59430
- if (!raw)
59431
- return new Set(PACK_IDS);
59432
- const { unknown: unknown2, enabled } = parseDevkitPacks(raw);
59433
- if (unknown2.length > 0) {
59434
- throw new Error(`DEVKIT_PACKS contains unknown pack id(s): ${unknown2.join(", ")}. Valid pack ids: ${VALID_IDS.join(", ")}.`);
59435
- }
59436
- return enabled;
59437
- }
59438
- var VALID_IDS, runtimeOverride;
59439
- var init_enable = __esm({
59440
- "plugins/huaweicloud-core/dist.new/packs/enable.js"() {
59441
- "use strict";
59442
- init_pack_types();
59443
- init_dependency_model();
59444
- VALID_IDS = PACK_IDS;
59445
- runtimeOverride = null;
59446
- }
59447
- });
59448
-
59449
59619
  // plugins/huaweicloud-core/dist.new/tool-schemas.js
59450
59620
  function getToolSchema(name) {
59451
59621
  return TOOL_SCHEMAS[name];
@@ -59453,6 +59623,16 @@ function getToolSchema(name) {
59453
59623
  function toolSchemaEntries() {
59454
59624
  return Object.entries(TOOL_SCHEMAS);
59455
59625
  }
59626
+ function toolArgKeys(name) {
59627
+ const cached2 = argKeyCache.get(name);
59628
+ if (cached2)
59629
+ return cached2;
59630
+ const def = TOOL_SCHEMAS[name]._zod?.def;
59631
+ const keys = new Set(Object.keys(def?.shape ?? {}));
59632
+ keys.add("vendorConfirmed");
59633
+ argKeyCache.set(name, keys);
59634
+ return keys;
59635
+ }
59456
59636
  function assertConstructedSchemas() {
59457
59637
  for (const [name, schema] of toolSchemaEntries()) {
59458
59638
  const def = schema._zod?.def;
@@ -59461,7 +59641,7 @@ function assertConstructedSchemas() {
59461
59641
  }
59462
59642
  }
59463
59643
  }
59464
- var SCHEMA_DRIFT_IGNORED_KEYS, artifactsItem, TOOL_SCHEMAS;
59644
+ var SCHEMA_DRIFT_IGNORED_KEYS, artifactsItem, TOOL_SCHEMAS, argKeyCache;
59465
59645
  var init_tool_schemas = __esm({
59466
59646
  "plugins/huaweicloud-core/dist.new/tool-schemas.js"() {
59467
59647
  "use strict";
@@ -59570,6 +59750,89 @@ var init_tool_schemas = __esm({
59570
59750
  reset: external_exports.boolean().optional().describe("Drop the session override and return to the operator DEVKIT_PACKS posture.")
59571
59751
  })
59572
59752
  };
59753
+ argKeyCache = /* @__PURE__ */ new Map();
59754
+ }
59755
+ });
59756
+
59757
+ // plugins/huaweicloud-core/dist.new/vendor-gate.js
59758
+ function vendorChallengeEnabled() {
59759
+ return process.env.HUAWEICLOUD_VENDOR_CHALLENGE !== "off";
59760
+ }
59761
+ function enforceVendorGate(args, opts) {
59762
+ const quote = args.vendorConfirmed;
59763
+ if (typeof quote !== "string" || quote.trim().length === 0) {
59764
+ throw new Error(VENDOR_GATE_MESSAGE);
59765
+ }
59766
+ const challengeKey = opts.sessionId || "default";
59767
+ if (vendorChallengeEnabled() && !vendorChallengeConsumed.get(challengeKey)) {
59768
+ vendorChallengeConsumed.set(challengeKey, true);
59769
+ throw new Error(VENDOR_CHALLENGE_MESSAGE);
59770
+ }
59771
+ }
59772
+ var VENDOR_GATED_TOOLS, VENDOR_GATE_MESSAGE, VENDOR_CHALLENGE_MESSAGE, vendorChallengeConsumed;
59773
+ var init_vendor_gate = __esm({
59774
+ "plugins/huaweicloud-core/dist.new/vendor-gate.js"() {
59775
+ "use strict";
59776
+ VENDOR_GATED_TOOLS = /* @__PURE__ */ new Set([
59777
+ "huaweicloud_auth_status",
59778
+ "huaweicloud_auth_init",
59779
+ "huaweicloud_auth_switch",
59780
+ "huaweicloud_check_cli",
59781
+ "huaweicloud_show_profile_redacted",
59782
+ "huaweicloud_list_operations",
59783
+ "huaweicloud_list_regions",
59784
+ "huaweicloud_run_readonly_command",
59785
+ "huaweicloud_plan_cli_command",
59786
+ "huaweicloud_run_approved_command",
59787
+ "huaweicloud_service_catalog",
59788
+ "huaweicloud_sandbox_connect",
59789
+ "huaweicloud_voucher_claim",
59790
+ "huaweicloud_competition_voucher_claim"
59791
+ ]);
59792
+ VENDOR_GATE_MESSAGE = "Vendor gate: this tool operates on Huawei Cloud. Pass vendorConfirmed with the user's establishing words \u2014 the quote where they named Huawei Cloud, an hcloud artifact, a myhuaweicloud endpoint, a Huawei region ID, or an earlier confirmation. The devkit being installed is NOT confirmation. If you cannot quote the user, ask which cloud they mean, then retry once established.";
59793
+ VENDOR_CHALLENGE_MESSAGE = "Vendor challenge: first Huawei Cloud tool call this session \u2014 is the vendorConfirmed quote the user's actual words, or invented? An invented quote is a fabricated user statement. If invented, or the vendor was only assumed, ask which cloud they mean now. Retry the same call to proceed; this challenge appears once per session.";
59794
+ vendorChallengeConsumed = /* @__PURE__ */ new Map();
59795
+ }
59796
+ });
59797
+
59798
+ // plugins/huaweicloud-core/dist.new/packs/enable.js
59799
+ function setRuntimePacksOverride(raw) {
59800
+ const parsed = parseDevkitPacks(raw);
59801
+ if (!parsed.raw) {
59802
+ throw new Error("Runtime pack override cannot be blank. Clear it with reset instead.");
59803
+ }
59804
+ if (parsed.unknown.length > 0) {
59805
+ throw new Error(`Runtime pack override contains unknown pack id(s): ${parsed.unknown.join(", ")}. Valid pack ids: ${VALID_IDS.join(", ")}.`);
59806
+ }
59807
+ runtimeOverride = parsed;
59808
+ return parsed;
59809
+ }
59810
+ function clearRuntimePacksOverride() {
59811
+ runtimeOverride = null;
59812
+ }
59813
+ function runtimePacksOverride() {
59814
+ return runtimeOverride;
59815
+ }
59816
+ function resolveEnabledPacks(env = process.env) {
59817
+ if (runtimeOverride)
59818
+ return runtimeOverride.enabled;
59819
+ const raw = (env.DEVKIT_PACKS ?? "").trim();
59820
+ if (!raw)
59821
+ return new Set(PACK_IDS);
59822
+ const { unknown: unknown2, enabled } = parseDevkitPacks(raw);
59823
+ if (unknown2.length > 0) {
59824
+ throw new Error(`DEVKIT_PACKS contains unknown pack id(s): ${unknown2.join(", ")}. Valid pack ids: ${VALID_IDS.join(", ")}.`);
59825
+ }
59826
+ return enabled;
59827
+ }
59828
+ var VALID_IDS, runtimeOverride;
59829
+ var init_enable = __esm({
59830
+ "plugins/huaweicloud-core/dist.new/packs/enable.js"() {
59831
+ "use strict";
59832
+ init_pack_types();
59833
+ init_dependency_model();
59834
+ VALID_IDS = PACK_IDS;
59835
+ runtimeOverride = null;
59573
59836
  }
59574
59837
  });
59575
59838
 
@@ -60152,8 +60415,8 @@ var init_skill_frontmatter = __esm({
60152
60415
  });
60153
60416
 
60154
60417
  // plugins/huaweicloud-core/dist.new/skill-disclosure.js
60155
- import { readFileSync as readFileSync32, readdirSync as readdirSync7, existsSync as existsSync33 } from "node:fs";
60156
- import { join as join43, dirname as dirname24 } from "node:path";
60418
+ import { readFileSync as readFileSync32, readdirSync as readdirSync7, existsSync as existsSync34 } from "node:fs";
60419
+ import { join as join44, dirname as dirname25 } from "node:path";
60157
60420
  import { fileURLToPath as fileURLToPath10 } from "node:url";
60158
60421
  function verifySkillTree(root = SKILLS_ROOT) {
60159
60422
  const present2 = new Set(listSkillDirs(root));
@@ -60169,8 +60432,8 @@ function verifySkillTree(root = SKILLS_ROOT) {
60169
60432
  }
60170
60433
  }
60171
60434
  function referenceFilenames(skillName) {
60172
- const refDir = join43(SKILLS_ROOT, skillName, "references");
60173
- if (!existsSync33(refDir))
60435
+ const refDir = join44(SKILLS_ROOT, skillName, "references");
60436
+ if (!existsSync34(refDir))
60174
60437
  return [];
60175
60438
  return readdirSync7(refDir, { withFileTypes: true }).filter((entry) => entry.isFile() || entry.isSymbolicLink()).map((entry) => entry.name).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
60176
60439
  }
@@ -60202,7 +60465,7 @@ function listSkills(pack, opts = {}) {
60202
60465
  if (!enabled.has(entry.id))
60203
60466
  continue;
60204
60467
  for (const skillName of entry.skills) {
60205
- const fm = parseSkillFrontmatter(readFileSync32(join43(SKILLS_ROOT, skillName, "SKILL.md"), "utf8"));
60468
+ const fm = parseSkillFrontmatter(readFileSync32(join44(SKILLS_ROOT, skillName, "SKILL.md"), "utf8"));
60206
60469
  skills.push({
60207
60470
  name: skillName,
60208
60471
  description: fm.description ?? "",
@@ -60230,8 +60493,8 @@ async function retrieveSkill(name, opts = {}) {
60230
60493
  error: 'Invalid skill name "' + skillName + '". Skill names are lowercase letters, digits, and dashes.'
60231
60494
  };
60232
60495
  }
60233
- const skillPath = join43(SKILLS_ROOT, skillName, "SKILL.md");
60234
- if (!existsSync33(skillPath)) {
60496
+ const skillPath = join44(SKILLS_ROOT, skillName, "SKILL.md");
60497
+ if (!existsSync34(skillPath)) {
60235
60498
  const enabled = resolveEnabledPacks();
60236
60499
  const dirs = listSkillDirs(SKILLS_ROOT).filter((dir) => {
60237
60500
  const owner2 = SKILL_OWNER.get(dir);
@@ -60249,7 +60512,7 @@ async function retrieveSkill(name, opts = {}) {
60249
60512
  const content = readFileSync32(skillPath, "utf8");
60250
60513
  const references = [];
60251
60514
  for (const filename of referenceFilenames(skillName)) {
60252
- const refPath = join43(SKILLS_ROOT, skillName, "references", filename);
60515
+ const refPath = join44(SKILLS_ROOT, skillName, "references", filename);
60253
60516
  const raw = readFileSync32(refPath, "utf8");
60254
60517
  references.push({
60255
60518
  filename,
@@ -60281,29 +60544,29 @@ var init_skill_disclosure = __esm({
60281
60544
  init_skill_tree();
60282
60545
  init_skill_frontmatter();
60283
60546
  init_capability_catalog();
60284
- __dirname8 = dirname24(fileURLToPath10(import.meta.url));
60285
- SKILLS_ROOT = join43(__dirname8, "..", "skills");
60547
+ __dirname8 = dirname25(fileURLToPath10(import.meta.url));
60548
+ SKILLS_ROOT = join44(__dirname8, "..", "skills");
60286
60549
  REFERENCE_CAP = 4e3;
60287
60550
  }
60288
60551
  });
60289
60552
 
60290
60553
  // plugins/huaweicloud-core/dist.new/search-docs.js
60291
- import { readFileSync as readFileSync33, existsSync as existsSync34 } from "node:fs";
60292
- import { join as join44 } from "node:path";
60554
+ import { readFileSync as readFileSync33, existsSync as existsSync35 } from "node:fs";
60555
+ import { join as join45 } from "node:path";
60293
60556
  async function searchDocs(query, topic = "all") {
60294
60557
  const q = String(query || "").toLowerCase();
60295
60558
  const tokens = q.split(/\s+/).filter((t) => t.length > 0);
60296
60559
  const enabled = resolveEnabledPacks();
60297
60560
  const results = [];
60298
60561
  try {
60299
- if (existsSync34(SKILLS_ROOT)) {
60562
+ if (existsSync35(SKILLS_ROOT)) {
60300
60563
  const dirs = listSkillDirs(SKILLS_ROOT);
60301
60564
  for (const dir of dirs) {
60302
60565
  const owner = SKILL_OWNER.get(dir);
60303
60566
  if (owner && !enabled.has(owner))
60304
60567
  continue;
60305
- const skillPath = join44(SKILLS_ROOT, dir, "SKILL.md");
60306
- if (!existsSync34(skillPath))
60568
+ const skillPath = join45(SKILLS_ROOT, dir, "SKILL.md");
60569
+ if (!existsSync35(skillPath))
60307
60570
  continue;
60308
60571
  const content = readFileSync33(skillPath, "utf8");
60309
60572
  const fm = parseSkillFrontmatter(content);
@@ -60368,12 +60631,13 @@ async function callTool(name, rawArgs = {}, opts = {}) {
60368
60631
  const args = normalizeNumericArgs(rawArgs);
60369
60632
  const toolValue = toolInvokeValue(name, args);
60370
60633
  trackToolInvoke(name, toolValue);
60634
+ const paramWarnings = unknownParamWarnings(args, toolArgKeys(name));
60371
60635
  if (!traceEnabled())
60372
- return dispatchTool(name, args, opts);
60636
+ return attachParamWarnings(await dispatchTool(name, args, opts), paramWarnings);
60373
60637
  try {
60374
60638
  const result = await dispatchTool(name, args, opts);
60375
60639
  recordToolCall(name, args, true);
60376
- return result;
60640
+ return attachParamWarnings(result, paramWarnings);
60377
60641
  } catch (error62) {
60378
60642
  recordToolCall(name, args, false, error62);
60379
60643
  throw error62;
@@ -60424,7 +60688,10 @@ function hookResult(result) {
60424
60688
  ok: result.decision !== "deny",
60425
60689
  decision: result.decision,
60426
60690
  findings: result.findings,
60427
- nextStep: result.decision === "deny" ? "Revise the command, artifact, or deployment plan before execution." : result.decision === "warn" ? "Review the warnings with the user before proceeding." : "No Huawei Cloud hook risk rule matched."
60691
+ // allow means "no rule matched", never "approved": make that explicit so
60692
+ // an agent cannot read a green advisory check as a safety verdict.
60693
+ ...result.decision === "allow" ? { unmatched: true } : {},
60694
+ nextStep: result.decision === "deny" ? "Revise the command, artifact, or deployment plan before execution." : result.decision === "warn" ? "Review the warnings with the user before proceeding." : "No Huawei Cloud hook risk rule matched. This is not a safety verdict or an approval."
60428
60695
  };
60429
60696
  }
60430
60697
  function withUnknownOperationWarn(command, result, classify2 = classifyTextCommand) {
@@ -60436,6 +60703,9 @@ function withUnknownOperationWarn(command, result, classify2 = classifyTextComma
60436
60703
  } catch {
60437
60704
  return { ...result, decision: "warn", findings: [unverifiedFinding(command)] };
60438
60705
  }
60706
+ if (classification?.risk === "write" || classification?.risk === "execution") {
60707
+ return { ...result, decision: "warn", findings: [writeOperationFinding(command)] };
60708
+ }
60439
60709
  if (classification?.risk !== "unknown_read")
60440
60710
  return result;
60441
60711
  const triage = triageUnknownService(classification.service);
@@ -60459,7 +60729,7 @@ function withUnknownOperationWarn(command, result, classify2 = classifyTextComma
60459
60729
  }
60460
60730
  return { ...result, decision: "warn", findings: [unknownOperationFinding(command)] };
60461
60731
  }
60462
- var NUMERIC_ARG_KEYS, unknownOperationFinding, unverifiedFinding;
60732
+ var NUMERIC_ARG_KEYS, unknownOperationFinding, unverifiedFinding, writeOperationFinding;
60463
60733
  var init_tools10 = __esm({
60464
60734
  "plugins/huaweicloud-core/dist.new/tools.js"() {
60465
60735
  "use strict";
@@ -60472,8 +60742,10 @@ var init_tools10 = __esm({
60472
60742
  init_availability();
60473
60743
  init_registry();
60474
60744
  init_skill_tree();
60745
+ init_param_warnings();
60475
60746
  init_call_trace();
60476
60747
  init_tool_definitions();
60748
+ init_tool_schemas();
60477
60749
  init_vendor_gate();
60478
60750
  init_capability_catalog();
60479
60751
  init_packs_configure();
@@ -60508,6 +60780,16 @@ var init_tools10 = __esm({
60508
60780
  source: "command",
60509
60781
  evidence: command.slice(0, 240)
60510
60782
  });
60783
+ writeOperationFinding = (command) => ({
60784
+ ruleId: "hwc-write-operation",
60785
+ title: "Write or execution operation",
60786
+ category: "approval",
60787
+ severity: "warn",
60788
+ message: "This command is classified as a write or execution operation. Raw shell execution is blocked; writes require a plan and explicit user approval.",
60789
+ remediation: "Plan the exact command with huaweicloud_plan_cli_command, show it to the user, obtain explicit approval, then run it with huaweicloud_run_approved_command and the approval token.",
60790
+ source: "command",
60791
+ evidence: command.slice(0, 240)
60792
+ });
60511
60793
  }
60512
60794
  });
60513
60795
 
@@ -61297,9 +61579,9 @@ data:
61297
61579
  const initRequest = messages.find((m) => isInitializeRequest(m));
61298
61580
  const clientProtocolVersion = initRequest ? initRequest.params.protocolVersion : req.headers.get("mcp-protocol-version") ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
61299
61581
  if (this._enableJsonResponse) {
61300
- return new Promise((resolve9) => {
61582
+ return new Promise((resolve10) => {
61301
61583
  this._streamMapping.set(streamId, {
61302
- resolveJson: resolve9,
61584
+ resolveJson: resolve10,
61303
61585
  cleanup: () => {
61304
61586
  this._streamMapping.delete(streamId);
61305
61587
  }
@@ -61724,8 +62006,8 @@ var init_mcp_server_remote = __esm({
61724
62006
  });
61725
62007
 
61726
62008
  // plugins/huaweicloud-core/dist.new/mcp-server.js
61727
- import { rmSync as rmSync10, existsSync as existsSync36 } from "node:fs";
61728
- import { resolve as resolve8, dirname as dirname26 } from "node:path";
62009
+ import { rmSync as rmSync11, existsSync as existsSync37 } from "node:fs";
62010
+ import { resolve as resolve9, dirname as dirname27 } from "node:path";
61729
62011
  import { fileURLToPath as fileURLToPath12 } from "node:url";
61730
62012
 
61731
62013
  // plugins/huaweicloud-core/dist.new/mcp-stdio-transport.js
@@ -61914,15 +62196,15 @@ init_update_check();
61914
62196
  init_hcloud_probe();
61915
62197
  init_koocli_paths();
61916
62198
  import { spawn as spawn4 } from "node:child_process";
61917
- import { appendFileSync as appendFileSync5, closeSync, existsSync as existsSync35, mkdirSync as mkdirSync15, openSync, readFileSync as readFileSync34, rmSync as rmSync9, statSync as statSync10, writeFileSync as writeFileSync16 } from "node:fs";
61918
- import { dirname as dirname25, join as join45 } from "node:path";
62199
+ import { appendFileSync as appendFileSync5, closeSync, existsSync as existsSync36, mkdirSync as mkdirSync16, openSync, readFileSync as readFileSync34, rmSync as rmSync10, statSync as statSync10, writeFileSync as writeFileSync16 } from "node:fs";
62200
+ import { dirname as dirname26, join as join46 } from "node:path";
61919
62201
  import { fileURLToPath as fileURLToPath11 } from "node:url";
61920
- var __dirname9 = dirname25(fileURLToPath11(import.meta.url));
62202
+ var __dirname9 = dirname26(fileURLToPath11(import.meta.url));
61921
62203
  var INSTALL_LOCK_TTL_MS = 15 * 60 * 1e3;
61922
62204
  var INSTALL_LOG_MAX_BYTES = 1024 * 1024;
61923
62205
  var INSTALL_FAILURE_COOLDOWN_MS = 24 * 60 * 60 * 1e3;
61924
62206
  function failureMarkerPath() {
61925
- return join45(dirname25(kooCliInstallLockPath()), ".koocli-install.failed");
62207
+ return join46(dirname26(kooCliInstallLockPath()), ".koocli-install.failed");
61926
62208
  }
61927
62209
  function lockIsStale(body) {
61928
62210
  const ts = Number(body.trim());
@@ -61932,7 +62214,7 @@ function lockIsStale(body) {
61932
62214
  }
61933
62215
  function acquireInstallLock(lockPath = kooCliInstallLockPath()) {
61934
62216
  try {
61935
- mkdirSync15(dirname25(lockPath), { recursive: true });
62217
+ mkdirSync16(dirname26(lockPath), { recursive: true });
61936
62218
  let replace = false;
61937
62219
  try {
61938
62220
  replace = lockIsStale(String(readFileSync34(lockPath, "utf8")));
@@ -61940,7 +62222,7 @@ function acquireInstallLock(lockPath = kooCliInstallLockPath()) {
61940
62222
  }
61941
62223
  if (replace) {
61942
62224
  try {
61943
- rmSync9(lockPath, { force: true });
62225
+ rmSync10(lockPath, { force: true });
61944
62226
  } catch (error62) {
61945
62227
  return { acquired: false, reason: `stale lock cleanup failed: ${error62.message}` };
61946
62228
  }
@@ -61962,25 +62244,25 @@ function releaseInstallLock(lockPath = kooCliInstallLockPath(), ownedTs) {
61962
62244
  if (body !== String(ownedTs))
61963
62245
  return;
61964
62246
  }
61965
- rmSync9(lockPath, { force: true });
62247
+ rmSync10(lockPath, { force: true });
61966
62248
  } catch {
61967
62249
  }
61968
62250
  }
61969
62251
  function openKooCliInstallLog(logPath = kooCliInstallLogPath()) {
61970
62252
  try {
61971
- const st = existsSync35(logPath) ? statSync10(logPath) : null;
62253
+ const st = existsSync36(logPath) ? statSync10(logPath) : null;
61972
62254
  if (st && st.size > INSTALL_LOG_MAX_BYTES)
61973
- rmSync9(logPath, { force: true });
61974
- mkdirSync15(dirname25(logPath), { recursive: true });
62255
+ rmSync10(logPath, { force: true });
62256
+ mkdirSync16(dirname26(logPath), { recursive: true });
61975
62257
  } catch {
61976
62258
  }
61977
62259
  return openSync(logPath, "a", 384);
61978
62260
  }
61979
62261
  function resolvePreinstallCliEntry() {
61980
- const compiled = join45(__dirname9, "setup-cli.js");
61981
- if (existsSync35(compiled))
62262
+ const compiled = join46(__dirname9, "setup-cli.js");
62263
+ if (existsSync36(compiled))
61982
62264
  return compiled;
61983
- return join45(__dirname9, "setup-cli.ts");
62265
+ return join46(__dirname9, "setup-cli.ts");
61984
62266
  }
61985
62267
  var spawnForTests = null;
61986
62268
  var installStarted = false;
@@ -61994,7 +62276,7 @@ function maybePreinstallKooCli({ force = false } = {}) {
61994
62276
  return { launched: false, reason: "already installed" };
61995
62277
  }
61996
62278
  try {
61997
- if (existsSync35(failureMarkerPath())) {
62279
+ if (existsSync36(failureMarkerPath())) {
61998
62280
  const ts = Number(String(readFileSync34(failureMarkerPath(), "utf8")).trim());
61999
62281
  if (Number.isFinite(ts) && Date.now() - ts < INSTALL_FAILURE_COOLDOWN_MS) {
62000
62282
  return { launched: false, reason: "cooldown after an unsuccessful install attempt" };
@@ -62017,7 +62299,7 @@ function maybePreinstallKooCli({ force = false } = {}) {
62017
62299
  const releaseOwned = () => releaseInstallLock(kooCliInstallLockPath(), ownedTs);
62018
62300
  installStarted = true;
62019
62301
  const entryPath = resolvePreinstallCliEntry();
62020
- if (!existsSync35(entryPath)) {
62302
+ if (!existsSync36(entryPath)) {
62021
62303
  releaseOwned();
62022
62304
  console.error(`[preflight] install entry missing: ${entryPath}`);
62023
62305
  return { launched: false, reason: `install entry missing: ${entryPath}` };
@@ -62098,10 +62380,10 @@ try {
62098
62380
  } catch {
62099
62381
  }
62100
62382
  try {
62101
- const pluginDir = resolve8(dirname26(fileURLToPath12(import.meta.url)), "..");
62102
- const marker = resolve8(pluginDir, ".installed");
62103
- if (existsSync36(marker))
62104
- rmSync10(marker, { force: true });
62383
+ const pluginDir = resolve9(dirname27(fileURLToPath12(import.meta.url)), "..");
62384
+ const marker = resolve9(pluginDir, ".installed");
62385
+ if (existsSync37(marker))
62386
+ rmSync11(marker, { force: true });
62105
62387
  } catch {
62106
62388
  }
62107
62389
  if (transport === "remote") {