huaweicloud-devkit 2.0.0-next.3 → 2.0.0-next.5

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 (173) hide show
  1. package/README.md +3 -1
  2. package/package.json +3 -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/.mcp.json +55 -1
  8. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
  9. package/plugins/huaweicloud-core/dist/agents/codex-config.js +374 -0
  10. package/plugins/huaweicloud-core/dist/agents/codex-desktop.js +8 -1
  11. package/plugins/huaweicloud-core/dist/agents/codex.js +9 -0
  12. package/plugins/huaweicloud-core/dist/agents/opencode-config.js +141 -86
  13. package/plugins/huaweicloud-core/dist/agents/opencode.js +106 -39
  14. package/plugins/huaweicloud-core/dist/approval-gate.js +1185 -0
  15. package/plugins/huaweicloud-core/dist/approval-ledger.js +2331 -0
  16. package/plugins/huaweicloud-core/dist/approval-roster.js +89 -0
  17. package/plugins/huaweicloud-core/dist/approval-types.js +1 -0
  18. package/plugins/huaweicloud-core/dist/approvals-cli.js +4 -4
  19. package/plugins/huaweicloud-core/dist/data/icons-manifest.v1.json +23 -5
  20. package/plugins/huaweicloud-core/dist/dep/receipts.js +65 -5
  21. package/plugins/huaweicloud-core/dist/explain-error.js +9 -1
  22. package/plugins/huaweicloud-core/dist/hcloud-cli.js +1 -1
  23. package/plugins/huaweicloud-core/dist/hcloud-plan.js +68 -62
  24. package/plugins/huaweicloud-core/dist/lib/approval-mode.js +7 -5
  25. package/plugins/huaweicloud-core/dist/lib/approval-tokens.js +18 -4
  26. package/plugins/huaweicloud-core/dist/lib/call-trace.js +7 -14
  27. package/plugins/huaweicloud-core/dist/lib/confirm-language.js +50 -0
  28. package/plugins/huaweicloud-core/dist/lib/credentials.js +9 -9
  29. package/plugins/huaweicloud-core/dist/lib/hdkit/hdkit-gate.js +1398 -0
  30. package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +371 -32
  31. package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +6 -16
  32. package/plugins/huaweicloud-core/dist/lib/opencode-ask-rule.js +224 -78
  33. package/plugins/huaweicloud-core/dist/lib/opencode-saved-perms.js +282 -0
  34. package/plugins/huaweicloud-core/dist/lib/supplemental-redaction.js +116 -0
  35. package/plugins/huaweicloud-core/dist/lib/tool-schema-parts.js +31 -0
  36. package/plugins/huaweicloud-core/dist/lib/workspace-glob.js +442 -0
  37. package/plugins/huaweicloud-core/dist/mcp-config-io.js +28 -1
  38. package/plugins/huaweicloud-core/dist/mcp-protocol.js +68 -16
  39. package/plugins/huaweicloud-core/dist/mcp-server.js +6933 -1186
  40. package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
  41. package/plugins/huaweicloud-core/dist/mcp-stdio-transport.js +14 -4
  42. package/plugins/huaweicloud-core/dist/packs/auth/approval.js +249 -0
  43. package/plugins/huaweicloud-core/dist/packs/auth/tools.js +44 -44
  44. package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +85 -130
  45. package/plugins/huaweicloud-core/dist/packs/obs/approval.js +110 -0
  46. package/plugins/huaweicloud-core/dist/packs/obs/tools.js +7 -2
  47. package/plugins/huaweicloud-core/dist/packs/registry.js +20 -1
  48. package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +245 -0
  49. package/plugins/huaweicloud-core/dist/packs/sandbox/expose-task.js +71 -0
  50. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +180 -23
  51. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-credentials.js +13 -1
  52. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-hwexec.js +136 -0
  53. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-session.js +11 -1
  54. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +29 -3
  55. package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +93 -9
  56. package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +37 -10
  57. package/plugins/huaweicloud-core/dist/packs/secrets/approval.js +46 -0
  58. package/plugins/huaweicloud-core/dist/packs/secrets/tools.js +4 -1
  59. package/plugins/huaweicloud-core/dist/packs/update/approval.js +79 -0
  60. package/plugins/huaweicloud-core/dist/packs/update/tools.js +8 -1
  61. package/plugins/huaweicloud-core/dist/packs/voucher/tools.js +1 -1
  62. package/plugins/huaweicloud-core/dist/packs-configure.js +74 -0
  63. package/plugins/huaweicloud-core/dist/risk-rule-engine.js +20 -4
  64. package/plugins/huaweicloud-core/dist/safety/classify-hcloud.js +6 -6
  65. package/plugins/huaweicloud-core/dist/safety/classify-text.js +36 -0
  66. package/plugins/huaweicloud-core/dist/safety/policy.js +2 -0
  67. package/plugins/huaweicloud-core/dist/safety/redact.js +21 -3
  68. package/plugins/huaweicloud-core/dist/safety/risk-merge.js +24 -4
  69. package/plugins/huaweicloud-core/dist/sandbox/deploy-check.js +1 -1
  70. package/plugins/huaweicloud-core/dist/sandbox/devbridge-auth.js +65 -14
  71. package/plugins/huaweicloud-core/dist/sandbox/devbridge-cleanup.js +422 -0
  72. package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose-flow.js +66 -16
  73. package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose.js +13 -10
  74. package/plugins/huaweicloud-core/dist/sandbox/devbridge-keepalive.js +42 -2
  75. package/plugins/huaweicloud-core/dist/sandbox/devbridge-key.js +11 -3
  76. package/plugins/huaweicloud-core/dist/sandbox/devbridge-tunnel.js +6 -0
  77. package/plugins/huaweicloud-core/dist/sandbox/devbridge-validation.js +10 -1
  78. package/plugins/huaweicloud-core/dist/sandbox/hwexec-task.js +244 -0
  79. package/plugins/huaweicloud-core/dist/setup-cli.js +36 -1
  80. package/plugins/huaweicloud-core/dist/tool-definitions.js +13 -1
  81. package/plugins/huaweicloud-core/dist/tool-schemas.js +32 -6
  82. package/plugins/huaweicloud-core/dist/tools.js +76 -9
  83. package/plugins/huaweicloud-core/dist/update-registry.js +358 -5
  84. package/plugins/huaweicloud-core/dist/update-upgrade.js +1083 -14
  85. package/plugins/huaweicloud-core/dist/vendor-gate.js +2 -2
  86. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +150 -1
  87. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +67 -4
  88. package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
  89. package/plugins/huaweicloud-core/safety/policy.json +18 -11
  90. package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +115 -11
  91. package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +198 -143
  92. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +36 -12
  93. package/plugins/huaweicloud-core/skills/huawei-voucher/SKILL.md +2 -0
  94. package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +2 -2
  95. package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +11 -7
  96. package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +74 -29
  97. package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/SKILL.md +21 -19
  98. package/plugins/huaweicloud-core/src/agents/codex-config.ts +432 -0
  99. package/plugins/huaweicloud-core/src/agents/codex-desktop.ts +8 -1
  100. package/plugins/huaweicloud-core/src/agents/codex.ts +10 -0
  101. package/plugins/huaweicloud-core/src/agents/opencode-config.ts +176 -88
  102. package/plugins/huaweicloud-core/src/agents/opencode.ts +125 -54
  103. package/plugins/huaweicloud-core/src/approval-gate.ts +1306 -0
  104. package/plugins/huaweicloud-core/src/approval-ledger.ts +2446 -0
  105. package/plugins/huaweicloud-core/src/approval-roster.ts +127 -0
  106. package/plugins/huaweicloud-core/src/approval-types.ts +237 -0
  107. package/plugins/huaweicloud-core/src/approvals-cli.ts +4 -4
  108. package/plugins/huaweicloud-core/src/data/icons-manifest.v1.json +23 -5
  109. package/plugins/huaweicloud-core/src/dep/receipts.ts +84 -5
  110. package/plugins/huaweicloud-core/src/explain-error.ts +9 -1
  111. package/plugins/huaweicloud-core/src/hcloud-cli.ts +3 -0
  112. package/plugins/huaweicloud-core/src/hcloud-plan.ts +74 -71
  113. package/plugins/huaweicloud-core/src/lib/approval-mode.ts +7 -5
  114. package/plugins/huaweicloud-core/src/lib/approval-tokens.ts +19 -4
  115. package/plugins/huaweicloud-core/src/lib/call-trace.ts +7 -17
  116. package/plugins/huaweicloud-core/src/lib/confirm-language.ts +51 -0
  117. package/plugins/huaweicloud-core/src/lib/credentials.ts +9 -8
  118. package/plugins/huaweicloud-core/src/lib/hdkit/hdkit-gate.ts +1428 -0
  119. package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +408 -30
  120. package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +8 -15
  121. package/plugins/huaweicloud-core/src/lib/opencode-ask-rule.ts +302 -83
  122. package/plugins/huaweicloud-core/src/lib/opencode-saved-perms.ts +354 -0
  123. package/plugins/huaweicloud-core/src/lib/supplemental-redaction.ts +129 -0
  124. package/plugins/huaweicloud-core/src/lib/tool-schema-parts.ts +40 -0
  125. package/plugins/huaweicloud-core/src/lib/workspace-glob.ts +414 -0
  126. package/plugins/huaweicloud-core/src/mcp-config-io.ts +27 -1
  127. package/plugins/huaweicloud-core/src/mcp-protocol.ts +81 -17
  128. package/plugins/huaweicloud-core/src/mcp-server.ts +7 -7
  129. package/plugins/huaweicloud-core/src/mcp-stdio-transport.ts +14 -4
  130. package/plugins/huaweicloud-core/src/packs/auth/approval.ts +302 -0
  131. package/plugins/huaweicloud-core/src/packs/auth/tools.ts +54 -45
  132. package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +99 -137
  133. package/plugins/huaweicloud-core/src/packs/obs/approval.ts +122 -0
  134. package/plugins/huaweicloud-core/src/packs/obs/tools.ts +7 -2
  135. package/plugins/huaweicloud-core/src/packs/registry.ts +43 -1
  136. package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +296 -0
  137. package/plugins/huaweicloud-core/src/packs/sandbox/expose-task.ts +105 -0
  138. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +195 -23
  139. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-credentials.ts +11 -1
  140. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-hwexec.ts +228 -0
  141. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-session.ts +11 -1
  142. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +41 -14
  143. package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +120 -8
  144. package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +42 -9
  145. package/plugins/huaweicloud-core/src/packs/secrets/approval.ts +50 -0
  146. package/plugins/huaweicloud-core/src/packs/secrets/tools.ts +4 -1
  147. package/plugins/huaweicloud-core/src/packs/update/approval.ts +87 -0
  148. package/plugins/huaweicloud-core/src/packs/update/tools.ts +8 -1
  149. package/plugins/huaweicloud-core/src/packs/voucher/tools.ts +1 -1
  150. package/plugins/huaweicloud-core/src/packs-configure.ts +75 -0
  151. package/plugins/huaweicloud-core/src/risk-rule-engine.ts +20 -7
  152. package/plugins/huaweicloud-core/src/safety/classify-hcloud.ts +28 -16
  153. package/plugins/huaweicloud-core/src/safety/classify-text.ts +40 -0
  154. package/plugins/huaweicloud-core/src/safety/policy.ts +7 -0
  155. package/plugins/huaweicloud-core/src/safety/redact.ts +24 -6
  156. package/plugins/huaweicloud-core/src/safety/risk-merge.ts +26 -5
  157. package/plugins/huaweicloud-core/src/sandbox/deploy-check.ts +1 -1
  158. package/plugins/huaweicloud-core/src/sandbox/devbridge-auth.ts +74 -14
  159. package/plugins/huaweicloud-core/src/sandbox/devbridge-cleanup.ts +511 -0
  160. package/plugins/huaweicloud-core/src/sandbox/devbridge-expose-flow.ts +70 -18
  161. package/plugins/huaweicloud-core/src/sandbox/devbridge-expose.ts +26 -10
  162. package/plugins/huaweicloud-core/src/sandbox/devbridge-keepalive.ts +41 -2
  163. package/plugins/huaweicloud-core/src/sandbox/devbridge-key.ts +9 -3
  164. package/plugins/huaweicloud-core/src/sandbox/devbridge-tunnel.ts +24 -0
  165. package/plugins/huaweicloud-core/src/sandbox/devbridge-validation.ts +11 -1
  166. package/plugins/huaweicloud-core/src/sandbox/hwexec-task.ts +304 -0
  167. package/plugins/huaweicloud-core/src/setup-cli.ts +39 -1
  168. package/plugins/huaweicloud-core/src/tool-definitions.ts +13 -1
  169. package/plugins/huaweicloud-core/src/tool-schemas.ts +39 -6
  170. package/plugins/huaweicloud-core/src/tools.ts +124 -10
  171. package/plugins/huaweicloud-core/src/update-registry.ts +340 -5
  172. package/plugins/huaweicloud-core/src/update-upgrade.ts +1130 -14
  173. package/plugins/huaweicloud-core/src/vendor-gate.ts +2 -2
