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

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 (161) hide show
  1. package/README.md +3 -1
  2. package/package.json +3 -1
  3. package/plugins/huaweicloud-core/.claude-plugin/plugin.json +16 -3
  4. package/plugins/huaweicloud-core/.codex-plugin/plugin.json +16 -3
  5. package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +16 -3
  6. package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +16 -3
  7. package/plugins/huaweicloud-core/.mcp.json +55 -1
  8. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +16 -3
  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 +157 -31
  13. package/plugins/huaweicloud-core/dist/agents/opencode.js +129 -1
  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/hcloud-cli.js +1 -1
  22. package/plugins/huaweicloud-core/dist/hcloud-plan.js +77 -56
  23. package/plugins/huaweicloud-core/dist/lib/approval-mode.js +32 -0
  24. package/plugins/huaweicloud-core/dist/lib/approval-tokens.js +18 -4
  25. package/plugins/huaweicloud-core/dist/lib/call-trace.js +7 -14
  26. package/plugins/huaweicloud-core/dist/lib/confirm-language.js +50 -0
  27. package/plugins/huaweicloud-core/dist/lib/credentials.js +9 -9
  28. package/plugins/huaweicloud-core/dist/lib/hdkit/hdkit-gate.js +1398 -0
  29. package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +362 -32
  30. package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +6 -16
  31. package/plugins/huaweicloud-core/dist/lib/opencode-ask-rule.js +262 -0
  32. package/plugins/huaweicloud-core/dist/lib/opencode-saved-perms.js +282 -0
  33. package/plugins/huaweicloud-core/dist/lib/supplemental-redaction.js +116 -0
  34. package/plugins/huaweicloud-core/dist/lib/tool-schema-parts.js +31 -0
  35. package/plugins/huaweicloud-core/dist/lib/workspace-glob.js +442 -0
  36. package/plugins/huaweicloud-core/dist/mcp-config-io.js +28 -1
  37. package/plugins/huaweicloud-core/dist/mcp-protocol.js +75 -4
  38. package/plugins/huaweicloud-core/dist/mcp-server.js +6560 -898
  39. package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
  40. package/plugins/huaweicloud-core/dist/mcp-stdio-transport.js +14 -4
  41. package/plugins/huaweicloud-core/dist/packs/auth/approval.js +249 -0
  42. package/plugins/huaweicloud-core/dist/packs/auth/tools.js +44 -44
  43. package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +119 -112
  44. package/plugins/huaweicloud-core/dist/packs/obs/approval.js +110 -0
  45. package/plugins/huaweicloud-core/dist/packs/obs/tools.js +7 -2
  46. package/plugins/huaweicloud-core/dist/packs/registry.js +19 -1
  47. package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +245 -0
  48. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +156 -23
  49. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-credentials.js +13 -1
  50. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-hwexec.js +136 -0
  51. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-session.js +11 -1
  52. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +1 -0
  53. package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +79 -9
  54. package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +28 -9
  55. package/plugins/huaweicloud-core/dist/packs/secrets/approval.js +46 -0
  56. package/plugins/huaweicloud-core/dist/packs/secrets/tools.js +4 -1
  57. package/plugins/huaweicloud-core/dist/packs/update/approval.js +79 -0
  58. package/plugins/huaweicloud-core/dist/packs/update/tools.js +8 -1
  59. package/plugins/huaweicloud-core/dist/packs/voucher/tools.js +1 -1
  60. package/plugins/huaweicloud-core/dist/packs-configure.js +74 -0
  61. package/plugins/huaweicloud-core/dist/safety/classify-text.js +36 -0
  62. package/plugins/huaweicloud-core/dist/safety/policy.js +2 -0
  63. package/plugins/huaweicloud-core/dist/sandbox/deploy-check.js +1 -1
  64. package/plugins/huaweicloud-core/dist/sandbox/devbridge-auth.js +65 -14
  65. package/plugins/huaweicloud-core/dist/sandbox/devbridge-cleanup.js +422 -0
  66. package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose-flow.js +66 -16
  67. package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose.js +13 -10
  68. package/plugins/huaweicloud-core/dist/sandbox/devbridge-keepalive.js +42 -2
  69. package/plugins/huaweicloud-core/dist/sandbox/devbridge-key.js +11 -3
  70. package/plugins/huaweicloud-core/dist/sandbox/devbridge-tunnel.js +6 -0
  71. package/plugins/huaweicloud-core/dist/sandbox/devbridge-validation.js +10 -1
  72. package/plugins/huaweicloud-core/dist/sandbox/hwexec-task.js +244 -0
  73. package/plugins/huaweicloud-core/dist/setup-cli.js +42 -4
  74. package/plugins/huaweicloud-core/dist/tool-definitions.js +9 -1
  75. package/plugins/huaweicloud-core/dist/tool-schemas.js +32 -6
  76. package/plugins/huaweicloud-core/dist/tools.js +76 -9
  77. package/plugins/huaweicloud-core/dist/update-registry.js +358 -5
  78. package/plugins/huaweicloud-core/dist/update-upgrade.js +1083 -14
  79. package/plugins/huaweicloud-core/dist/vendor-gate.js +2 -2
  80. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +150 -1
  81. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +53 -3
  82. package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
  83. package/plugins/huaweicloud-core/safety/policy.json +18 -11
  84. package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +114 -10
  85. package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +190 -138
  86. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +36 -12
  87. package/plugins/huaweicloud-core/skills/huawei-voucher/SKILL.md +2 -0
  88. package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +5 -5
  89. package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +13 -8
  90. package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +78 -23
  91. package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/SKILL.md +21 -19
  92. package/plugins/huaweicloud-core/src/agents/codex-config.ts +432 -0
  93. package/plugins/huaweicloud-core/src/agents/codex-desktop.ts +8 -1
  94. package/plugins/huaweicloud-core/src/agents/codex.ts +10 -0
  95. package/plugins/huaweicloud-core/src/agents/opencode-config.ts +198 -30
  96. package/plugins/huaweicloud-core/src/agents/opencode.ts +157 -1
  97. package/plugins/huaweicloud-core/src/approval-gate.ts +1306 -0
  98. package/plugins/huaweicloud-core/src/approval-ledger.ts +2446 -0
  99. package/plugins/huaweicloud-core/src/approval-roster.ts +127 -0
  100. package/plugins/huaweicloud-core/src/approval-types.ts +237 -0
  101. package/plugins/huaweicloud-core/src/approvals-cli.ts +4 -4
  102. package/plugins/huaweicloud-core/src/data/icons-manifest.v1.json +23 -5
  103. package/plugins/huaweicloud-core/src/dep/receipts.ts +84 -5
  104. package/plugins/huaweicloud-core/src/hcloud-cli.ts +3 -0
  105. package/plugins/huaweicloud-core/src/hcloud-plan.ts +93 -63
  106. package/plugins/huaweicloud-core/src/lib/approval-mode.ts +34 -0
  107. package/plugins/huaweicloud-core/src/lib/approval-tokens.ts +19 -4
  108. package/plugins/huaweicloud-core/src/lib/call-trace.ts +7 -17
  109. package/plugins/huaweicloud-core/src/lib/confirm-language.ts +51 -0
  110. package/plugins/huaweicloud-core/src/lib/credentials.ts +9 -8
  111. package/plugins/huaweicloud-core/src/lib/hdkit/hdkit-gate.ts +1428 -0
  112. package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +377 -30
  113. package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +8 -15
  114. package/plugins/huaweicloud-core/src/lib/opencode-ask-rule.ts +350 -0
  115. package/plugins/huaweicloud-core/src/lib/opencode-saved-perms.ts +354 -0
  116. package/plugins/huaweicloud-core/src/lib/supplemental-redaction.ts +129 -0
  117. package/plugins/huaweicloud-core/src/lib/tool-schema-parts.ts +40 -0
  118. package/plugins/huaweicloud-core/src/lib/workspace-glob.ts +414 -0
  119. package/plugins/huaweicloud-core/src/mcp-config-io.ts +27 -1
  120. package/plugins/huaweicloud-core/src/mcp-protocol.ts +88 -5
  121. package/plugins/huaweicloud-core/src/mcp-server.ts +13 -0
  122. package/plugins/huaweicloud-core/src/mcp-stdio-transport.ts +14 -4
  123. package/plugins/huaweicloud-core/src/packs/auth/approval.ts +302 -0
  124. package/plugins/huaweicloud-core/src/packs/auth/tools.ts +54 -45
  125. package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +139 -120
  126. package/plugins/huaweicloud-core/src/packs/obs/approval.ts +122 -0
  127. package/plugins/huaweicloud-core/src/packs/obs/tools.ts +7 -2
  128. package/plugins/huaweicloud-core/src/packs/registry.ts +42 -1
  129. package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +296 -0
  130. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +168 -23
  131. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-credentials.ts +11 -1
  132. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-hwexec.ts +228 -0
  133. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-session.ts +11 -1
  134. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +1 -0
  135. package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +100 -8
  136. package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +31 -8
  137. package/plugins/huaweicloud-core/src/packs/secrets/approval.ts +50 -0
  138. package/plugins/huaweicloud-core/src/packs/secrets/tools.ts +4 -1
  139. package/plugins/huaweicloud-core/src/packs/update/approval.ts +87 -0
  140. package/plugins/huaweicloud-core/src/packs/update/tools.ts +8 -1
  141. package/plugins/huaweicloud-core/src/packs/voucher/tools.ts +1 -1
  142. package/plugins/huaweicloud-core/src/packs-configure.ts +75 -0
  143. package/plugins/huaweicloud-core/src/safety/classify-text.ts +40 -0
  144. package/plugins/huaweicloud-core/src/safety/policy.ts +7 -0
  145. package/plugins/huaweicloud-core/src/sandbox/deploy-check.ts +1 -1
  146. package/plugins/huaweicloud-core/src/sandbox/devbridge-auth.ts +74 -14
  147. package/plugins/huaweicloud-core/src/sandbox/devbridge-cleanup.ts +509 -0
  148. package/plugins/huaweicloud-core/src/sandbox/devbridge-expose-flow.ts +70 -18
  149. package/plugins/huaweicloud-core/src/sandbox/devbridge-expose.ts +26 -10
  150. package/plugins/huaweicloud-core/src/sandbox/devbridge-keepalive.ts +41 -2
  151. package/plugins/huaweicloud-core/src/sandbox/devbridge-key.ts +9 -3
  152. package/plugins/huaweicloud-core/src/sandbox/devbridge-tunnel.ts +24 -0
  153. package/plugins/huaweicloud-core/src/sandbox/devbridge-validation.ts +11 -1
  154. package/plugins/huaweicloud-core/src/sandbox/hwexec-task.ts +304 -0
  155. package/plugins/huaweicloud-core/src/setup-cli.ts +45 -3
  156. package/plugins/huaweicloud-core/src/tool-definitions.ts +9 -1
  157. package/plugins/huaweicloud-core/src/tool-schemas.ts +39 -6
  158. package/plugins/huaweicloud-core/src/tools.ts +124 -10
  159. package/plugins/huaweicloud-core/src/update-registry.ts +340 -5
  160. package/plugins/huaweicloud-core/src/update-upgrade.ts +1130 -14
  161. package/plugins/huaweicloud-core/src/vendor-gate.ts +2 -2
