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
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { fingerprint } from '../../auth/reconcile.ts';
|
|
2
|
+
import { readCodeArtsCredentials } from '../../auth/credentials.ts';
|
|
3
|
+
import { peekImportFile } from '../../lib/credentials.ts';
|
|
4
|
+
import { resolveSecretValue } from '../../lib/secret-vault/store.ts';
|
|
5
|
+
import { hashArgs } from '../../lib/approval-tokens.ts';
|
|
6
|
+
import type { ApprovalSpec } from '../../approval-types.ts';
|
|
7
|
+
import type { ToolArgs } from '../../tools.ts';
|
|
8
|
+
|
|
9
|
+
// The auth pack's approval registration (PR-3b): the account-switch pair.
|
|
10
|
+
// The account switch is the one step that can redirect every downstream
|
|
11
|
+
// approved write to a different account, so both faces join the roster as
|
|
12
|
+
// always-gated — the vendor gate in front asserts the vendor (the quote),
|
|
13
|
+
// this gate asserts the human (the confirmation). auth_confirm stays OFF
|
|
14
|
+
// this table per the parked decision: its pendingConfirms flow is the
|
|
15
|
+
// persist-conflict reconciliation's own confirmation, and gating it would
|
|
16
|
+
// ask the same human twice about the same switch (the double-ask on a
|
|
17
|
+
// persist conflict is the recorded known transient, not a defect to
|
|
18
|
+
// collapse here). auth_sync, auth_status, and check_account_type stay
|
|
19
|
+
// unregistered — read or operator-configured faces.
|
|
20
|
+
//
|
|
21
|
+
// The binding value is the call's RESOLVED CREDENTIAL SNAPSHOT with the
|
|
22
|
+
// consent plumbing (vendorConfirmed, approvalToken, approvedByUser,
|
|
23
|
+
// command) normalized away. Resolution mirrors the handler's channel
|
|
24
|
+
// precedence exactly — the args pair wins when present, else the mode's
|
|
25
|
+
// backing store (the import file for mode=import, the CodeArts injection
|
|
26
|
+
// for mode=mcp-config), with secret:// refs resolved — and the backing
|
|
27
|
+
// store is PEEKED, never read-for-wipe: the gate runs before any consent,
|
|
28
|
+
// so a read with a side effect (the malformed-file wipe) would mutate the
|
|
29
|
+
// user's state on the refusal path. The handler EXECUTES this snapshot
|
|
30
|
+
// (threaded through dispatch as opts.approvedBinding), never a
|
|
31
|
+
// post-consent re-read — interrogate round 1, finding 2: the account the
|
|
32
|
+
// confirmation view named is the account that switches, and a rewrite of
|
|
33
|
+
// the import file between the shown form and the accept lands nowhere.
|
|
34
|
+
// Folding the resolved region and security token into the BINDING (not
|
|
35
|
+
// just the display) extends the same doctrine to the full effect: a
|
|
36
|
+
// same-fingerprint call with a different region or STS re-asks instead
|
|
37
|
+
// of executing under the old approval (round 1, finding 3).
|
|
38
|
+
//
|
|
39
|
+
// The cost of a resolved binding: the post-dispatch outcome recorder
|
|
40
|
+
// re-derives it AFTER the handler wiped a consumed import file, so its
|
|
41
|
+
// argsHash can miss the arrival row — the annotate is best-effort by
|
|
42
|
+
// contract and a missing outcome line is the documented consequence.
|
|
43
|
+
|
|
44
|
+
function asStr(value: unknown): string {
|
|
45
|
+
return typeof value === 'string' ? value : '';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function resolved(value: string): string {
|
|
49
|
+
return resolveSecretValue(value) ?? value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Shape guard for the dispatch-threaded snapshot: it comes from our own
|
|
53
|
+
// gate, but the narrow keeps the handler's fallback honest against any
|
|
54
|
+
// future binding-shape change.
|
|
55
|
+
export function isApprovedSwitchSnapshot(value: unknown): value is ApprovedSwitchSnapshot {
|
|
56
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
57
|
+
const v = value as Record<string, unknown>;
|
|
58
|
+
return (
|
|
59
|
+
typeof v.mode === 'string' &&
|
|
60
|
+
typeof v.action === 'string' &&
|
|
61
|
+
typeof v.ak === 'string' &&
|
|
62
|
+
typeof v.sk === 'string' &&
|
|
63
|
+
typeof v.securityToken === 'string' &&
|
|
64
|
+
typeof v.region === 'string' &&
|
|
65
|
+
typeof v.account === 'string' &&
|
|
66
|
+
typeof v.fromImport === 'boolean'
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The resolved credential record the switch handler executes, and the ONE
|
|
71
|
+
// place the resolution precedence lives (the gate's normalizeArgs and the
|
|
72
|
+
// handler's no-binding fallback both call this). Shape-guards in the
|
|
73
|
+
// handler (isApprovedSwitchSnapshot) keep the threading an in-process
|
|
74
|
+
// contract: it comes from our own gate, but the narrow costs nothing.
|
|
75
|
+
export interface ApprovedSwitchSnapshot {
|
|
76
|
+
mode: string;
|
|
77
|
+
action: string;
|
|
78
|
+
ak: string;
|
|
79
|
+
sk: string;
|
|
80
|
+
securityToken: string;
|
|
81
|
+
region: string;
|
|
82
|
+
// The 8-hex fingerprint of the resolved account (display + pin view).
|
|
83
|
+
account: string;
|
|
84
|
+
// True when the import file supplied the values (the handler wipes it on
|
|
85
|
+
// non-replayable outcomes, exactly as its own read did).
|
|
86
|
+
fromImport: boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Resolve the switch substance with the handler's own precedence: the args
|
|
90
|
+
// pair wins when present, else the mode's backing store (full replace for
|
|
91
|
+
// the import channel; the CodeArts channel defaults region from the
|
|
92
|
+
// injection and falls back to the args). Refs resolve to plaintext, the
|
|
93
|
+
// same seam the handler resolved through.
|
|
94
|
+
export function switchSnapshot(args: ToolArgs): ApprovedSwitchSnapshot {
|
|
95
|
+
const mode = args.mode || 'memory';
|
|
96
|
+
const action = args.action || 'temporary';
|
|
97
|
+
if (action === 'clear') {
|
|
98
|
+
return { mode, action: 'clear', ak: '', sk: '', securityToken: '', region: '', account: '', fromImport: false };
|
|
99
|
+
}
|
|
100
|
+
let ak = asStr(args.ak);
|
|
101
|
+
let sk = asStr(args.sk);
|
|
102
|
+
let securityToken = asStr(args.securityToken);
|
|
103
|
+
let region = asStr(args.region);
|
|
104
|
+
let fromImport = false;
|
|
105
|
+
if (mode === 'import' && (!ak || !sk)) {
|
|
106
|
+
const imported = peekImportFile();
|
|
107
|
+
if (imported) {
|
|
108
|
+
({ ak, sk, securityToken, region } = imported);
|
|
109
|
+
fromImport = true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (mode === 'mcp-config' && (!ak || !sk)) {
|
|
113
|
+
const cc = readCodeArtsCredentials();
|
|
114
|
+
if (cc) {
|
|
115
|
+
ak = cc.ak;
|
|
116
|
+
sk = cc.sk;
|
|
117
|
+
securityToken = cc.securityToken || '';
|
|
118
|
+
region = cc.region || region;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const akValue = resolved(ak);
|
|
122
|
+
const skValue = resolved(sk);
|
|
123
|
+
const securityTokenValue = resolved(securityToken);
|
|
124
|
+
return {
|
|
125
|
+
mode,
|
|
126
|
+
action,
|
|
127
|
+
ak: akValue,
|
|
128
|
+
sk: skValue,
|
|
129
|
+
securityToken: securityTokenValue,
|
|
130
|
+
region,
|
|
131
|
+
account: fingerprint(akValue, skValue),
|
|
132
|
+
fromImport,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Resolve the init substance with the SAME seam the switch snapshot uses
|
|
137
|
+
// (round 2, the twin path): the args may carry secret:// refs, and the
|
|
138
|
+
// binding must hash and name the RESOLVED account — the fingerprint of the
|
|
139
|
+
// ref strings is the fingerprint of nothing. Resolution at snapshot time
|
|
140
|
+
// also refuses the doomed shape pre-mint (an unresolvable ref throws
|
|
141
|
+
// VaultError at the gate, before any consent surface or token store
|
|
142
|
+
// write), and makes a vault swap behind the same refs change the binding
|
|
143
|
+
// hash, so a confirmed retry re-asks instead of executing an unseen
|
|
144
|
+
// account.
|
|
145
|
+
function initSnapshot(args: ToolArgs): Record<string, unknown> {
|
|
146
|
+
if (args.clear) return { clear: true };
|
|
147
|
+
const ak = resolved(asStr(args.ak));
|
|
148
|
+
const sk = resolved(asStr(args.sk));
|
|
149
|
+
const region = resolved(asStr(args.region));
|
|
150
|
+
return {
|
|
151
|
+
ak,
|
|
152
|
+
sk,
|
|
153
|
+
...(region ? { region } : {}),
|
|
154
|
+
account: fingerprint(ak, sk),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Shape guard for the init twin's dispatched snapshot: ak/sk/account are
|
|
159
|
+
// strings (the resolved values), and the switch snapshot's channel keys
|
|
160
|
+
// are absent — the two bindings never cross.
|
|
161
|
+
export interface ApprovedInitSnapshot {
|
|
162
|
+
ak: string;
|
|
163
|
+
sk: string;
|
|
164
|
+
region?: string;
|
|
165
|
+
account: string;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function isApprovedInitSnapshot(value: unknown): value is ApprovedInitSnapshot {
|
|
169
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
170
|
+
const v = value as Record<string, unknown>;
|
|
171
|
+
return (
|
|
172
|
+
typeof v.ak === 'string' &&
|
|
173
|
+
typeof v.sk === 'string' &&
|
|
174
|
+
typeof v.account === 'string' &&
|
|
175
|
+
!('mode' in v) &&
|
|
176
|
+
!('fromImport' in v)
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const SOURCE_LABELS: Record<string, string> = {
|
|
181
|
+
memory: 'session arguments',
|
|
182
|
+
import: 'the devkit credentials import file (creds-import.json)',
|
|
183
|
+
'mcp-config': 'the CodeArts mcp_settings.json injection',
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const SCOPE_LABELS: Record<string, string> = {
|
|
187
|
+
persist: 'persist: S1 + KooCLI profile + OBS mirrors',
|
|
188
|
+
temporary: 'temporary: this MCP process only',
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
function switchView(binding: ApprovedSwitchSnapshot) {
|
|
192
|
+
if (binding.action === 'clear') {
|
|
193
|
+
return {
|
|
194
|
+
summary: "huaweicloud_auth_switch: clear this session's runtime credentials (fall back to env/file/S1)",
|
|
195
|
+
argsHash: hashArgs(binding),
|
|
196
|
+
pinView: { action: 'clear' },
|
|
197
|
+
command: "huaweicloud_auth_switch (clear the session's runtime credentials)",
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const account = binding.account || '(unknown)';
|
|
201
|
+
const source = SOURCE_LABELS[binding.mode] ?? binding.mode;
|
|
202
|
+
const scope = SCOPE_LABELS[binding.action] ?? binding.action;
|
|
203
|
+
const regionNote = binding.region ? `, region ${binding.region}` : '';
|
|
204
|
+
const stsNote = binding.securityToken ? ', session-scoped STS' : '';
|
|
205
|
+
return {
|
|
206
|
+
summary: `huaweicloud_auth_switch: switch to account ${account} from ${source}${regionNote}${stsNote} (${scope})`,
|
|
207
|
+
argsHash: hashArgs(binding),
|
|
208
|
+
pinView: {
|
|
209
|
+
account,
|
|
210
|
+
source: binding.mode,
|
|
211
|
+
scope: binding.action,
|
|
212
|
+
...(binding.region ? { region: binding.region } : {}),
|
|
213
|
+
...(binding.securityToken ? { sts: true } : {}),
|
|
214
|
+
},
|
|
215
|
+
command: `huaweicloud_auth_switch (switch the account to ${account}, source ${binding.mode}${regionNote}${stsNote}, ${binding.action})`,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export const AUTH_APPROVAL_SPECS: Readonly<Record<'huaweicloud_auth_init' | 'huaweicloud_auth_switch', ApprovalSpec>> =
|
|
220
|
+
{
|
|
221
|
+
huaweicloud_auth_init: {
|
|
222
|
+
domain: 'auth',
|
|
223
|
+
flavor: 'always',
|
|
224
|
+
tokenSource: 'gate',
|
|
225
|
+
normalizeArgs: initSnapshot,
|
|
226
|
+
// NoDoomedToken (round 1, finding 4): the handler refuses a set call
|
|
227
|
+
// with no credential pair, so the gate refuses it before any mint —
|
|
228
|
+
// the user is never asked to approve a call the execution would
|
|
229
|
+
// reject.
|
|
230
|
+
assertArgsExecutable: (bindingValue) => {
|
|
231
|
+
const binding = (bindingValue ?? {}) as Record<string, unknown>;
|
|
232
|
+
if (binding.clear) return;
|
|
233
|
+
if (
|
|
234
|
+
typeof binding.ak !== 'string' ||
|
|
235
|
+
binding.ak === '' ||
|
|
236
|
+
typeof binding.sk !== 'string' ||
|
|
237
|
+
binding.sk === ''
|
|
238
|
+
) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
'ak and sk are required to set runtime credentials (secret:// vault refs are accepted). ' +
|
|
241
|
+
'Pass clear=true to clear the session\u2019s runtime credentials instead.',
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
summarize: (bindingValue) => {
|
|
246
|
+
const binding = (bindingValue ?? {}) as Record<string, unknown>;
|
|
247
|
+
if (binding.clear) {
|
|
248
|
+
return {
|
|
249
|
+
summary: "huaweicloud_auth_init: clear this session's runtime credentials (fall back to env/file)",
|
|
250
|
+
argsHash: hashArgs(binding),
|
|
251
|
+
pinView: { clear: true },
|
|
252
|
+
command: "huaweicloud_auth_init (clear the session's runtime credentials)",
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const account = asStr(binding.account) || '(unknown)';
|
|
256
|
+
const region = asStr(binding.region);
|
|
257
|
+
return {
|
|
258
|
+
summary:
|
|
259
|
+
`huaweicloud_auth_init: switch this session's runtime credentials to account ${account}` +
|
|
260
|
+
`${region ? ` (region ${region})` : ''} (source: session arguments)`,
|
|
261
|
+
argsHash: hashArgs(binding),
|
|
262
|
+
pinView: { account, ...(region ? { region } : {}) },
|
|
263
|
+
command: `huaweicloud_auth_init (switch the session's runtime credentials to account ${account})`,
|
|
264
|
+
};
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
huaweicloud_auth_switch: {
|
|
268
|
+
domain: 'auth',
|
|
269
|
+
flavor: 'always',
|
|
270
|
+
tokenSource: 'gate',
|
|
271
|
+
normalizeArgs: switchSnapshot,
|
|
272
|
+
// NoDoomedToken (round 1, finding 4): no mint for a switch with no
|
|
273
|
+
// resolvable target account (an absent or malformed import file, an
|
|
274
|
+
// empty injection), and no mint for a persist shape the handler
|
|
275
|
+
// rejects anyway — a regionless persist (invalid_region, round 2's
|
|
276
|
+
// close of the recorded residual) or an STS persist (R3).
|
|
277
|
+
assertArgsExecutable: (bindingValue) => {
|
|
278
|
+
const binding = bindingValue as ApprovedSwitchSnapshot;
|
|
279
|
+
if (binding.action === 'clear') return;
|
|
280
|
+
if (
|
|
281
|
+
typeof binding.ak !== 'string' ||
|
|
282
|
+
binding.ak === '' ||
|
|
283
|
+
typeof binding.sk !== 'string' ||
|
|
284
|
+
binding.sk === ''
|
|
285
|
+
) {
|
|
286
|
+
throw new Error(
|
|
287
|
+
'the account switch has no resolvable target account: pass ak/sk (mode=memory), ' +
|
|
288
|
+
'a valid creds-import.json (mode=import), or an injected mcp_settings.json (mode=mcp-config).',
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
if (binding.action === 'persist' && !binding.region.trim()) {
|
|
292
|
+
throw new Error(
|
|
293
|
+
'region is required to persist credentials. Pass --region, or include "region" in creds-import.json (mode=import).',
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
if (binding.action === 'persist' && binding.securityToken !== '') {
|
|
297
|
+
throw new Error('Temporary STS credentials cannot be persisted (R3). Use action=temporary.');
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
summarize: (bindingValue) => switchView(bindingValue as ApprovedSwitchSnapshot),
|
|
301
|
+
},
|
|
302
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
import { vendorConfirmed } from '../../lib/tool-schema-parts.ts';
|
|
3
|
+
import { approvalTokenArg, approvedByUserArg, vendorConfirmed } from '../../lib/tool-schema-parts.ts';
|
|
4
4
|
import { getAuthStatus, syncAuth } from '../../auth/service.ts';
|
|
5
5
|
import { checkAccountType } from '../../auth/account-type.ts';
|
|
6
6
|
import {
|
|
@@ -13,13 +13,18 @@ import {
|
|
|
13
13
|
import { fingerprint } from '../../auth/reconcile.ts';
|
|
14
14
|
import {
|
|
15
15
|
persistCredentials,
|
|
16
|
-
readImportFile,
|
|
17
16
|
clearImportFile,
|
|
18
17
|
pendingConfirms,
|
|
19
18
|
consumedConfirms,
|
|
20
19
|
refreshUserHashAfterAuthChange,
|
|
21
20
|
} from '../../lib/credentials.ts';
|
|
22
21
|
import { resolveSecretValue } from '../../lib/secret-vault/store.ts';
|
|
22
|
+
import {
|
|
23
|
+
isApprovedInitSnapshot,
|
|
24
|
+
isApprovedSwitchSnapshot,
|
|
25
|
+
switchSnapshot,
|
|
26
|
+
type ApprovedSwitchSnapshot,
|
|
27
|
+
} from './approval.ts';
|
|
23
28
|
import type { PackToolDefinition, LooseToolSchema } from '../../lib/pack-types.ts';
|
|
24
29
|
import type { CallToolOptions, ToolArgs } from '../../tools.ts';
|
|
25
30
|
|
|
@@ -36,7 +41,7 @@ async function handleAuthSync(args: ToolArgs = {}, _opts: CallToolOptions = {})
|
|
|
36
41
|
return result;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
async function handleAuthInit(args: ToolArgs = {},
|
|
44
|
+
async function handleAuthInit(args: ToolArgs = {}, opts: CallToolOptions = {}) {
|
|
40
45
|
if (args.clear) {
|
|
41
46
|
clearRuntimeCredentials();
|
|
42
47
|
refreshUserHashAfterAuthChange({ regenerate: false });
|
|
@@ -48,16 +53,21 @@ async function handleAuthInit(args: ToolArgs = {}, _opts: CallToolOptions = {})
|
|
|
48
53
|
// Incoming values may be secret:// refs. Resolve them so the runtime store
|
|
49
54
|
// carries usable credentials (same contract as auth_switch and the CLI's
|
|
50
55
|
// auth init); an unresolvable ref throws VaultError with its own
|
|
51
|
-
// remediation.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
// remediation. When the gate threaded its approved snapshot (round 2,
|
|
57
|
+
// the twin path), the handler executes the RESOLVED VALUES the
|
|
58
|
+
// confirmation surface was shown against — a vault swap behind the same
|
|
59
|
+
// refs cannot execute an account that appeared on no surface. Without a
|
|
60
|
+
// matching snapshot (a direct handler call), the trunk resolution runs.
|
|
61
|
+
const approved = isApprovedInitSnapshot(opts.approvedBinding) ? opts.approvedBinding : null;
|
|
62
|
+
const ak = approved ? approved.ak : (resolveSecretValue(args.ak) ?? args.ak);
|
|
63
|
+
const sk = approved ? approved.sk : (resolveSecretValue(args.sk) ?? args.sk);
|
|
64
|
+
const region = approved ? approved.region : (resolveSecretValue(args.region) ?? args.region);
|
|
55
65
|
setRuntimeCredentials(ak, sk, undefined, region);
|
|
56
66
|
refreshUserHashAfterAuthChange();
|
|
57
67
|
return { status: 'ok', message: 'Runtime credentials set for this MCP session.' };
|
|
58
68
|
}
|
|
59
69
|
|
|
60
|
-
async function handleAuthSwitch(args: ToolArgs = {},
|
|
70
|
+
async function handleAuthSwitch(args: ToolArgs = {}, opts: CallToolOptions = {}) {
|
|
61
71
|
const action = args.action || 'temporary';
|
|
62
72
|
if (action === 'clear') {
|
|
63
73
|
clearRuntimeCredentials();
|
|
@@ -65,38 +75,24 @@ async function handleAuthSwitch(args: ToolArgs = {}, _opts: CallToolOptions = {}
|
|
|
65
75
|
return { status: 'cleared', message: 'Runtime credentials cleared. Fallback to env/file/S1.' };
|
|
66
76
|
}
|
|
67
77
|
|
|
68
|
-
let ak = args.ak || '';
|
|
69
|
-
let sk = args.sk || '';
|
|
70
|
-
let securityToken = args.securityToken || '';
|
|
71
|
-
let region = args.region || '';
|
|
72
78
|
const sourceChannel = args.mode || 'memory';
|
|
73
|
-
let importedFromFile = false;
|
|
74
79
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// Incoming values may be secret:// refs (mode=memory with refs, or an
|
|
93
|
-
// import file carrying them). Resolve before any comparison or fan-out:
|
|
94
|
-
// the conflict check and displayed fingerprints must compare plaintext,
|
|
95
|
-
// and persistCredentials' mirrors must never see a literal ref string.
|
|
96
|
-
// An unresolvable ref throws VaultError with its own remediation.
|
|
97
|
-
ak = resolveSecretValue(ak) ?? ak;
|
|
98
|
-
sk = resolveSecretValue(sk) ?? sk;
|
|
99
|
-
securityToken = resolveSecretValue(securityToken) ?? securityToken;
|
|
80
|
+
// The gate's approved snapshot (interrogate round 1, finding 2): the
|
|
81
|
+
// resolved credential substance from BEFORE the confirmation surface was
|
|
82
|
+
// shown, threaded through dispatch when the call passed the gate.
|
|
83
|
+
// Executing THIS record — never a post-consent re-read of the import
|
|
84
|
+
// file or the CodeArts injection — is what makes the shown account the
|
|
85
|
+
// executed account. Without a matching snapshot (a direct handler call,
|
|
86
|
+
// no dispatch gate in front), the same resolution runs inline through
|
|
87
|
+
// the spec's own snapshot function — one precedence, one seam.
|
|
88
|
+
const approved = isApprovedSwitchSnapshot(opts.approvedBinding)
|
|
89
|
+
? opts.approvedBinding.mode === sourceChannel && opts.approvedBinding.action === action
|
|
90
|
+
? opts.approvedBinding
|
|
91
|
+
: null
|
|
92
|
+
: null;
|
|
93
|
+
const resolved: ApprovedSwitchSnapshot = approved ?? switchSnapshot(args);
|
|
94
|
+
const { ak, sk, securityToken, region } = resolved;
|
|
95
|
+
const importedFromFile = resolved.fromImport;
|
|
100
96
|
|
|
101
97
|
if (!ak || !sk) {
|
|
102
98
|
throw new Error('ak and sk are required (or provide creds-import.json for mode=import).');
|
|
@@ -225,21 +221,34 @@ const authInitSchema = z.looseObject({
|
|
|
225
221
|
sk: z.string().optional().describe('Huawei Cloud Secret Key (required unless clear=true)'),
|
|
226
222
|
region: z.string().optional().describe('Default region (optional)'),
|
|
227
223
|
clear: z.boolean().optional().describe('Set to true to clear runtime credentials and revert to env/file'),
|
|
224
|
+
approvalToken: approvalTokenArg.describe(
|
|
225
|
+
'Required in token-approval mode (from the USER_CONFIRMATION_REQUIRED envelope this gate returns); omit in ask mode, where the server-run gate confirms at run time.',
|
|
226
|
+
),
|
|
227
|
+
approvedByUser: approvedByUserArg,
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
const authSwitchSchema = z.looseObject({
|
|
231
231
|
vendorConfirmed,
|
|
232
232
|
mode: z.enum(['import', 'memory', 'mcp-config']).optional().describe('Credential source channel'),
|
|
233
233
|
action: z.enum(['persist', 'temporary', 'clear']).optional().describe('Apply scope'),
|
|
234
|
-
ak: z.string().optional(),
|
|
235
|
-
sk: z.string().optional(),
|
|
236
|
-
securityToken: z.string().optional(),
|
|
237
|
-
region: z.string().optional(),
|
|
234
|
+
ak: z.string().optional().describe('Huawei Cloud Access Key to switch this session to.'),
|
|
235
|
+
sk: z.string().optional().describe('Huawei Cloud Secret Key to switch this session to.'),
|
|
236
|
+
securityToken: z.string().optional().describe('Security (STS) token when the new credentials are session-scoped.'),
|
|
237
|
+
region: z.string().optional().describe('Optional default region applied with the switched credentials.'),
|
|
238
|
+
approvalToken: approvalTokenArg.describe(
|
|
239
|
+
'Required in token-approval mode (from the USER_CONFIRMATION_REQUIRED envelope this gate returns); omit in ask mode, where the server-run gate confirms at run time.',
|
|
240
|
+
),
|
|
241
|
+
approvedByUser: approvedByUserArg,
|
|
238
242
|
});
|
|
239
243
|
|
|
240
244
|
const authConfirmSchema = z.looseObject({
|
|
241
245
|
token: z.string().optional().describe('confirmation token from the needs_confirmation response'),
|
|
242
|
-
decision: z
|
|
246
|
+
decision: z
|
|
247
|
+
.enum(['s1', 'newImported'])
|
|
248
|
+
.optional()
|
|
249
|
+
.describe(
|
|
250
|
+
'Reconciliation choice: s1 keeps the existing S1 vault credentials; newImported adopts the newly imported ones.',
|
|
251
|
+
),
|
|
243
252
|
});
|
|
244
253
|
|
|
245
254
|
async function handleCheckAccountType(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
|
|
@@ -273,14 +282,14 @@ export const AUTH_TOOLS = [
|
|
|
273
282
|
{
|
|
274
283
|
name: 'huaweicloud_auth_init',
|
|
275
284
|
description:
|
|
276
|
-
'Set or clear runtime Huawei Cloud credentials (AK/SK) for this MCP session. Runtime credentials take highest priority over environment variables and config files for all subsequent API calls. Use when switching accounts within the same Agent session — call with AK/SK to switch, or with clear=true to fall back to env/file credentials. Vendor-gated (vendorConfirmed): call only when the vendor is established — see the vendorConfirmed parameter description; when unknown, ask which cloud the user means first.',
|
|
285
|
+
'Set or clear runtime Huawei Cloud credentials (AK/SK) for this MCP session. Runtime credentials take highest priority over environment variables and config files for all subsequent API calls. Use when switching accounts within the same Agent session — call with AK/SK to switch, or with clear=true to fall back to env/file credentials. Approval-gated: the account switch requires the user\u2019s explicit confirmation, and the confirmation view names the target account fingerprint — in the default token mode the first call returns USER_CONFIRMATION_REQUIRED with an approvalToken the user confirms in their own terminal (npx huaweicloud-devkit approve <token>); under DEVKIT_APPROVAL_MODE=ask the server raises the confirmation itself (an elicitation form, or the ASK_CONFIRMATION_REQUIRED chat round-trip). Vendor-gated (vendorConfirmed): call only when the vendor is established — see the vendorConfirmed parameter description; when unknown, ask which cloud the user means first.',
|
|
277
286
|
schema: authInitSchema,
|
|
278
287
|
handler: handleAuthInit,
|
|
279
288
|
},
|
|
280
289
|
{
|
|
281
290
|
name: 'huaweicloud_auth_switch',
|
|
282
291
|
description:
|
|
283
|
-
'Switch Huawei Cloud credentials within the current session. action=temporary keeps AK/SK in memory only (restart loses them; hcloud commands are unaffected and an A+C warning will be raised). action=persist writes S1 (single source of truth) with configuredBySession flag and propagates to S2 (KooCLI current profile) and S3 (OBS). action=clear resets runtime credentials. mode=import reads AK/SK from ~/.config/huaweicloud/creds-import.json then wipes it (SK never enters conversation). mode=memory passes AK/SK as tool arguments (SK is visible to model - prefer import). mode=mcp-config reads the injected mcp_settings environment. Vendor-gated (vendorConfirmed): call only when the vendor is established — see the vendorConfirmed parameter description; when unknown, ask which cloud the user means first.',
|
|
292
|
+
'Switch Huawei Cloud credentials within the current session. action=temporary keeps AK/SK in memory only (restart loses them; hcloud commands are unaffected and an A+C warning will be raised). action=persist writes S1 (single source of truth) with configuredBySession flag and propagates to S2 (KooCLI current profile) and S3 (OBS). action=clear resets runtime credentials. mode=import reads AK/SK from ~/.config/huaweicloud/creds-import.json then wipes it (SK never enters conversation). mode=memory passes AK/SK as tool arguments (SK is visible to model - prefer import). mode=mcp-config reads the injected mcp_settings environment. Approval-gated: the switch requires the user\u2019s explicit confirmation, and the confirmation view names the target account fingerprint and the credential source — in the default token mode the first call returns USER_CONFIRMATION_REQUIRED with an approvalToken the user confirms in their own terminal (npx huaweicloud-devkit approve <token>); under DEVKIT_APPROVAL_MODE=ask the server raises the confirmation itself (an elicitation form, or the ASK_CONFIRMATION_REQUIRED chat round-trip). Vendor-gated (vendorConfirmed): call only when the vendor is established — see the vendorConfirmed parameter description; when unknown, ask which cloud the user means first.',
|
|
284
293
|
schema: authSwitchSchema,
|
|
285
294
|
handler: handleAuthSwitch,
|
|
286
295
|
},
|