package/README.md CHANGED
@@ -404,7 +404,9 @@ Debug logs are written to the plugin's `telemetry/telemetry-debug.log` file.
404
404
  - **Sandbox (DevStation)** — temporary cloud runtime for web app deployment with instant public URL preview
405
405
  - **Capability packs (56 MCP tools)** — the devkit ships ten packs (core 12 tools; huaweicloud-cli carries the 20 service skills plus the 7 KooCLI execution tools; sandbox, auth, obs, voucher, update, discovery, secrets, huaweicloud-open-mcp for the rest). The huaweicloud-open-mcp pack proxies Huawei Cloud's full OpenAPI catalog through the local huaweicloud-open-mcp gateway with one generic call tool (`huaweicloud_gateway_call`: search_apis → list_apis → get_api discovery, execute_api with gateway-engine-gated consent; install the gateway with pip or uv, or just have `uvx` on PATH — no persistent install needed). Discover packs with `huaweicloud_list_packs` → `huaweicloud_pack_info`, browse the effective skill catalog with `huaweicloud_list_skills` (every enabled pack's skills with name, description, version, and reference filenames in one call, plus `skillRoot` — the tree's absolute location; which skills are ENABLED is pack-gated and can change at runtime, so a `huawei-*` service skill absent from the catalog belongs to a trimmed pack — the six `huaweicloud-*` meta-skills never appear in it and are always available), read the skill files directly under `skillRoot` on a same-machine install (the stdio server instructions state the location at initialize, so no catalog call is needed just to start reading; the taught policy is action-first — attempt the direct read, the attempt itself is the reachability check), and fall back to `huaweicloud_retrieve_skill` only when the attempted read fails or is denied — the taught reaction is falling back (the loader needs no file access), never repeatedly requesting. (the gated, telemetry-bearing, portable fallback, whose stdio payload also carries `skillRoot`; the six core meta-skills are additionally installed as native skill copies on directory-loading agents for system-prompt visibility). Trim the surface with `DEVKIT_PACKS` (comma-separated pack ids, e.g. `DEVKIT_PACKS=core,sandbox`); unset means all packs, unknown ids fail fast at startup, and core (pack meta, safety and discovery surface) is always included — trimming huaweicloud-cli removes the CLI execution face and its approval tools together. In a live stdio agent session, `huaweicloud_packs_configure` enables or disables packs on the spot (session-scoped; the refreshed tool list is pushed to the agent, and restarting the session restores the operator posture; the stateless remote surface does not carry it). Manage the surface persistently after install with `npx huaweicloud-devkit packs status | enable <ids> | disable <ids> | all [--target <agent>]`: the command rewrites `DEVKIT_PACKS` inside every installed agent's MCP config (the install-time `--packs` flag never overwrites an existing value), and the change takes effect on the agent's next session restart.