@@ -4,10 +4,20 @@
4
4
  // classification, OBS/SG/parameter warnings, required-parameter
5
5
  // validation, and the approval token. The consent layer itself lives in
6
6
  // src/lib/approval-tokens.ts.
7
+ //
8
+ // The plan's approval posture is mode-dependent (HcloudPlanOptions.
9
+ // approvalMode): 'ask' (DEVKIT_APPROVAL_MODE=ask) plans for the SERVER-run
10
+ // confirmation — the approval gate raises an elicitation form, or the T3
11
+ // chat round-trip on a client that cannot render one — so no token is
12
+ // minted and userConfirmation carries the ask note instead of a terminal
13
+ // approve line; 'token' (the default) keeps the mint + approve line
14
+ // contract above.
7
15
 
8
16
  import { classifyHcloudArgs, redactSecrets, stripExecutable, type ClassifyOptions } from './safety-policy.ts';
9
17
  import { isHcloudToken } from './safety/tokens.ts';
10
18
  import { createApprovalToken } from './lib/approval-tokens.ts';
19
+ import { foldSecretTokens, SECRET_KEY_TOKEN_RE, secretSegments } from './lib/supplemental-redaction.ts';
20
+ import type { ApprovalMode } from './lib/approval-mode.ts';
11
21
  import type { RiskDecision } from './risk-rule-engine.ts';
