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.
- package/README.md +3 -1
- package/package.json +3 -1
- package/plugins/huaweicloud-core/.claude-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.mcp.json +55 -1
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/dist/agents/codex-config.js +374 -0
- package/plugins/huaweicloud-core/dist/agents/codex-desktop.js +8 -1
- package/plugins/huaweicloud-core/dist/agents/codex.js +9 -0
- package/plugins/huaweicloud-core/dist/agents/opencode-config.js +141 -86
- package/plugins/huaweicloud-core/dist/agents/opencode.js +106 -39
- package/plugins/huaweicloud-core/dist/approval-gate.js +1185 -0
- package/plugins/huaweicloud-core/dist/approval-ledger.js +2331 -0
- package/plugins/huaweicloud-core/dist/approval-roster.js +89 -0
- package/plugins/huaweicloud-core/dist/approval-types.js +1 -0
- package/plugins/huaweicloud-core/dist/approvals-cli.js +4 -4
- package/plugins/huaweicloud-core/dist/data/icons-manifest.v1.json +23 -5
- package/plugins/huaweicloud-core/dist/dep/receipts.js +65 -5
- package/plugins/huaweicloud-core/dist/explain-error.js +9 -1
- package/plugins/huaweicloud-core/dist/hcloud-cli.js +1 -1
- package/plugins/huaweicloud-core/dist/hcloud-plan.js +68 -62
- package/plugins/huaweicloud-core/dist/lib/approval-mode.js +7 -5
- package/plugins/huaweicloud-core/dist/lib/approval-tokens.js +18 -4
- package/plugins/huaweicloud-core/dist/lib/call-trace.js +7 -14
- package/plugins/huaweicloud-core/dist/lib/confirm-language.js +50 -0
- package/plugins/huaweicloud-core/dist/lib/credentials.js +9 -9
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkit-gate.js +1398 -0
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +371 -32
- package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +6 -16
- package/plugins/huaweicloud-core/dist/lib/opencode-ask-rule.js +224 -78
- package/plugins/huaweicloud-core/dist/lib/opencode-saved-perms.js +282 -0
- package/plugins/huaweicloud-core/dist/lib/supplemental-redaction.js +116 -0
- package/plugins/huaweicloud-core/dist/lib/tool-schema-parts.js +31 -0
- package/plugins/huaweicloud-core/dist/lib/workspace-glob.js +442 -0
- package/plugins/huaweicloud-core/dist/mcp-config-io.js +28 -1
- package/plugins/huaweicloud-core/dist/mcp-protocol.js +68 -16
- package/plugins/huaweicloud-core/dist/mcp-server.js +6933 -1186
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
- package/plugins/huaweicloud-core/dist/mcp-stdio-transport.js +14 -4
- package/plugins/huaweicloud-core/dist/packs/auth/approval.js +249 -0
- package/plugins/huaweicloud-core/dist/packs/auth/tools.js +44 -44
- package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +85 -130
- package/plugins/huaweicloud-core/dist/packs/obs/approval.js +110 -0
- package/plugins/huaweicloud-core/dist/packs/obs/tools.js +7 -2
- package/plugins/huaweicloud-core/dist/packs/registry.js +20 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +245 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/expose-task.js +71 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +180 -23
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-credentials.js +13 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-hwexec.js +136 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-session.js +11 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +29 -3
- package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +93 -9
- package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +37 -10
- package/plugins/huaweicloud-core/dist/packs/secrets/approval.js +46 -0
- package/plugins/huaweicloud-core/dist/packs/secrets/tools.js +4 -1
- package/plugins/huaweicloud-core/dist/packs/update/approval.js +79 -0
- package/plugins/huaweicloud-core/dist/packs/update/tools.js +8 -1
- package/plugins/huaweicloud-core/dist/packs/voucher/tools.js +1 -1
- package/plugins/huaweicloud-core/dist/packs-configure.js +74 -0
- package/plugins/huaweicloud-core/dist/risk-rule-engine.js +20 -4
- package/plugins/huaweicloud-core/dist/safety/classify-hcloud.js +6 -6
- package/plugins/huaweicloud-core/dist/safety/classify-text.js +36 -0
- package/plugins/huaweicloud-core/dist/safety/policy.js +2 -0
- package/plugins/huaweicloud-core/dist/safety/redact.js +21 -3
- package/plugins/huaweicloud-core/dist/safety/risk-merge.js +24 -4
- package/plugins/huaweicloud-core/dist/sandbox/deploy-check.js +1 -1
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-auth.js +65 -14
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-cleanup.js +422 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose-flow.js +66 -16
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose.js +13 -10
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-keepalive.js +42 -2
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-key.js +11 -3
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-tunnel.js +6 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-validation.js +10 -1
- package/plugins/huaweicloud-core/dist/sandbox/hwexec-task.js +244 -0
- package/plugins/huaweicloud-core/dist/setup-cli.js +36 -1
- package/plugins/huaweicloud-core/dist/tool-definitions.js +13 -1
- package/plugins/huaweicloud-core/dist/tool-schemas.js +32 -6
- package/plugins/huaweicloud-core/dist/tools.js +76 -9
- package/plugins/huaweicloud-core/dist/update-registry.js +358 -5
- package/plugins/huaweicloud-core/dist/update-upgrade.js +1083 -14
- package/plugins/huaweicloud-core/dist/vendor-gate.js +2 -2
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +150 -1
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +67 -4
- package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
- package/plugins/huaweicloud-core/safety/policy.json +18 -11
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +115 -11
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +198 -143
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +36 -12
- package/plugins/huaweicloud-core/skills/huawei-voucher/SKILL.md +2 -0
- package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +2 -2
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +11 -7
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +74 -29
- package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/SKILL.md +21 -19
- package/plugins/huaweicloud-core/src/agents/codex-config.ts +432 -0
- package/plugins/huaweicloud-core/src/agents/codex-desktop.ts +8 -1
- package/plugins/huaweicloud-core/src/agents/codex.ts +10 -0
- package/plugins/huaweicloud-core/src/agents/opencode-config.ts +176 -88
- package/plugins/huaweicloud-core/src/agents/opencode.ts +125 -54
- package/plugins/huaweicloud-core/src/approval-gate.ts +1306 -0
- package/plugins/huaweicloud-core/src/approval-ledger.ts +2446 -0
- package/plugins/huaweicloud-core/src/approval-roster.ts +127 -0
- package/plugins/huaweicloud-core/src/approval-types.ts +237 -0
- package/plugins/huaweicloud-core/src/approvals-cli.ts +4 -4
- package/plugins/huaweicloud-core/src/data/icons-manifest.v1.json +23 -5
- package/plugins/huaweicloud-core/src/dep/receipts.ts +84 -5
- package/plugins/huaweicloud-core/src/explain-error.ts +9 -1
- package/plugins/huaweicloud-core/src/hcloud-cli.ts +3 -0
- package/plugins/huaweicloud-core/src/hcloud-plan.ts +74 -71
- package/plugins/huaweicloud-core/src/lib/approval-mode.ts +7 -5
- package/plugins/huaweicloud-core/src/lib/approval-tokens.ts +19 -4
- package/plugins/huaweicloud-core/src/lib/call-trace.ts +7 -17
- package/plugins/huaweicloud-core/src/lib/confirm-language.ts +51 -0
- package/plugins/huaweicloud-core/src/lib/credentials.ts +9 -8
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkit-gate.ts +1428 -0
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +408 -30
- package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +8 -15
- package/plugins/huaweicloud-core/src/lib/opencode-ask-rule.ts +302 -83
- package/plugins/huaweicloud-core/src/lib/opencode-saved-perms.ts +354 -0
- package/plugins/huaweicloud-core/src/lib/supplemental-redaction.ts +129 -0
- package/plugins/huaweicloud-core/src/lib/tool-schema-parts.ts +40 -0
- package/plugins/huaweicloud-core/src/lib/workspace-glob.ts +414 -0
- package/plugins/huaweicloud-core/src/mcp-config-io.ts +27 -1
- package/plugins/huaweicloud-core/src/mcp-protocol.ts +81 -17
- package/plugins/huaweicloud-core/src/mcp-server.ts +7 -7
- package/plugins/huaweicloud-core/src/mcp-stdio-transport.ts +14 -4
- package/plugins/huaweicloud-core/src/packs/auth/approval.ts +302 -0
- package/plugins/huaweicloud-core/src/packs/auth/tools.ts +54 -45
- package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +99 -137
- package/plugins/huaweicloud-core/src/packs/obs/approval.ts +122 -0
- package/plugins/huaweicloud-core/src/packs/obs/tools.ts +7 -2
- package/plugins/huaweicloud-core/src/packs/registry.ts +43 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +296 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/expose-task.ts +105 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +195 -23
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-credentials.ts +11 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-hwexec.ts +228 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-session.ts +11 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +41 -14
- package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +120 -8
- package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +42 -9
- package/plugins/huaweicloud-core/src/packs/secrets/approval.ts +50 -0
- package/plugins/huaweicloud-core/src/packs/secrets/tools.ts +4 -1
- package/plugins/huaweicloud-core/src/packs/update/approval.ts +87 -0
- package/plugins/huaweicloud-core/src/packs/update/tools.ts +8 -1
- package/plugins/huaweicloud-core/src/packs/voucher/tools.ts +1 -1
- package/plugins/huaweicloud-core/src/packs-configure.ts +75 -0
- package/plugins/huaweicloud-core/src/risk-rule-engine.ts +20 -7
- package/plugins/huaweicloud-core/src/safety/classify-hcloud.ts +28 -16
- package/plugins/huaweicloud-core/src/safety/classify-text.ts +40 -0
- package/plugins/huaweicloud-core/src/safety/policy.ts +7 -0
- package/plugins/huaweicloud-core/src/safety/redact.ts +24 -6
- package/plugins/huaweicloud-core/src/safety/risk-merge.ts +26 -5
- package/plugins/huaweicloud-core/src/sandbox/deploy-check.ts +1 -1
- package/plugins/huaweicloud-core/src/sandbox/devbridge-auth.ts +74 -14
- package/plugins/huaweicloud-core/src/sandbox/devbridge-cleanup.ts +511 -0
- package/plugins/huaweicloud-core/src/sandbox/devbridge-expose-flow.ts +70 -18
- package/plugins/huaweicloud-core/src/sandbox/devbridge-expose.ts +26 -10
- package/plugins/huaweicloud-core/src/sandbox/devbridge-keepalive.ts +41 -2
- package/plugins/huaweicloud-core/src/sandbox/devbridge-key.ts +9 -3
- package/plugins/huaweicloud-core/src/sandbox/devbridge-tunnel.ts +24 -0
- package/plugins/huaweicloud-core/src/sandbox/devbridge-validation.ts +11 -1
- package/plugins/huaweicloud-core/src/sandbox/hwexec-task.ts +304 -0
- package/plugins/huaweicloud-core/src/setup-cli.ts +39 -1
- package/plugins/huaweicloud-core/src/tool-definitions.ts +13 -1
- package/plugins/huaweicloud-core/src/tool-schemas.ts +39 -6
- package/plugins/huaweicloud-core/src/tools.ts +124 -10
- package/plugins/huaweicloud-core/src/update-registry.ts +340 -5
- package/plugins/huaweicloud-core/src/update-upgrade.ts +1130 -14
- package/plugins/huaweicloud-core/src/vendor-gate.ts +2 -2
|
@@ -6,15 +6,17 @@
|
|
|
6
6
|
// src/lib/approval-tokens.ts.
|
|
7
7
|
//
|
|
8
8
|
// The plan's approval posture is mode-dependent (HcloudPlanOptions.
|
|
9
|
-
// approvalMode): 'ask' (DEVKIT_APPROVAL_MODE=ask) plans for the
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// line
|
|
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.
|
|
14
15
|
|
|
15
16
|
import { classifyHcloudArgs, redactSecrets, stripExecutable, type ClassifyOptions } from './safety-policy.ts';
|
|
16
17
|
import { isHcloudToken } from './safety/tokens.ts';
|
|
17
18
|
import { createApprovalToken } from './lib/approval-tokens.ts';
|
|
19
|
+
import { foldSecretTokens, SECRET_KEY_TOKEN_RE, secretSegments } from './lib/supplemental-redaction.ts';
|
|
18
20
|
import type { ApprovalMode } from './lib/approval-mode.ts';
|
|
19
21
|
import type { RiskDecision } from './risk-rule-engine.ts';
|
|
20
22
|
import { obsWriteHint } from './hcloud-obs-redact.ts';
|
|
@@ -30,9 +32,9 @@ import { triageUnknownService } from './hcloud-triage.ts';
|
|
|
30
32
|
// The plan's terminal-confirmation block: `needed` says the command waits
|
|
31
33
|
// on a confirmation the user makes in their own terminal, `command` is the
|
|
32
34
|
// exact line they run (present only on plans that minted a token). Ask
|
|
33
|
-
// mode shifts the confirmation onto the
|
|
34
|
-
//
|
|
35
|
-
// satisfies it — no `command` exists to name.
|
|
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.
|
|
36
38
|
export interface HcloudPlanUserConfirmation {
|
|
37
39
|
needed: boolean;
|
|
38
40
|
command?: string;
|
|
@@ -88,13 +90,36 @@ export function needsUserConfirmation(args: string[], options: ClassifyOptions =
|
|
|
88
90
|
return strict.decision === 'deny' && (strict.risk === 'write' || strict.risk === 'execution');
|
|
89
91
|
}
|
|
90
92
|
|
|
91
|
-
function quoteShellArg(value: unknown): string {
|
|
93
|
+
export function quoteShellArg(value: unknown): string {
|
|
92
94
|
const text = String(value);
|
|
93
95
|
if (!text) return '""';
|
|
94
96
|
if (/^[A-Za-z0-9_./:=@-]+$/.test(text)) return text;
|
|
95
97
|
return `"${text.replace(/(["\\])/g, '\\$1')}"`;
|
|
96
98
|
}
|
|
97
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
|
+
|
|
98
123
|
function planningWarnings(args: string[]): string[] {
|
|
99
124
|
const joined = args.join(' ');
|
|
100
125
|
const warnings: string[] = [];
|
|
@@ -201,33 +226,14 @@ function leadingBinWarning(stripped: string): string {
|
|
|
201
226
|
// pinning message no longer claims a reason. Free-form JSON bodies with
|
|
202
227
|
// real secrets should go through plan→approve with literal values (hash
|
|
203
228
|
// path), not the substitution flow.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
//
|
|
209
|
-
|
|
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.
|
|
210
235
|
const PLACEHOLDER_SECRET_VALUE_RE = /^["']?<{1,2}[A-Za-z0-9_ -]{1,40}>{1,2}["']?/;
|
|
211
236
|
|
|
212
|
-
// Shared key+separator scanner (loop round 8): ONE global split drives every
|
|
213
|
-
// consumer. The value segment of a key runs to the NEXT key occurrence — a
|
|
214
|
-
// multi-key body (`{"token":"<x>","password":"Real"}`) yields one segment
|
|
215
|
-
// per key, so a mixed placeholder/real body can no longer hide a real value
|
|
216
|
-
// behind a lazy first match (loop round 7, seat-1 B1).
|
|
217
|
-
const SECRET_KEY_SEP_RE = new RegExp(
|
|
218
|
-
'((?:(?:' + SECRET_KEY_ALT + ')|\\b(?:AK|SK))["\'\\\\]*\\s*(?:[=:]|\\s|(?=["\']))\\s*)',
|
|
219
|
-
'gi',
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
function secretSegments(arg: string): Array<{ sep: string; value: string }> {
|
|
223
|
-
const parts = String(arg).split(SECRET_KEY_SEP_RE);
|
|
224
|
-
const segments: Array<{ sep: string; value: string }> = [];
|
|
225
|
-
for (let i = 1; i < parts.length; i += 2) {
|
|
226
|
-
segments.push({ sep: parts[i] ?? '', value: parts[i + 1] ?? '' });
|
|
227
|
-
}
|
|
228
|
-
return segments;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
237
|
function placeholderShaped(value: string): boolean {
|
|
232
238
|
return PLACEHOLDER_SECRET_VALUE_RE.test(value.trim());
|
|
233
239
|
}
|
|
@@ -283,34 +289,12 @@ export function firstPlaceholderSecretArg(args: string[]): string | null {
|
|
|
283
289
|
// the map-only version dropped the two-token branch and let cross-form
|
|
284
290
|
// swaps through). The redactor's own output cannot serve here — it never
|
|
285
291
|
// folds the two-token/glued forms, so the substitution flow dead-ended in
|
|
286
|
-
// 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.
|
|
287
296
|
export function pinViewArgs(args: string[]): string[] {
|
|
288
|
-
|
|
289
|
-
for (let i = 0; i < args.length; i += 1) {
|
|
290
|
-
const arg = String(args[i]);
|
|
291
|
-
const segments = secretSegments(arg);
|
|
292
|
-
if (segments.length > 0) {
|
|
293
|
-
const parts = String(arg).split(SECRET_KEY_SEP_RE);
|
|
294
|
-
let folded = parts[0] ?? '';
|
|
295
|
-
for (let j = 1; j < parts.length; j += 2) {
|
|
296
|
-
folded += parts[j] + '<redacted>';
|
|
297
|
-
}
|
|
298
|
-
out.push(folded);
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
const next = i + 1 < args.length ? String(args[i + 1]) : undefined;
|
|
302
|
-
if (SECRET_KEY_TOKEN_RE.test(arg) && next !== undefined && !SECRET_KEY_TOKEN_RE.test(next)) {
|
|
303
|
-
// Bare key token with its value riding the next argv element — fold
|
|
304
|
-
// the value, keep the key. A CHAINED bare key (`--password --token x`)
|
|
305
|
-
// is left for its own iteration so no real value hides behind the
|
|
306
|
-
// skip (loop round 7, seat-1 residual).
|
|
307
|
-
out.push(arg, '<redacted>');
|
|
308
|
-
i += 1;
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
311
|
-
out.push(arg);
|
|
312
|
-
}
|
|
313
|
-
return out;
|
|
297
|
+
return foldSecretTokens(args) as string[];
|
|
314
298
|
}
|
|
315
299
|
|
|
316
300
|
function validateRequiredParams(args: string[]): { valid: boolean; missing: string[]; hints: string[] } {
|
|
@@ -328,7 +312,20 @@ export function planHcloudCommand(args: unknown, options: HcloudPlanOptions = {}
|
|
|
328
312
|
const inputArgs = Array.isArray(args) ? args.map(String) : [];
|
|
329
313
|
const { args: normalizedArgs, stripped } = stripLeadingHcloudBinArgs(inputArgs);
|
|
330
314
|
const classification = classifyHcloudArgs(normalizedArgs, options);
|
|
331
|
-
|
|
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
|
+
);
|
|
332
329
|
const warnings: Array<string | SgFinding> = planningWarnings(normalizedArgs);
|
|
333
330
|
if (stripped !== null) warnings.unshift(leadingBinWarning(stripped));
|
|
334
331
|
const obsHint = obsWriteHint(normalizedArgs);
|
|
@@ -369,10 +366,10 @@ export function planHcloudCommand(args: unknown, options: HcloudPlanOptions = {}
|
|
|
369
366
|
}
|
|
370
367
|
}
|
|
371
368
|
const approvalMode = options.approvalMode ?? 'token';
|
|
372
|
-
// Ask mode never mints: the confirmation is the
|
|
373
|
-
//
|
|
374
|
-
//
|
|
375
|
-
//
|
|
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.
|
|
376
373
|
const approvalToken =
|
|
377
374
|
approvalMode === 'ask' || options.mintApprovalToken === false
|
|
378
375
|
? undefined
|
|
@@ -387,9 +384,10 @@ export function planHcloudCommand(args: unknown, options: HcloudPlanOptions = {}
|
|
|
387
384
|
// The plan echo is a COMMAND string, not child-process output — banner
|
|
388
385
|
// stripping is an output concern, and an argument VALUE that happens to
|
|
389
386
|
// carry banner-shaped text must never blank the command the user is asked
|
|
390
|
-
// to approve (
|
|
391
|
-
|
|
392
|
-
|
|
387
|
+
// to approve (redaction only, already applied per arg above so the
|
|
388
|
+
// quoting stays balanced).
|
|
389
|
+
command,
|
|
390
|
+
executableBlock: command,
|
|
393
391
|
warnings,
|
|
394
392
|
classification: applyPreflightFindings(effectiveClassification, sgFindings),
|
|
395
393
|
sgFindings,
|
|
@@ -403,13 +401,18 @@ export function planHcloudCommand(args: unknown, options: HcloudPlanOptions = {}
|
|
|
403
401
|
? {
|
|
404
402
|
needed: true,
|
|
405
403
|
mode: 'ask',
|
|
406
|
-
note: 'The
|
|
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.',
|
|
407
405
|
}
|
|
408
406
|
: {
|
|
409
407
|
needed: true,
|
|
410
408
|
...(approvalToken !== undefined ? { command: `npx huaweicloud-devkit approve ${approvalToken}` } : {}),
|
|
411
409
|
}
|
|
412
410
|
: { needed: false },
|
|
413
|
-
|
|
411
|
+
// "Safe to run NOW": a caller-supplied allowWrites:true only unlocks the
|
|
412
|
+
// classification — the strict view still demands the user's confirmation
|
|
413
|
+
// (the approval token/form), so a plan showing decision:"allow" must not
|
|
414
|
+
// also read as runnable while userConfirmation.needed is true (AX D-02
|
|
415
|
+
// display-layer alignment).
|
|
416
|
+
safeToRun: effectiveClassification.decision === 'allow' && !needsConfirmation,
|
|
414
417
|
};
|
|
415
418
|
}
|
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
// an approval token, the user confirms it in their own terminal
|
|
5
5
|
// (`npx huaweicloud-devkit approve <uuid>`), and run_approved_command
|
|
6
6
|
// consumes the token before executing. 'ask' moves the confirmation onto
|
|
7
|
-
// the
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
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.
|
|
12
14
|
//
|
|
13
15
|
// Resolution is exact-match and fail-loud, mirroring the DEVKIT_PACKS
|
|
14
16
|
// unknown-id doctrine: a typo'd mode must not silently fall back to the
|
|
@@ -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
|
-
|
|
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
|
|
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
|
|
62
|
-
|
|
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
|
|
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
|
-
|
|
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
|
}
|