406
406
 
407
- Harness permission notes (skill-tree reads outside the workspace): the taught reaction above is universal — when a direct read fails or is denied, fall back to `huaweicloud_retrieve_skill`, never repeatedly request. The OpenCode installer writes a persistent permission seam (external_directory allow + edit deny over the tree globs); on other harnesses the operator can pre-allow the tree in the harness's own config if prompts bother them. Honest semantics for the seam: the allow covers every path-taking tool including bash (an allowed external directory inherits workspace defaults), so shell-mediated writes to the tree stop asking too — the edit deny governs only the edit tools; the tree is regenerated on every install/update, and the devkit's PreToolUse hook still denies hcloud writes. On opencode >= 2.0 the installer additionally writes the ASK approval posture — a top-level `permissions` entry with effect `ask` on the `huaweicloud-devkit_huaweicloud_run_approved_command` action plus `DEVKIT_APPROVAL_MODE=ask` in the mcp entry's environment — so every hcloud write makes OpenCode itself prompt (no terminal approve trip, no token UUID; below 2.0 neither half is written). Honest residual for that posture: answering OpenCode's prompt with "Allow always" saves an `allow` rule on the same action that removes the gate — `npx huaweicloud-devkit doctor` fails that state; see the huaweicloud-safety skill's approvals reference.
407
+ Harness permission notes (skill-tree reads outside the workspace): the taught reaction above is universal — when a direct read fails or is denied, fall back to `huaweicloud_retrieve_skill`, never repeatedly request. The OpenCode installer writes a persistent permission seam (external_directory allow + edit deny over the tree globs); on other harnesses the operator can pre-allow the tree in the harness's own config if prompts bother them. Honest semantics for the seam: the allow covers every path-taking tool including bash (an allowed external directory inherits workspace defaults), so shell-mediated writes to the tree stop asking too — the edit deny governs only the edit tools; the tree is regenerated on every install/update, and the devkit's PreToolUse hook still denies hcloud writes. On opencode at or above 1.19.0 the installer additionally writes the ASK approval posture as a pair — one exact `allow` entry per roster tool on the `huaweicloud-devkit_<tool>` action (a top-level `permissions` array entry on 2.0+, a `permission`-object key on 1.19–1.x; the two generations name the rule identically) plus `DEVKIT_APPROVAL_MODE=ask` in the mcp entry's environment. Ask mode means the server-run gate: the confirmation is raised inside the tool call, and the client `allow` rule only yields the client's own redundant popup to it. On opencode 2.x the gate raises an elicitation form, so the form is the single confirmation; on 1.19–1.x the client cannot render forms, so the yield hands the confirmation to the chat round-trip — the envelope answered in chat and retried with `approvedByUser: true`, which the consent ledger records as posture trust (the user's word as the agent reports it, no mechanical proof a human answered). No terminal approve trip, no token UUID; below the floor neither half is written, and an install or update still removes the legacy ask rules. The allow rules are written only when the server half is present or established this run; a user-set `DEVKIT_APPROVAL_MODE` value wins, no client rules are kept, and rules a past install wrote are removed value-exact so the user's mechanical posture stays clean. A client `allow` rule can no longer fail anything open, while a `deny` rule still blocks the call in the client — which is why `npx huaweicloud-devkit doctor` fails one, fails a leftover devkit-written ask rule (the migration missed it), and warns when allow rules are present without the server env or the client half is unverifiable. Ownership follows the skills-tree seam's doctrine — add-only-if-absent per rule and value-exact removal — including its accepted edge: a user-authored rule of the identical shape that predates the install is removed together with the devkit's own. Residual from pre-yield installs: a saved "Always allow" row in OpenCode's permission store is a stale grant — the gate never consults it, and the yield rules mean the popup no longer appears to recreate it. `npx huaweicloud-devkit doctor` reports it as a `[WARN]` naming the row and the store; clean it up with `opencode api GET /api/permission/saved` (list) and `opencode api DELETE /api/permission/saved/<id>` (remove). See the huaweicloud-safety skill's approvals reference.
408
+
409
+ Harness tool-routing note (Codex with a custom OpenAI-compatible provider): codex presents MCP tools as namespace-type tools and dispatches only through the `namespace` field on function_call items, with no flat-name fallback. A provider that drops that field (request history and/or generated calls) turns every regenerated call namespace-less, so codex answers `unsupported call: <huaweicloud tool>` without the call ever reaching the devkit — measured 2026-11-13 on codex 0.167.2 with an OpenAI-compatible gateway (a live session: 690 of 692 huaweicloud calls failed this way, only the fresh-history first call dispatched; reproduced with a two-call `codex exec` against the same provider). Nothing devkit-side can observe or fix these calls. Do not retry — the identical call cannot succeed. Remediation is gateway-side: round-trip the `namespace` field on function_call items in both directions (or use a provider that preserves it). Measured non-fix: codex's `non_prefixed_mcp_tool_names` feature only renames the namespace; regenerated calls still arrive namespace-less. The huaweicloud-troubleshooting skill and the server's initialize instructions teach the signature so agents stop retrying and report it instead.
408
410
 
409
411
  | Harness | Outside-workspace reads | Operator relief |
410
412
  | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "huaweicloud-devkit",
3
3
  "mcpName": "io.github.huaweicloud/huaweicloud-devkit",
4
- "version": "2.0.0-next.3",
4
+ "version": "2.0.0-next.5",
5
5
  "kooCliVersion": "7.3.12",
6
6
  "description": "Agent toolkit that helps coding agents use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities safely and accurately.",
7
7
  "type": "module",
@@ -42,6 +42,8 @@
42
42
  "prepack": "npm run build && node ./scripts/sync-skills.mjs --check",
43
43
  "skills:sync": "node ./scripts/sync-skills.mjs --write",
44
44
  "test": "node --experimental-test-module-mocks --test \"test/*.test.ts\"",
45
+ "pretest:quick": "npm run build",
46
+ "test:quick": "node scripts/test-quick.mjs",
45
47
  "test:e2e": "node test/e2e/runner.ts",
46
48
  "format": "prettier --write .",
47
49
  "format:check": "prettier --check .",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "mcpServers": "./.mcp.json",
18
18
  "description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
19
- "version": "2.0.0-next.3",
19
+ "version": "2.0.0-next.5",
20
20
  "author": {
21
21
  "name": "HuaweiCloud Mate",
22
22
  "url": "https://github.com/huaweicloud"
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "mcpServers": "./.mcp.json",
21
21
  "description": "Agent toolkit that helps coding agents use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities safely and accurately.",
22
- "version": "2.0.0-next.3",
22
+ "version": "2.0.0-next.5",
23
23
  "author": {
24
24
  "name": "HuaweiCloud Mate",
25
25
  "url": "https://github.com/huaweicloud"
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "mcpServers": "./.mcp.json",
18
18
  "description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
19
- "version": "2.0.0-next.3",
19
+ "version": "2.0.0-next.5",
20
20
  "author": {
21
21
  "name": "HuaweiCloud Mate",
22
22
  "url": "https://github.com/huaweicloud"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huaweicloud-devkit",
3
- "version": "2.0.0-next.3",
3
+ "version": "2.0.0-next.5",
4
4
  "description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
5
5
  "author": {
6
6
  "name": "HuaweiCloud Mate",
@@ -5,7 +5,61 @@
5
5
  "args": ["./dist/mcp-server.js"],
6
6
  "cwd": ".",
7
7
  "env": {
8
- "HUAWEICLOUD_AGENT_TOOLKIT_MODE": "local"
8
+ "HUAWEICLOUD_AGENT_TOOLKIT_MODE": "local",
9
+ "DEVKIT_APPROVAL_MODE": "ask"
10
+ },
11
+ "tools": {
12
+ "huaweicloud_run_approved_command": {
13
+ "approval_mode": "approve"
14
+ },
15
+ "huaweicloud_sandbox_connect": {
16
+ "approval_mode": "approve"
17
+ },
18
+ "huaweicloud_sandbox_exec_with_session": {
19
+ "approval_mode": "approve"
20
+ },
21
+ "huaweicloud_sandbox_exec_one_shot": {
22
+ "approval_mode": "approve"
23
+ },
24
+ "huaweicloud_sandbox_expose_tunnel": {
25
+ "approval_mode": "approve"
26
+ },
27
+ "huaweicloud_sandbox_renew_tunnel": {
28
+ "approval_mode": "approve"
29
+ },
30
+ "huaweicloud_sandbox_keepalive_watchdog": {
31
+ "approval_mode": "approve"
32
+ },
33
+ "huaweicloud_sandbox_sign_agreement": {
34
+ "approval_mode": "approve"
35
+ },
36
+ "huaweicloud_sandbox_credentials": {
37
+ "approval_mode": "approve"
38
+ },
39
+ "huaweicloud_sandbox_shutdown": {
40
+ "approval_mode": "approve"
41
+ },
42
+ "huaweicloud_auth_init": {
43
+ "approval_mode": "approve"
44
+ },
45
+ "huaweicloud_auth_switch": {
46
+ "approval_mode": "approve"
47
+ },
48
+ "huaweicloud_obs_set_website_config": {
49
+ "approval_mode": "approve"
50
+ },
51
+ "huaweicloud_obs_set_cors": {
52
+ "approval_mode": "approve"
53
+ },
54
+ "huaweicloud_upgrade": {
55
+ "approval_mode": "approve"
56
+ },
57
+ "huaweicloud_secret_delete": {
58
+ "approval_mode": "approve"
59
+ },
60
+ "huaweicloud_packs_configure": {
61
+ "approval_mode": "approve"
62
+ }
9
63
  }
10
64
  }
11
65
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "huaweicloud-devkit",
3
- "version": "2.0.0-next.3",
3
+ "version": "2.0.0-next.5",
4
4
  "description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
5
5
  "author": {
6
6
  "name": "HuaweiCloud Mate",
@@ -0,0 +1,374 @@
1
+ // The codex client approval yield: per-tool `approval_mode` config for the
2
+ // devkit's MCP server — the codex half of the approval-chain yield (PR-5).
3
+ //
4
+ // Under codex's default approvalPolicy ("on-request") codex fires its OWN
5
+ // approval gate ahead of every MCP tool call, so a roster call is a double
6
+ // interaction: the codex dialog first, the devkit server's confirmation
7
+ // second (measured on codex-cli 0.167.2, probe home
8
+ // /tmp/opencode/probe-non-elicit-dlg — the same geometry PR-2 removed on
9
+ // opencode). The yield is the per-tool value the codex config understands,
10
+ // measured live on the same build: `approve` runs the call straight through
11
+ // with no codex dialog, so the devkit's own confirmation is the single
12
+ // surface. `prompt` shows an Allow/Cancel dialog with the tool name and up
13
+ // to 3 truncated argument lines (no persistence options); `auto` keeps
14
+ // codex's 4-option gate with persistence options. Neither fails anything
15
+ // open — the server gate confirms every roster call regardless of the
16
+ // client value — so the doctor treats every non-approve value as a WARN
17
+ // naming its direction, never a FAIL: a wrong value degrades UX (double
18
+ // interaction) or fails closed, and WARN is the honest ceiling. `prompt` is
19
+ // the taught fallback for the policy-off branch only, never a written value.
20
+ //
21
+ // WHERE the yield lives, settled by live measurement against codex 0.167.2
22
+ // plus the upstream source (core mcp_tool_call.rs,
23
+ // resolve_user_configured_approval_mode): codex reads per-tool
24
+ // approval_mode from TWO places, in order — the config layer stack's
25
+ // mcp_servers.<server>.tools.<tool> (the user's config.toml), then the
26
+ // PLUGIN-provided server definition (plugin.mcp_servers.<server>.tools.<tool>).
27
+ // The devkit server is plugin-provided on every current install (the CLI
28
+ // marketplace flow copies plugins/huaweicloud-core — including .mcp.json —
29
+ // into codex's cache; Codex Desktop reads the plugin dir), so the yield
30
+ // belongs in the devkit-owned .mcp.json. Writing config.toml instead is
31
+ // actively harmful: a tools table under [mcp_servers.huaweicloud-devkit]
32
+ // implies a config-declared server, and with no command/url codex refuses
33
+ // to load the whole config ("Error: failed to load bootstrap configuration
34
+ // — Caused by: invalid transport in `mcp_servers.huaweicloud-devkit`",
35
+ // measured live; the probe's config.toml always carried a transport for
36
+ // its probe server, which is why the plan's original config.toml dialect
37
+ // never met this shape). The installer therefore never touches the user's
38
+ // config.toml; a user's own per-tool value there WINS over the payload
39
+ // (the source's precedence), and the doctor surfaces it as a WARN.
40
+ //
41
+ // Ownership contracts: the payload .mcp.json is devkit-owned end to end —
42
+ // regenerated on every deploy, removed with the plugin dir / cache on
43
+ // uninstall — so the yield needs no add-only-if-absent or value-exact
44
+ // machinery. The user's config.toml is never written, so its values are
45
+ // user-owned by construction; the doctor reports them by name.
46
+ //
47
+ // Policy directions the doctor names, both measured on 0.167.2: codex's
48
+ // granular `mcp_elicitations = false` auto-declines every server form and
49
+ // substitutes codex's built-in gate, so every roster call fails CLOSED at
50
+ // the devkit gate until the policy is on — the remediation names the flip.
51
+ // A top-level `approval_policy = "never"` blocks MCP tool calls outright,
52
+ // ahead of the devkit gate.
53
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
54
+ import { homedir } from 'node:os';
55
+ import { join } from 'node:path';
56
+ import { APPROVAL_MCP_SERVER, APPROVAL_TOOLS } from "../approval-roster.js";
57
+ import { codexPluginProbe, getCodexPluginName, getMarketplaceName } from "../codex-probe.js";
58
+ import { codexDesktopPluginsDir } from "../targets.js";
59
+ import { asRecord } from "../lib/as-record.js";
60
+ // The yield value the devkit owns. Never "prompt" or "auto": those are
61
+ // remediation shapes for the policy-off branch, taught by the doctor only.
62
+ export const CODEX_APPROVAL_MODE = 'approve';
63
+ // The ask-mode env the payload .mcp.json carries beside the yield: codex
64
+ // passes the plugin-provided server entry's env to the MCP child (live-
65
+ // measured on codex-cli 0.167.2 — a roster call returned ELICITATION_DECLINED,
66
+ // the headless auto-decline of the server-raised form, proving both the
67
+ // passthrough and the capable-client ladder). The payload is the devkit-owned
68
+ // channel: there is no codex-side override for plugin-provided env, so an
69
+ // operator wanting token mode on codex edits their cached copy (and re-runs
70
+ // the install to restore it) — the doctor flags the drift.
71
+ export const CODEX_APPROVAL_MODE_ENV = 'ask';
72
+ // The `tools` map the payload .mcp.json carries inside the devkit's server
73
+ // entry — one per-tool block per roster tool, roster-driven so a
74
+ // registration PR widens the yield with the roster, not by hand. JSON
75
+ // object key order matches the roster order; callers that deep-compare
76
+ // should compare structurally, not by serialization.
77
+ export function codexApprovalToolsBlock() {
78
+ return Object.fromEntries(APPROVAL_TOOLS.map((tool) => [tool, { approval_mode: CODEX_APPROVAL_MODE }]));
79
+ }
80
+ // The ask-mode env half of the payload posture, as a record for entry writes
81
+ // (writeMcpServersFile merges it under the same `agentKey !== 'openclaw'`
82
+ // condition as the tools block, with the same wholesale drift healing).
83
+ export function codexApprovalEnv() {
84
+ return { DEVKIT_APPROVAL_MODE: CODEX_APPROVAL_MODE_ENV };
85
+ }
86
+ function classifyMode(mode) {
87
+ if (mode === 'approve' || mode === 'prompt' || mode === 'auto')
88
+ return mode;
89
+ return mode === undefined ? 'absent' : 'foreign';
90
+ }
91
+ // The per-tool states from a parsed .mcp.json (the payload shape codex's
92
+ // plugin loader reads): mcpServers.<server>.tools.<tool>.approval_mode. A
93
+ // file without our server entry reads as all-absent (a foreign server map
94
+ // never leaks in — asRecord drops nothing, the server key is exact).
95
+ export function readMcpJsonApprovalStates(config, tools = APPROVAL_TOOLS) {
96
+ const server = asRecord(asRecord(config.mcpServers)[APPROVAL_MCP_SERVER]);
97
+ const blocks = asRecord(server.tools);
98
+ return tools.map((tool) => {
99
+ const mode = asRecord(blocks[tool]).approval_mode;
100
+ return classifyMode(typeof mode === 'string' ? mode : undefined);
101
+ });
102
+ }
103
+ // Any mcp_servers tool table header in config.toml: the server segment is
104
+ // captured so the reader can pin the devkit's own server name instead of a
105
+ // regex that would silently accept a lookalike server. Trailing comments
106
+ // are tolerated (valid TOML) so a commented header still reads as the block
107
+ // it is, not as absence.
108
+ const BLOCK_HEADER_RE = /^\s*\[mcp_servers\.([A-Za-z0-9_-]+)\.tools\.([A-Za-z0-9_-]+)\]\s*(?:#.*)?$/;
109
+ const APPROVAL_MODE_LINE_RE = /^\s*approval_mode\s*=\s*"([^"]*)"\s*(?:#.*)?$/;
110
+ const ANY_TABLE_RE = /^\s*\[/;
111
+ // Reads every roster tool's per-tool state from the USER's config.toml
112
+ // text — the config-layer override channel, which the upstream source
113
+ // resolves BEFORE the plugin payload, so a value here wins over our yield.
114
+ // A block runs from its header to the next table header (or EOF); the FIRST
115
+ // approval_mode assignment in the body decides. Blocks under a different
116
+ // server name, or on a non-roster tool, are the user's own config and never
117
+ // read.
118
+ export function readCodexApprovalBlocks(text, tools = APPROVAL_TOOLS) {
119
+ const wanted = new Set(tools);
120
+ const state = new Map(tools.map((tool) => [tool, 'absent']));
121
+ let inBlock = null;
122
+ let mode;
123
+ const closeBlock = () => {
124
+ if (inBlock !== null)
125
+ state.set(inBlock, classifyMode(mode));
126
+ inBlock = null;
127
+ mode = undefined;
128
+ };
129
+ for (const line of text.split(/\r?\n/)) {
130
+ const header = BLOCK_HEADER_RE.exec(line);
131
+ if (header) {
132
+ closeBlock();
133
+ if (header[1] === APPROVAL_MCP_SERVER && wanted.has(header[2]))
134
+ inBlock = header[2];
135
+ continue;
136
+ }
137
+ if (inBlock === null || mode !== undefined)
138
+ continue;
139
+ const assignment = APPROVAL_MODE_LINE_RE.exec(line);
140
+ if (assignment)
141
+ mode = assignment[1];
142
+ }
143
+ closeBlock();
144
+ return tools.map((tool) => state.get(tool));
145
+ }
146
+ // codex's granular approval policy, measured on 0.167.2: with
147
+ // `mcp_elicitations = false` codex auto-declines every server form and
148
+ // substitutes its built-in gate, so every roster call fails CLOSED at the
149
+ // devkit gate until the policy is on. codex accepts TWO spellings of the
150
+ // value (both live-measured): the [approval_policy.granular] table and
151
+ // the inline table `approval_policy = { granular = { mcp_elicitations =
152
+ // false, … } }` — the inline spelling is exactly the machine the
153
+ // remediation-naming contract exists for, so the detector is a whole-file
154
+ // match on the false spelling. The negative lookbehind keeps lookalike
155
+ // keys (`allow_mcp_elicitations = false`) from tripping it; `true` is the
156
+ // healthy granular spelling and never does.
157
+ export function codexElicitPolicyOff(text) {
158
+ return /(?<![A-Za-z_])mcp_elicitations\s*=\s*false\b/.test(text);
159
+ }
160
+ // A top-level `approval_policy = "never"` blocks MCP tool calls outright,
161
+ // ahead of the devkit gate. TOML pins top-level keys before the first table
162
+ // header, so the scan stops at the first header — a [projects.*]-scoped
163
+ // spelling must not be misread as the machine's posture.
164
+ export function codexApprovalPolicyNever(text) {
165
+ for (const line of text.split(/\r?\n/)) {
166
+ if (ANY_TABLE_RE.test(line))
167
+ return false;
168
+ if (/^\s*approval_policy\s*=\s*"never"\s*(#.*)?$/.test(line))
169
+ return true;
170
+ }
171
+ return false;
172
+ }
173
+ // The user-override spellings codex honors that this doctor cannot parse
174
+ // (a full TOML parser is deliberately out of scope): dotted keys
175
+ // (mcp_servers.<server>.tools.<tool>.approval_mode = "…") and inline
176
+ // tables (tools = { <tool> = { approval_mode = "…" } } inside our server's
177
+ // section). Both live-verified to win over the payload, so a value in
178
+ // either shape must never read as absence — the doctor reports the
179
+ // dialect instead, the same honesty as the unreadable-config WARN.
180
+ export function codexOverridesUnparseableDialect(text) {
181
+ let inOurServer = false;
182
+ for (const line of text.split(/\r?\n/)) {
183
+ const header = /^\s*\[mcp_servers\.([A-Za-z0-9_-]+)[.\]]/.exec(line);
184
+ if (header) {
185
+ inOurServer = header[1] === APPROVAL_MCP_SERVER;
186
+ continue;
187
+ }
188
+ if (ANY_TABLE_RE.test(line)) {
189
+ inOurServer = false;
190
+ continue;
191
+ }
192
+ const dotted = /^\s*mcp_servers\.([A-Za-z0-9_-]+)\.tools\./.exec(line);
193
+ if (dotted && dotted[1] === APPROVAL_MCP_SERVER)
194
+ return true;
195
+ if (inOurServer && /^\s*tools\s*=\s*\{/.test(line))
196
+ return true;
197
+ }
198
+ return false;
199
+ }
200
+ // ── The payload candidates (what codex actually loads) ──
201
+ // The devkit plugin's cache dir under CODEX_HOME — the CLI marketplace
202
+ // flow's payload home. CODEX_HOME mirrors the resolution codex.ts's cache
203
+ // cleanup uses; codex resolves its whole home from this override.
204
+ export function codexPluginCacheDir() {
205
+ return join(process.env.CODEX_HOME || join(homedir(), '.codex'), 'plugins', 'cache', getMarketplaceName(), getCodexPluginName());
206
+ }
207
+ // Every .mcp.json under the cache dir (one per version dir). Every copy is
208
+ // verified, not just the newest: which version codex loads is codex's
209
+ // call, and a stale copy missing the yield changes that machine's posture.
210
+ // A missing cache dir reads as no candidates (not installed that way).
211
+ export function codexCacheMcpJsonPaths() {
212
+ const cacheDir = codexPluginCacheDir();
213
+ if (!existsSync(cacheDir))
214
+ return [];
215
+ let entries;
216
+ try {
217
+ entries = readdirSync(cacheDir);
218
+ }
219
+ catch {
220
+ return [];
221
+ }
222
+ const out = [];
223
+ for (const name of entries) {
224
+ const path = join(cacheDir, name, '.mcp.json');
225
+ try {
226
+ if (statSync(path).isFile())
227
+ out.push(path);
228
+ }
229
+ catch {
230
+ // unreadable or not a file — not a candidate
231
+ }
232
+ }
233
+ return out;
234
+ }
235
+ // The Codex Desktop payload's .mcp.json (the desktop deploy's plugin dir).
236
+ export function codexDesktopMcpJsonPath() {
237
+ return join(codexDesktopPluginsDir(), '.mcp.json');
238
+ }
239
+ // The doctor's shared reading: which roster tools sit in each non-approve
240
+ // state. Both channels (payload .mcp.json, config.toml overrides) ask the
241
+ // same question, so the derivation has one home.
242
+ function toolsInStates(states) {
243
+ const names = (wanted) => APPROVAL_TOOLS.filter((_tool, index) => states[index] === wanted).join(', ');
244
+ return {
245
+ prompt: names('prompt'),
246
+ auto: names('auto'),
247
+ foreign: names('foreign'),
248
+ absent: names('absent'),
249
+ };
250
+ }
251
+ // The payload half of the doctor row: every cached copy that carries our
252
+ // server must carry the full yield; a stale or hand-stripped copy is
253
+ // drift, healable by re-running the install (the payload is regenerated
254
+ // wholesale). A relevant machine with NO payload file at all gets a WARN,
255
+ // never a vacuous pass — the yield cannot be verified without the file
256
+ // codex reads it from.
257
+ function payloadDriftWarns(payloadPaths) {
258
+ const warns = [];
259
+ if (payloadPaths.length === 0) {
260
+ warns.push(`no devkit payload .mcp.json was found in the codex plugin cache or the Codex Desktop plugin dir, so the yield cannot be verified (${RERUN})`);
261
+ return warns;
262
+ }
263
+ for (const path of payloadPaths) {
264
+ let config;
265
+ let states;
266
+ try {
267
+ config = asRecord(JSON.parse(readFileSync(path, 'utf8')));
268
+ states = readMcpJsonApprovalStates(config);
269
+ }
270
+ catch {
271
+ warns.push(`${path} is unparseable, so its yield cannot be verified (${RERUN})`);
272
+ continue;
273
+ }
274
+ // The env half: a copy that carries our server entry but not the ask env
275
+ // runs the devkit in token mode (a stale pre-ask payload) — drift,
276
+ // healable by the same re-run.
277
+ if (asRecord(asRecord(asRecord(config.mcpServers)[APPROVAL_MCP_SERVER]).env).DEVKIT_APPROVAL_MODE !==
278
+ CODEX_APPROVAL_MODE_ENV) {
279
+ warns.push(`${path} does not set DEVKIT_APPROVAL_MODE="${CODEX_APPROVAL_MODE_ENV}" in the server env, so the devkit runs its default token mode under codex (${RERUN})`);
280
+ }
281
+ if (states.every((state) => state === 'approve'))
282
+ continue;
283
+ const { prompt, auto, foreign, absent } = toolsInStates(states);
284
+ if (prompt)
285
+ warns.push(`approval_mode "prompt" on ${prompt} in ${path} (double interaction) (${RERUN})`);
286
+ if (auto)
287
+ warns.push(`approval_mode "auto" on ${auto} in ${path} keeps codex's own gate ahead of the devkit's confirmation (${RERUN})`);
288
+ if (foreign)
289
+ warns.push(`approval_mode on ${foreign} in ${path} is not "approve", so codex's own approval gate may fire ahead of the devkit's confirmation (${RERUN})`);
290
+ if (absent)
291
+ warns.push(`the approve block is missing for ${absent} in ${path} (${RERUN})`);
292
+ }
293
+ return warns;
294
+ }
295
+ // ── The doctor row ──
296
+ const CODEX_POSTURE_LABEL = 'Codex approval posture';
297
+ const RERUN = 're-run: npx huaweicloud-devkit install --target codex (or update)';
298
+ // Verifies the yield where codex reads it. Self-gating, silent on machines
299
+ // the devkit has no codex relationship with: no payload .mcp.json (cache or
300
+ // desktop), no codex plugin answering installed, no desktop marketplace
301
+ // registration. `desktopRegistered` is passed in by the doctor shell
302
+ // (codexDesktopDoctorMcpConfigured already runs there as an MCP-configured
303
+ // candidate).
304
+ export function codexDoctorApprovalRow(ctx, desktopRegistered) {
305
+ const payloadPaths = [...codexCacheMcpJsonPaths(), codexDesktopMcpJsonPath()].filter((p) => existsSync(p));
306
+ // The user override + policy channel. An absent config.toml is the
307
+ // healthy no-overrides default (nothing to warn about); a present but
308
+ // unreadable one cannot be verified, which earns a WARN below when the
309
+ // machine has a devkit payload.
310
+ const configPath = join(process.env.CODEX_HOME || join(homedir(), '.codex'), 'config.toml');
311
+ let configText = null;
312
+ let configUnreadable = false;
313
+ try {
314
+ configText = readFileSync(configPath, 'utf8');
315
+ }
316
+ catch (error) {
317
+ configUnreadable = error.code !== 'ENOENT';
318
+ }
319
+ let relevant = payloadPaths.length > 0 || desktopRegistered;
320
+ if (!relevant) {
321
+ const probe = codexPluginProbe();
322
+ relevant = probe.ok && probe.installed;
323
+ }
324
+ if (!relevant)
325
+ return;
326
+ // 1. The payload half — every copy that carries our server must carry
327
+ // the full yield; a stale or hand-stripped copy is drift, healable by
328
+ // re-running the install (the payload is regenerated wholesale).
329
+ const payloadWarns = payloadDriftWarns(payloadPaths);
330
+ // 2. The user override half (config.toml) — a value here WINS over the
331
+ // payload (the config layer resolves first, upstream source), so it
332
+ // decides the machine's actual posture; WARN, never FAIL: no client
333
+ // value fails anything open. Overrides in a dialect this doctor cannot
334
+ // parse (dotted keys, inline tables) get the dialect WARN, never
335
+ // silence — reading them as absence would hide the winning value.
336
+ const overrideWarns = [];
337
+ if (configText !== null) {
338
+ if (codexOverridesUnparseableDialect(configText)) {
339
+ overrideWarns.push(`the user's config.toml carries per-tool overrides in a dialect this doctor cannot parse (dotted keys or inline tables), so the winning values cannot be verified — codex's own approval gate may fire ahead of the devkit's confirmation`);
340
+ }
341
+ const { prompt, auto, foreign } = toolsInStates(readCodexApprovalBlocks(configText));
342
+ if (prompt) {
343
+ overrideWarns.push(`the user's config.toml sets approval_mode "prompt" on ${prompt}, which wins over the payload and shows codex's own Allow/Cancel dialog ahead of the devkit's confirmation (double interaction)`);
344
+ }
345
+ if (auto) {
346
+ overrideWarns.push(`the user's config.toml sets approval_mode "auto" on ${auto}, which wins over the payload and keeps codex's own approval gate (with persistence options) ahead of the devkit's confirmation`);
347
+ }
348
+ if (foreign) {
349
+ overrideWarns.push(`the user's config.toml sets approval_mode on ${foreign}, which wins over the payload — codex's own approval gate may fire ahead of the devkit's confirmation`);
350
+ }
351
+ }
352
+ // 3. The policy directions, both config.toml-borne.
353
+ const policyWarns = [];
354
+ if (configText !== null) {
355
+ if (codexElicitPolicyOff(configText)) {
356
+ policyWarns.push(`codex's granular policy sets mcp_elicitations = false, so codex auto-declines every devkit confirmation form and every roster call fails closed at the devkit gate until the policy is on — flip it: set mcp_elicitations = true (or drop the granular approval_policy) in ${configPath}`);
357
+ }
358
+ if (codexApprovalPolicyNever(configText)) {
359
+ policyWarns.push(`approval_policy = "never" blocks MCP tool calls outright, ahead of the devkit gate — choose a policy that can ask, e.g. approval_policy = "on-request"`);
360
+ }
361
+ }
362
+ else if (configUnreadable) {
363
+ // A devkit payload exists but the override channel is unreadable, so
364
+ // user per-tool overrides and the approval policy cannot be verified.
365
+ overrideWarns.push(`the codex config at ${configPath} is unreadable, so user per-tool overrides and the approval policy cannot be verified`);
366
+ }
367
+ const warns = [...payloadWarns, ...overrideWarns, ...policyWarns];
368
+ if (warns.length === 0) {
369
+ ctx.check(`${CODEX_POSTURE_LABEL} (${APPROVAL_TOOLS.length} per-tool approve blocks + DEVKIT_APPROVAL_MODE="${CODEX_APPROVAL_MODE_ENV}" in the devkit payload)`, true, '');
370
+ }
371
+ else {
372
+ ctx.warn(`${CODEX_POSTURE_LABEL}: ${warns.join(' ')}`);
373
+ }
374
+ }
@@ -170,7 +170,14 @@ export function uninstallCodexDesktop() {
170
170
  if (removeIfExists(cacheDir)) {
171
171
  console.log(' Codex plugin cache cleaned');
172
172
  }
173
- // Clean up old config.toml section from pre-marketplace era
173
+ // Clean up old config.toml section from pre-marketplace era. The sweep is
174
+ // wholesale trunk behavior: EVERY [mcp_servers.huaweicloud-devkit…] table
175
+ // goes, including user-authored subtables under our server name (a user
176
+ // tools block vanishes with ours, and the doctor never sees it after the
177
+ // uninstall). The devkit's own yield never lands in config.toml at all
178
+ // (agents/codex-config.ts records why), so this pass removes legacy
179
+ // server sections plus whatever users placed under that name — nothing
180
+ // the current installer writes.
174
181
  const configPath = join(homedir(), '.codex', 'config.toml');
175
182
  if (existsSync(configPath)) {
176
183
  const lines = readFileSync(configPath, 'utf8').split(/\r?\n/);
@@ -125,6 +125,15 @@ export function installCodex() {
125
125
  console.log(` \x1b[31mCodex plugin installation failed.\x1b[0m`);
126
126
  return false;
127
127
  }
128
+ // The client yield (PR-5) needs no step here: the per-tool approve blocks
129
+ // ship inside the plugin payload's own .mcp.json (the repo's
130
+ // plugins/huaweicloud-core/.mcp.json, which `codex plugin add` copies
131
+ // into its cache) — the file codex reads per-tool approval_mode from for
132
+ // a plugin-provided server (agents/codex-config.ts). The user's
133
+ // config.toml is never touched: a tools table under
134
+ // [mcp_servers.huaweicloud-devkit] would imply a config-declared server,
135
+ // and without a transport codex refuses to load the whole config
136
+ // (live-measured "invalid transport" on codex-cli 0.167.2).
128
137
  return true;
129
138
  }
130
139
  export function uninstallCodex() {