12
22
  import { obsWriteHint } from './hcloud-obs-redact.ts';
13
23
  import { applyPreflightFindings, preflightSecurityGroupCheck, type SgFinding } from './hcloud-sg-preflight.ts';
@@ -21,10 +31,15 @@ import { triageUnknownService } from './hcloud-triage.ts';
21
31
 
22
32
  // The plan's terminal-confirmation block: `needed` says the command waits
23
33
  // on a confirmation the user makes in their own terminal, `command` is the
24
- // exact line they run (present only on plans that minted a token).
34
+ // exact line they run (present only on plans that minted a token). Ask
35
+ // mode shifts the confirmation onto the server-run gate (a form, or the T3
36
+ // chat round-trip): `mode` names that posture and `note` teaches the run
37
+ // call that satisfies it — no `command` exists to name.
25
38
  export interface HcloudPlanUserConfirmation {
26
39
  needed: boolean;
27
40
  command?: string;
41
+ mode?: 'ask';
42
+ note?: string;
28
43
  }
29
44
 
30
45
  export interface HcloudPlan {
@@ -56,6 +71,12 @@ export interface HcloudPlanOptions extends ClassifyOptions {
56
71
  // False on run paths: only the plan face mints approval tokens. Defaults
57
72
  // true, so the plan tool face keeps its consent contract unchanged.
58
73
  mintApprovalToken?: boolean;
74
+ // The approval posture this plan reports: 'ask' suppresses token minting
75
+ // and describes the client-prompt confirmation in userConfirmation;
76
+ // 'token' (the default) keeps the terminal gate. The tool faces resolve
77
+ // it from DEVKIT_APPROVAL_MODE (lib/approval-mode.ts) — never a tool
78
+ // argument an agent could set.
79
+ approvalMode?: ApprovalMode;
59
80
  }
60
81
 
61
82
  // Does this command wait on the user's terminal confirmation? The verdict
@@ -69,13 +90,36 @@ export function needsUserConfirmation(args: string[], options: ClassifyOptions =
69
90
  return strict.decision === 'deny' && (strict.risk === 'write' || strict.risk === 'execution');
70
91
  }
71
92
 
72
- function quoteShellArg(value: unknown): string {
93
+ export function quoteShellArg(value: unknown): string {
73
94
  const text = String(value);
74
95
  if (!text) return '""';
75
96
  if (/^[A-Za-z0-9_./:=@-]+$/.test(text)) return text;
76
97
  return `"${text.replace(/(["\\])/g, '\\$1')}"`;
77
98
  }
78
99
 
100
+ // One redacted echo argument: the real argument's quoting shape with the
101
+ // value text replaced. A real argument quoteShellArg leaves bare stays bare
102
+ // (so a safe-charset substitution is the gate's plain line); one it would
103
+ // quote gets the same wrapper around the redacted spelling (so a
104
+ // shell-special substitution is the gate's quoted line).
105
+ function redactedCommandArg(raw: string, redacted: string): string {
106
+ if (quoteShellArg(raw) === raw) return redacted;
107
+ return `"${redacted.replace(/(["\\])/g, '\\$1')}"`;
108
+ }
109
+
110
+ // The accepted executable lines for a normalized argument list: the
111
+ // command-forward `command` field must equal one of them exactly. The plain
112
+ // space-joined line is the contract's stated anchor; the shell-quoted line is
113
+ // this module's own echo (plan.command), so a model that forwards the plan's
114
+ // echo verbatim passes too. The two coincide for the ordinary case (service,
115
+ // operation, --key=value) and differ only where an argument carries a space,
116
+ // a quote, or another character the echo has to quote.
117
+ export function hcloudExecutableLines(normalizedArgs: readonly string[]): string[] {
118
+ const plain = ['hcloud', ...normalizedArgs].join(' ');
119
+ const quoted = ['hcloud', ...normalizedArgs].map((arg) => quoteShellArg(arg)).join(' ');
120
+ return plain === quoted ? [plain] : [plain, quoted];
121
+ }
122
+
79
123
  function planningWarnings(args: string[]): string[] {
80
124
  const joined = args.join(' ');
81
125
  const warnings: string[] = [];
@@ -182,33 +226,14 @@ function leadingBinWarning(stripped: string): string {
182
226
  // pinning message no longer claims a reason. Free-form JSON bodies with
183
227
  // real secrets should go through plan→approve with literal values (hash
184
228
  // path), not the substitution flow.
185
- const SECRET_KEY_ALT =
186
- 'access[_-]?key(?:[_-]?(?:id|secret))?|secret[_-]?key|secret[_-]?string|secret[_-]?binary|security[_-]?token|x[_-]?auth[_-]?token|token|password|passwd|admin[_-]?pass|credential|input[_-]?value|user[_-]?data|metadata|private[_-]?key|authorization';
187
- // A bare key token (`--password`, `--server.adminPass`, `--dbpassword`): the
188
- // value rides the NEXT argv element. The optional prefix must end on a
189
- // separator char, or `--task` would parse as the SK key token.
190
- const SECRET_KEY_TOKEN_RE = new RegExp('^(?:--?[A-Za-z0-9_.-]*[._-])?(?:' + SECRET_KEY_ALT + '|AK|SK)$', 'i');
229
+ // The secret-token fold's primitives (the key vocabulary, the scanner, the
230
+ // argv fold) live in lib/supplemental-redaction.ts since PR-3a round 3 —
231
+ // one canonical home shared with the exec views and the token store, which
232
+ // cannot import this module's face (approval-tokens ← hcloud-cli would be
233
+ // a value cycle). The detector comments below describe THEIR semantics and
234
+ // stay authoritative for the substitution flow.
191
235
  const PLACEHOLDER_SECRET_VALUE_RE = /^["']?<{1,2}[A-Za-z0-9_ -]{1,40}>{1,2}["']?/;
192
236
 
193
- // Shared key+separator scanner (loop round 8): ONE global split drives every
194
- // consumer. The value segment of a key runs to the NEXT key occurrence — a
195
- // multi-key body (`{"token":"<x>","password":"Real"}`) yields one segment
196
- // per key, so a mixed placeholder/real body can no longer hide a real value
197
- // behind a lazy first match (loop round 7, seat-1 B1).
198
- const SECRET_KEY_SEP_RE = new RegExp(
199
- '((?:(?:' + SECRET_KEY_ALT + ')|\\b(?:AK|SK))["\'\\\\]*\\s*(?:[=:]|\\s|(?=["\']))\\s*)',
200
- 'gi',
201
- );
202
-
203
- function secretSegments(arg: string): Array<{ sep: string; value: string }> {
204
- const parts = String(arg).split(SECRET_KEY_SEP_RE);
205
- const segments: Array<{ sep: string; value: string }> = [];
206
- for (let i = 1; i < parts.length; i += 2) {
207
- segments.push({ sep: parts[i] ?? '', value: parts[i + 1] ?? '' });
208
- }
209
- return segments;
210
- }
211
-
212
237
  function placeholderShaped(value: string): boolean {
213
238
  return PLACEHOLDER_SECRET_VALUE_RE.test(value.trim());
214
239
  }
@@ -264,34 +289,12 @@ export function firstPlaceholderSecretArg(args: string[]): string | null {
264
289
  // the map-only version dropped the two-token branch and let cross-form
265
290
  // swaps through). The redactor's own output cannot serve here — it never
266
291
  // folds the two-token/glued forms, so the substitution flow dead-ended in
267
- // a mismatch (loop round 4, seat-1 B2).
292
+ // a mismatch (loop round 4, seat-1 B2). Since PR-3a round 3 the fold body
293
+ // lives in the shared leaf (lib/supplemental-redaction.ts) with the exec
294
+ // views and the token store as its co-consumers; this export keeps the
295
+ // run face's canonical name.
268
296
  export function pinViewArgs(args: string[]): string[] {
269
- const out: string[] = [];
270
- for (let i = 0; i < args.length; i += 1) {
271
- const arg = String(args[i]);
272
- const segments = secretSegments(arg);
273
- if (segments.length > 0) {
274
- const parts = String(arg).split(SECRET_KEY_SEP_RE);
275
- let folded = parts[0] ?? '';
276
- for (let j = 1; j < parts.length; j += 2) {
277
- folded += parts[j] + '<redacted>';
278
- }
279
- out.push(folded);
280
- continue;
281
- }
282
- const next = i + 1 < args.length ? String(args[i + 1]) : undefined;
283
- if (SECRET_KEY_TOKEN_RE.test(arg) && next !== undefined && !SECRET_KEY_TOKEN_RE.test(next)) {
284
- // Bare key token with its value riding the next argv element — fold
285
- // the value, keep the key. A CHAINED bare key (`--password --token x`)
286
- // is left for its own iteration so no real value hides behind the
287
- // skip (loop round 7, seat-1 residual).
288
- out.push(arg, '<redacted>');
289
- i += 1;
290
- continue;
291
- }
292
- out.push(arg);
293
- }
294
- return out;
297
+ return foldSecretTokens(args) as string[];
295
298
  }
296
299
 
297
300
  function validateRequiredParams(args: string[]): { valid: boolean; missing: string[]; hints: string[] } {
@@ -309,7 +312,20 @@ export function planHcloudCommand(args: unknown, options: HcloudPlanOptions = {}
309
312
  const inputArgs = Array.isArray(args) ? args.map(String) : [];
310
313
  const { args: normalizedArgs, stripped } = stripLeadingHcloudBinArgs(inputArgs);
311
314
  const classification = classifyHcloudArgs(normalizedArgs, options);
312
- const command = ['hcloud', ...normalizedArgs].map((arg) => quoteShellArg(arg)).join(' ');
315
+ // The echo reproduces the REAL argument's quoting SHAPE and redacts only the
316
+ // value text inside it, so replacing `<redacted>` with the real value yields
317
+ // exactly the line the approval gate accepts for every charset family.
318
+ // Quoting must be decided from the raw argument: the placeholder itself is
319
+ // not charset-safe (`<` and `>` sit outside quoteShellArg's safe set), so
320
+ // quoting the redacted spelling unconditionally would wrap a safe-charset
321
+ // value the real line leaves bare and dead-end the substitution on the most
322
+ // common family (alphanumeric password, hex token). The old post-quote
323
+ // redaction had the mirror defect on the shell-special family (an
324
+ // unbalanced quote), so this one construction now serves both.
325
+ const redactedArgs = normalizedArgs.map((arg) => redactSecrets(arg));
326
+ const command = ['hcloud', ...normalizedArgs.map((raw, i) => redactedCommandArg(raw, redactedArgs[i] ?? ''))].join(
327
+ ' ',
328
+ );
313
329
  const warnings: Array<string | SgFinding> = planningWarnings(normalizedArgs);
314
330
  if (stripped !== null) warnings.unshift(leadingBinWarning(stripped));
315
331
  const obsHint = obsWriteHint(normalizedArgs);
@@ -349,8 +365,13 @@ export function planHcloudCommand(args: unknown, options: HcloudPlanOptions = {}
349
365
  warnings.push(`${triage.message} ${triage.nextStep}`);
350
366
  }
351
367
  }
368
+ const approvalMode = options.approvalMode ?? 'token';
369
+ // Ask mode never mints: the confirmation is the server-run gate inside
370
+ // the run call, so there is no token to hand the model and nothing lands
371
+ // in the approvals store. Run paths keep mintApprovalToken:false in both
372
+ // modes.
352
373
  const approvalToken =
353
- options.mintApprovalToken === false
374
+ approvalMode === 'ask' || options.mintApprovalToken === false
354
375
  ? undefined
355
376
  : createApprovalToken(normalizedArgs, {
356
377
  secretsSubstitutable: secretsSubstitutable(normalizedArgs),
@@ -363,20 +384,29 @@ export function planHcloudCommand(args: unknown, options: HcloudPlanOptions = {}
363
384
  // The plan echo is a COMMAND string, not child-process output — banner
364
385
  // stripping is an output concern, and an argument VALUE that happens to
365
386
  // carry banner-shaped text must never blank the command the user is asked
366
- // to approve (redactSecrets only).
367
- command: redactSecrets(command),
368
- executableBlock: redactSecrets(command),
387
+ // to approve (redaction only, already applied per arg above so the
388
+ // quoting stays balanced).
389
+ command,
390
+ executableBlock: command,
369
391
  warnings,
370
392
  classification: applyPreflightFindings(effectiveClassification, sgFindings),
371
393
  sgFindings,
372
394
  ...(approvalToken !== undefined ? { approvalToken } : {}),
373
395
  // `command` exists only where a token was minted: a run-path plan stays
374
396
  // silent rather than name a line for a token the run cannot offer.
397
+ // Ask mode names the posture instead — the confirmation happens at the
398
+ // run call, and the note teaches exactly that.
375
399
  userConfirmation: needsConfirmation
376
- ? {
377
- needed: true,
378
- ...(approvalToken !== undefined ? { command: `npx huaweicloud-devkit approve ${approvalToken}` } : {}),
379
- }
400
+ ? approvalMode === 'ask'
401
+ ? {
402
+ needed: true,
403
+ mode: 'ask',
404
+ note: 'The confirmation happens on the server when huaweicloud_run_approved_command is called: an elicitation-capable client renders a form with this command line, and any other client returns ASK_CONFIRMATION_REQUIRED, which you answer by showing the user this command in chat and retrying with approvedByUser: true. Send the same args on every call. This command field is the display line: where it shows <redacted>, substitute the real values, and the args array spelled out is always accepted as the command. No terminal approval line or token is needed.',
405
+ }
406
+ : {
407
+ needed: true,
408
+ ...(approvalToken !== undefined ? { command: `npx huaweicloud-devkit approve ${approvalToken}` } : {}),
409
+ }
380
410
  : { needed: false },
381
411
  safeToRun: effectiveClassification.decision === 'allow',
382
412
  };
@@ -0,0 +1,34 @@
1
+ // The hcloud write-approval posture, resolved from DEVKIT_APPROVAL_MODE.
2
+ //
3
+ // 'token' (the default) is the out-of-band terminal gate: the plan mints
4
+ // an approval token, the user confirms it in their own terminal
5
+ // (`npx huaweicloud-devkit approve <uuid>`), and run_approved_command
6
+ // consumes the token before executing. 'ask' moves the confirmation onto
7
+ // the SERVER (PR-1.5): the operator opts in via the env var (normally
8
+ // written by the installer together with the client's ask rule), and the
9
+ // approval gate runs the confirmation itself inside the run call — an
10
+ // elicitation form on a client that declared the form capability, or the
11
+ // ASK_CONFIRMATION_REQUIRED chat round-trip whose retry carries
12
+ // approvedByUser. No terminal trip and no UUID in the model's context; the
13
+ // plan mints nothing.
14
+ //
15
+ // Resolution is exact-match and fail-loud, mirroring the DEVKIT_PACKS
16
+ // unknown-id doctrine: a typo'd mode must not silently fall back to the
17
+ // weaker gate, so anything but 'ask' or 'token' throws with the env name
18
+ // and the bad value (case included — 'ASK' throws). Unset or empty keeps
19
+ // 'token'. The resolver is pure and takes the env as a parameter; every
20
+ // reader re-resolves from process.env (the mode is process-stable for the
21
+ // life of the process), so there is deliberately no cached module state
22
+ // to disagree with a fresh read. The module imports nothing: it feeds
23
+ // both the bundled mcp-server graph and the unbundled setup-cli graph.
24
+
25
+ export type ApprovalMode = 'token' | 'ask';
26
+
27
+ export const APPROVAL_MODE_ENV = 'DEVKIT_APPROVAL_MODE';
28
+
29
+ export function approvalModeFromEnv(env: Record<string, string | undefined>): ApprovalMode {
30
+ const raw = env[APPROVAL_MODE_ENV];
31
+ if (raw === undefined || raw === '') return 'token';
32
+ if (raw === 'ask' || raw === 'token') return raw;
33
+ throw new Error(`DEVKIT_APPROVAL_MODE must be "ask" or "token" (got "${raw}")`);
34
+ }
@@ -12,6 +12,7 @@ import {
12
12
  import { dirname, join } from 'node:path';
13
13
 
14
14
  import { redactSecrets } from '../safety-policy.ts';
15
+ import { redactWithSupplementalKeys } from './supplemental-redaction.ts';
15
16
  import { ensureMasterKey, resolveMasterKey, type ResolvedMasterKey } from './secret-vault/custody.ts';
16
17
  import { devkitStateBase } from './pack-state.ts';
17
18
 
@@ -289,7 +290,11 @@ export function createApprovalToken(
289
290
  const map = readApprovals();
290
291
  map[token] = {
291
292
  argsHash: hashArgs(rawArgs),
292
- argsRedacted: redactSecrets(rawArgs),
293
+ // The same supplemental-key pass the trace face and the gate's pin views
294
+ // run (lib/supplemental-redaction.ts): redactSecrets alone lets a
295
+ // long-lived key under api_key ride the store entry and the approve
296
+ // CLI's Confirming line in plaintext (interrogate round 2, F2).
297
+ argsRedacted: redactWithSupplementalKeys(redactSecrets(rawArgs)),
293
298
  createdAt: Date.now(),
294
299
  ...(opts.secretsSubstitutable === true ? { secretsSubstitutable: true } : {}),
295
300
  ...(opts.argsPinView !== undefined ? { argsPinView: opts.argsPinView } : {}),
@@ -403,6 +408,18 @@ export interface GrantVerification {
403
408
  // breaks verification, not just an argsHash swap.
404
409
  const GRANT_MAC_DOMAIN = 'huaweicloud-approval-grant';
405
410
 
411
+ // The reusable custody-HMAC grant primitive: the evidence stamp shared by
412
+ // every confirmation channel (terminal today; elicitation and memo stamps
413
+ // in the later approval-chain PRs, each under its own domain). Custody
414
+ // material from one domain never verifies in another, so a grant proves
415
+ // both WHO confirmed (possession of the custody key) and WHAT they
416
+ // confirmed (the subject) and WHEN (the timestamp rides the message).
417
+ export function custodyGrantMac(masterKey: Buffer, domain: string, subject: string, confirmedAt: number): string {
418
+ return createHmac('sha256', masterKey)
419
+ .update(`${domain}\x00${subject}\x00${String(confirmedAt)}`)
420
+ .digest('hex');
421
+ }
422
+
406
423
  // The shape digests through hashArgs (the module's canonical-JSON machinery),
407
424
  // so the confirm side and the verify side agree no matter how the store was
408
425
  // re-serialized between them. undefined-valued keys drop on both sides.
@@ -421,9 +438,7 @@ function grantMac(
421
438
  secretsSubstitutable: entry.secretsSubstitutable,
422
439
  createdAt: entry.createdAt,
423
440
  });
424
- return createHmac('sha256', masterKey)
425
- .update(`${GRANT_MAC_DOMAIN}\x00${token}\x00${shapeDigest}\x00${String(confirmedAt)}`)
426
- .digest('hex');
441
+ return custodyGrantMac(masterKey, GRANT_MAC_DOMAIN, `${token}\x00${shapeDigest}`, confirmedAt);
427
442
  }
428
443
 
429
444
  export function confirmApprovalToken(token: string): ConfirmApprovalResult {
@@ -28,6 +28,10 @@
28
28
  import { appendFileSync, existsSync, writeFileSync } from 'node:fs';
29
29
 
30
30
  import { redactSecrets } from '../safety-policy.ts';
31
+ // The supplemental-key pass (api_key/apiKey/value): one shared leaf so
32
+ // every redaction consumer — the trace here, the approval gate's pin views —
33
+ // runs the same vocabulary.
34
+ import { redactWithSupplementalKeys } from './supplemental-redaction.ts';
31
35
 
32
36
  const TRACE_ENV = 'HUAWEICLOUD_DEVKIT_TRACE';
33
37
  const TRACE_VERSION = 1;
@@ -58,24 +62,10 @@ export type TraceRecord = ToolCallTraceRecord | DisclosureTraceRecord;
58
62
  // gateway_call toolArgs) and the secrets pack's set tool carries the
59
63
  // plaintext itself under value (channel=value) — no other tool schema uses
60
64
  // that arg name, so the denylist entry is collision-free. Trace redaction
61
- // must be a superset of the product's, so these get their own pass here.
62
- const SUPPLEMENTAL_SECRET_KEYS = new Set(['api_key', 'apikey', 'value']);
63
-
64
- function redactSupplemental(value: unknown): unknown {
65
- if (Array.isArray(value)) return value.map((item) => redactSupplemental(item));
66
- if (value && typeof value === 'object') {
67
- return Object.fromEntries(
68
- Object.entries(value as Record<string, unknown>).map(([key, val]) => [
69
- key,
70
- SUPPLEMENTAL_SECRET_KEYS.has(key.toLowerCase()) ? '<redacted>' : redactSupplemental(val),
71
- ]),
72
- );
73
- }
74
- return value;
75
- }
76
-
65
+ // must be a superset of the product's, so the supplemental keys get their
66
+ // own pass (imported above from the shared leaf).
77
67
  export function redactForTrace(args: unknown): unknown {
78
- return redactSupplemental(redactSecrets(args));
68
+ return redactWithSupplementalKeys(redactSecrets(args));
79
69
  }
80
70
 
81
71
  export function traceEnabled(): boolean {
@@ -0,0 +1,51 @@
1
+ // The confirmation form's display language — the display-tier counterpart
2
+ // of lib/approval-mode.ts. Approval MODE is a safety concern and fails
3
+ // loud (a bogus DEVKIT_APPROVAL_MODE aborts the server at boot); display
4
+ // LANGUAGE is a UX concern and fails SOFT: an unrecognized value at any
5
+ // tier falls through to the next, and a gated call never fails because its
6
+ // language could not be resolved.
7
+ //
8
+ // Three tiers, highest authority first:
9
+ // 1. DEVKIT_CONFIRM_LANG the operator's explicit pin — human-written
10
+ // configuration outranks any inference (the same doctrine as
11
+ // DEVKIT_APPROVAL_MODE's user-value-wins).
12
+ // 2. args.confirmLanguage the model's per-call relay of the user's
13
+ // conversation language — the ONLY channel that observes the
14
+ // conversation, because the MCP server never sees the chat; the model
15
+ // is the context. The schema field's description teaches the model to
16
+ // send it.
17
+ // 3. the machine locale LC_ALL/LC_MESSAGES/LANG/LANGUAGE — the
18
+ // pre-hint behavior, kept as the floor.
19
+ // Values normalize by prefix: /^zh/i → zh, /^en/i → en, anything else
20
+ // ('fr', garbage, empty) is unrecognized and falls through. Only the form's
21
+ // DISPLAY strings localize (message, title, enumNames — see
22
+ // approval-gate.ts); the enum VALUES, the refusal envelopes, and the T3
23
+ // chat instruction stay English in every language — wire vocabulary the
24
+ // gate, the ledger, and the tests pin.
25
+
26
+ export type ConfirmLanguage = 'zh' | 'en';
27
+
28
+ const ZH = /^zh/i;
29
+ const EN = /^en/i;
30
+
31
+ function normalize(value: string | undefined): ConfirmLanguage | undefined {
32
+ if (typeof value !== 'string') return undefined;
33
+ const trimmed = value.trim();
34
+ if (trimmed === '') return undefined;
35
+ if (ZH.test(trimmed)) return 'zh';
36
+ if (EN.test(trimmed)) return 'en';
37
+ return undefined;
38
+ }
39
+
40
+ export function resolveConfirmLanguage(
41
+ args: Record<string, unknown>,
42
+ env: NodeJS.ProcessEnv = process.env,
43
+ ): ConfirmLanguage {
44
+ const pinned = normalize(env.DEVKIT_CONFIRM_LANG);
45
+ if (pinned !== undefined) return pinned;
46
+ const hinted = normalize(typeof args.confirmLanguage === 'string' ? args.confirmLanguage : undefined);
47
+ if (hinted !== undefined) return hinted;
48
+ const locales = [env.LC_ALL, env.LC_MESSAGES, env.LANG, env.LANGUAGE];
49
+ if (locales.some((locale) => typeof locale === 'string' && ZH.test(locale))) return 'zh';
50
+ return 'en';
51
+ }
@@ -68,7 +68,15 @@ export const pendingConfirms = new Map<string, PendingConfirm>();
68
68
  // 2026-11-05 UX report pinned that).
69
69
  export const consumedConfirms = new Map<string, { consumedAt: number }>();
70
70
 
71
- export function readImportFile() {
71
+ // The import channel's side-effect-free read. The approval gate resolves
72
+ // the channel BEFORE any consent, and a read that wipes the file on
73
+ // malformed content would mutate the user's state on the refusal path —
74
+ // so every reader peeks (a malformed file stays on disk,
75
+ // operator-visible), and only EXECUTION wipes (the switch handler's
76
+ // clearImportFile on non-replayable outcomes). The pre-PR-3b wiping read
77
+ // (readImportFile) is gone with its only consumer: the handler now
78
+ // resolves through the approval spec's snapshot, which peeks here.
79
+ export function peekImportFile() {
72
80
  const path = join(dirname(globalCredentialsPath()), 'creds-import.json');
73
81
  try {
74
82
  if (!existsSync(path)) return null;
@@ -81,13 +89,6 @@ export function readImportFile() {
81
89
  region: asText(record.region || ''),
82
90
  };
83
91
  } catch {
84
- // Malformed/undecodable import file is un-replayable — wipe it. A VALID
85
- // file is kept so a rejected persist can be replayed (see #502).
86
- try {
87
- rmSync(path, { force: true });
88
- } catch {
89
- // ignore
90
- }
91
92
  return null;
92
93
  }
93
94
  }