huaweicloud-devkit 2.0.0-next.0 → 2.0.0-next.1
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/package.json +1 -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/.workbuddy-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/dist/agents/officeace-sqlite.js +14 -4
- package/plugins/huaweicloud-core/dist/agents/opencode-config.js +5 -1
- package/plugins/huaweicloud-core/dist/approvals-cli.js +159 -0
- package/plugins/huaweicloud-core/dist/hcloud-plan.js +26 -4
- package/plugins/huaweicloud-core/dist/hcloud-run.js +4 -1
- package/plugins/huaweicloud-core/dist/lib/approval-tokens.js +132 -13
- package/plugins/huaweicloud-core/dist/lib/approvals-pin.js +128 -0
- package/plugins/huaweicloud-core/dist/mcp-server.js +114 -28
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +3 -3
- package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +27 -9
- package/plugins/huaweicloud-core/dist/payload-runtime-deps.js +11 -3
- package/plugins/huaweicloud-core/dist/safety/classify-text.js +13 -0
- package/plugins/huaweicloud-core/dist/safety/policy.js +1 -0
- package/plugins/huaweicloud-core/dist/setup-cli.js +7 -0
- package/plugins/huaweicloud-core/dist/update-registry.js +8 -2
- package/plugins/huaweicloud-core/dist/update-upgrade.js +8 -1
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +20 -1
- package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
- package/plugins/huaweicloud-core/safety/policy.json +8 -0
- package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +4 -1
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +13 -6
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +47 -0
- package/plugins/huaweicloud-core/src/agents/officeace-sqlite.ts +14 -4
- package/plugins/huaweicloud-core/src/agents/opencode-config.ts +5 -1
- package/plugins/huaweicloud-core/src/approvals-cli.ts +187 -0
- package/plugins/huaweicloud-core/src/hcloud-plan.ts +44 -5
- package/plugins/huaweicloud-core/src/hcloud-run.ts +4 -1
- package/plugins/huaweicloud-core/src/lib/approval-tokens.ts +194 -13
- package/plugins/huaweicloud-core/src/lib/approvals-pin.ts +153 -0
- package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +29 -9
- package/plugins/huaweicloud-core/src/payload-runtime-deps.ts +11 -3
- package/plugins/huaweicloud-core/src/safety/classify-text.ts +15 -0
- package/plugins/huaweicloud-core/src/safety/policy.ts +2 -0
- package/plugins/huaweicloud-core/src/setup-cli.ts +7 -0
- package/plugins/huaweicloud-core/src/update-registry.ts +8 -2
- package/plugins/huaweicloud-core/src/update-upgrade.ts +8 -1
|
@@ -213,17 +213,36 @@ async function runApprovedCommand(args = {}) {
|
|
|
213
213
|
if (placeholderArg) {
|
|
214
214
|
throw new Error(`The argument "${placeholderArg}" still carries a placeholder secret value: replace <redacted> with the actual value the user approved, then re-run with the same approval token.`);
|
|
215
215
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
216
|
+
// The strict plan is pure, so it is computed before the token is consumed:
|
|
217
|
+
// its userConfirmation.needed decides whether the consume requires a grant,
|
|
218
|
+
// and the result still embeds it.
|
|
219
|
+
const strictPlan = planHcloudCommand(effectiveArgs, { allowWrites: false, mintApprovalToken: false });
|
|
220
|
+
// One snapshot: the confirmation gate, the args-hash binding, the pinView
|
|
221
|
+
// fallback, and the single-use claim all read the SAME entry — the one
|
|
222
|
+
// consumeApprovalToken returns. The pre-consume inspect-gate this replaces
|
|
223
|
+
// verified the grant on one read while execution consumed another, which
|
|
224
|
+
// a same-user store swap between the two reads laundered (the review's
|
|
225
|
+
// TOCTOU repro).
|
|
226
|
+
const consumed = consumeApprovalToken(token, { requireGrant: strictPlan.userConfirmation.needed });
|
|
227
|
+
if (consumed.status === 'grant_required') {
|
|
228
|
+
return {
|
|
229
|
+
status: 'rejected',
|
|
230
|
+
code: 'USER_CONFIRMATION_REQUIRED',
|
|
231
|
+
nextStep: 'Ask the user to run "npx huaweicloud-devkit approve <this approvalToken>" in their own terminal, then retry this exact call.',
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
if (consumed.status === 'gone') {
|
|
235
|
+
// Defensive: inspectApprovalToken said 'valid' but consume returned gone.
|
|
236
|
+
// The paths are the O_EXCL claim losing a race (another consumer is
|
|
237
|
+
// spending this exact token right now) or a store swap removing the
|
|
238
|
+
// entry between the two reads — classify via re-inspect, never a
|
|
239
|
+
// misleading success and never a false not_found.
|
|
222
240
|
const recheck = inspectApprovalToken(token);
|
|
223
241
|
if (recheck.state === 'expired')
|
|
224
242
|
return { status: 'rejected', code: 'CONFIRM_TOKEN_EXPIRED' };
|
|
225
243
|
return { status: 'ok', outcome: 'already_processed' };
|
|
226
244
|
}
|
|
245
|
+
const stored = consumed.entry;
|
|
227
246
|
if (hashArgs(effectiveArgs) !== stored.argsHash) {
|
|
228
247
|
// The pin view is the canonical fold for the substitution comparison
|
|
229
248
|
// (loop round 4, seat-1 B2): it folds the two-token/glued secret forms
|
|
@@ -249,7 +268,6 @@ async function runApprovedCommand(args = {}) {
|
|
|
249
268
|
throw new Error('Secret values are pinned to the approved plan: re-run huaweicloud_plan_cli_command with the final values and re-approve.');
|
|
250
269
|
}
|
|
251
270
|
}
|
|
252
|
-
const strictPlan = planHcloudCommand(effectiveArgs, { allowWrites: false });
|
|
253
271
|
const result = await runHcloud(effectiveArgs, {
|
|
254
272
|
allowWrites: true,
|
|
255
273
|
timeoutMs: args.timeoutMs,
|
|
@@ -373,7 +391,7 @@ export const HUAWEICLOUD_CLI_TOOLS = [
|
|
|
373
391
|
},
|
|
374
392
|
{
|
|
375
393
|
name: 'huaweicloud_plan_cli_command',
|
|
376
|
-
description:
|
|
394
|
+
description: "Classify and plan a Huawei Cloud hcloud command without executing it. When the result's userConfirmation.needed is true, the USER must confirm in their own terminal by running the userConfirmation.command line (npx huaweicloud-devkit approve <approvalToken>) before huaweicloud_run_approved_command will accept the command. Vendor-gated (vendorConfirmed): call only when the vendor is established — see the vendorConfirmed parameter description; when unknown, ask which cloud the user means first.",
|
|
377
395
|
schema: planCliCommandSchema,
|
|
378
396
|
handler: handlePlanCliCommand,
|
|
379
397
|
},
|
|
@@ -391,7 +409,7 @@ export const HUAWEICLOUD_CLI_TOOLS = [
|
|
|
391
409
|
},
|
|
392
410
|
{
|
|
393
411
|
name: 'huaweicloud_run_approved_command',
|
|
394
|
-
description: 'Run a write-capable hcloud command only after the exact command has been shown and explicitly approved by the user. Vendor-gated (vendorConfirmed): call only when the vendor is established — see the vendorConfirmed parameter description; when unknown, ask which cloud the user means first.',
|
|
412
|
+
description: 'Run a write-capable hcloud command only after the exact command has been shown and explicitly approved by the user, and after the user confirmed the plan token in their own terminal (npx huaweicloud-devkit approve <token>). A non-read command without that terminal confirmation is rejected with USER_CONFIRMATION_REQUIRED and the token stays usable. Vendor-gated (vendorConfirmed): call only when the vendor is established — see the vendorConfirmed parameter description; when unknown, ask which cloud the user means first.',
|
|
395
413
|
schema: runApprovedCommandSchema,
|
|
396
414
|
handler: handleRunApprovedCommand,
|
|
397
415
|
},
|
|
@@ -30,7 +30,15 @@ export function installRuntimeDeps(pluginsDir) {
|
|
|
30
30
|
stdio: 'pipe',
|
|
31
31
|
timeout: 120000,
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
// A string command, never an args array: args + shell:true is DEP0190 on
|
|
34
|
+
// Node 24 (the shell concatenates args unescaped), and the warning lands
|
|
35
|
+
// on the CLI's own stderr mid-install — deferred by emitWarning, it even
|
|
36
|
+
// surfaced glued to the provisioning prompt (2026-11-10 report #2). The
|
|
37
|
+
// words are static, so the shell concatenation is injection-safe by
|
|
38
|
+
// construction, and shell:true stays load-bearing: it routes npm.cmd on
|
|
39
|
+
// Windows (the #643 EINVAL doctrine).
|
|
40
|
+
const installCommand = 'npm install --omit=dev --no-audit --no-fund';
|
|
41
|
+
let r = spawnSync(installCommand, spawnOpts);
|
|
34
42
|
const isRetryable = (res) => {
|
|
35
43
|
if (res.status === 0)
|
|
36
44
|
return false;
|
|
@@ -40,12 +48,12 @@ export function installRuntimeDeps(pluginsDir) {
|
|
|
40
48
|
if (r.status !== 0 && isRetryable(r)) {
|
|
41
49
|
console.log(` \x1b[33m[WARN]\x1b[0m npm install hit file-lock error, retrying in 2s...`);
|
|
42
50
|
sleepSync(2000);
|
|
43
|
-
r = spawnSync(
|
|
51
|
+
r = spawnSync(installCommand, spawnOpts);
|
|
44
52
|
}
|
|
45
53
|
if (r.status !== 0 && !isRetryable(r)) {
|
|
46
54
|
console.log(` \x1b[33m[RETRY]\x1b[0m npm install failed (exit ${r.status}), retrying in 3s...`);
|
|
47
55
|
sleepSync(3000);
|
|
48
|
-
r = spawnSync(
|
|
56
|
+
r = spawnSync(installCommand, spawnOpts);
|
|
49
57
|
}
|
|
50
58
|
const undiciDir = join(pluginsDir, 'node_modules', 'undici');
|
|
51
59
|
if (r.status === 0 && existsSync(undiciDir)) {
|
|
@@ -818,6 +818,19 @@ export function classifyTextCommand(command, options = {}) {
|
|
|
818
818
|
reason: 'Printing vault secrets into the agent context is blocked. Run the value consumer instead: npx huaweicloud-devkit secret exec --env NAME=secret://<scope>/<name> -- <command> — a child you trust not to print its own environment, since its stdout is this conversation. Or use secret get --file from your own terminal.',
|
|
819
819
|
};
|
|
820
820
|
}
|
|
821
|
+
// The approval CLI's terminal-only verbs: `approve` consumes the plan token
|
|
822
|
+
// the user is meant to confirm in their own TTY (PIN-checked), and `pin`
|
|
823
|
+
// enrolls the credential that confirm checks. An agent that runs either
|
|
824
|
+
// from Bash drives the human's channel itself — an enrolled-by-agent PIN
|
|
825
|
+
// owns every later confirmation — so both verbs deny. Matched against the
|
|
826
|
+
// same two shadows as the reveal gate.
|
|
827
|
+
if (shadowCandidates.some((candidate) => matchesAny(candidate, policy.blockedApprovalCliPatterns))) {
|
|
828
|
+
return {
|
|
829
|
+
decision: 'deny',
|
|
830
|
+
risk: 'approval',
|
|
831
|
+
reason: "Running the approval CLI from the agent Bash face is blocked: the confirmation must come from the user's own interactive terminal, where the PIN is checked. Ask the user to run the printed npx huaweicloud-devkit approve <token> line themselves (first use: npx huaweicloud-devkit pin, once), then retry the same call.",
|
|
832
|
+
};
|
|
833
|
+
}
|
|
821
834
|
// Order-independent reveal pair: `echo secret get <ref> --stdout | xargs
|
|
822
835
|
// npx huaweicloud-devkit` reorders the argv through xargs while every word
|
|
823
836
|
// is literal in the text — the patterns above assume bin-before-
|
|
@@ -37,6 +37,7 @@ export function loadPolicy(path) {
|
|
|
37
37
|
blockedConfigureSubcommands: toStringArray(raw.blockedConfigureSubcommands, 'blockedConfigureSubcommands'),
|
|
38
38
|
blockedSecretOperations: toStringArray(raw.blockedSecretOperations, 'blockedSecretOperations'),
|
|
39
39
|
blockedSecretCliPatterns: toStringArray(raw.blockedSecretCliPatterns, 'blockedSecretCliPatterns'),
|
|
40
|
+
blockedApprovalCliPatterns: toStringArray(raw.blockedApprovalCliPatterns, 'blockedApprovalCliPatterns'),
|
|
40
41
|
writeOperationPrefixes,
|
|
41
42
|
readOperationPrefixes: toStringArray(raw.readOperationPrefixes, 'readOperationPrefixes'),
|
|
42
43
|
readOperationExceptions: toStringArray(raw.readOperationExceptions, 'readOperationExceptions'),
|
|
@@ -14,6 +14,7 @@ import { cmdProxy } from "./proxy/cli.js";
|
|
|
14
14
|
import { removeKooCli, removeObsConfig } from "./sandbox/uninstall-cleanup.js";
|
|
15
15
|
import { readReceipt, removeReceipt } from "./dep/receipts.js";
|
|
16
16
|
import { runSecretCommand } from "./lib/secret-vault/cli.js";
|
|
17
|
+
import { createProcessApproveIo, runApproveCommand, runPinCommand } from "./approvals-cli.js";
|
|
17
18
|
import { custodyReport } from "./lib/secret-vault/custody.js";
|
|
18
19
|
import { vaultList } from "./lib/secret-vault/store.js";
|
|
19
20
|
import { detectCodeartsSandbox } from "./codearts-sandbox.js";
|
|
@@ -1273,6 +1274,12 @@ async function main() {
|
|
|
1273
1274
|
case 'secret':
|
|
1274
1275
|
process.exitCode = runSecretCommand(process.argv.slice(3));
|
|
1275
1276
|
break;
|
|
1277
|
+
case 'approve':
|
|
1278
|
+
process.exitCode = await runApproveCommand(process.argv.slice(3), createProcessApproveIo());
|
|
1279
|
+
break;
|
|
1280
|
+
case 'pin':
|
|
1281
|
+
process.exitCode = await runPinCommand(process.argv.slice(3), createProcessApproveIo());
|
|
1282
|
+
break;
|
|
1276
1283
|
case 'proxy':
|
|
1277
1284
|
await cmdProxy();
|
|
1278
1285
|
break;
|
|
@@ -65,7 +65,11 @@ export async function queryDistTagsFetch({ timeoutMs = 15000 } = {}) {
|
|
|
65
65
|
}
|
|
66
66
|
export function queryDistTagsSync({ timeoutMs = 15000, cwd, } = {}) {
|
|
67
67
|
try {
|
|
68
|
-
|
|
68
|
+
// String command, never an args array: args + shell:true is DEP0190 on
|
|
69
|
+
// Node 24, and the words are static so the shell concatenation is
|
|
70
|
+
// injection-safe. shell:true stays load-bearing: it routes npm.cmd on
|
|
71
|
+
// Windows (the #643 EINVAL doctrine below).
|
|
72
|
+
const result = spawnSync(`${NPM_BIN} view huaweicloud-devkit dist-tags --json`, {
|
|
69
73
|
encoding: 'utf8',
|
|
70
74
|
timeout: timeoutMs,
|
|
71
75
|
windowsHide: true,
|
|
@@ -97,7 +101,9 @@ export function queryDistTags({ timeoutMs = 15000, cwd, } = {}) {
|
|
|
97
101
|
return new Promise((resolve) => {
|
|
98
102
|
let child;
|
|
99
103
|
try {
|
|
100
|
-
|
|
104
|
+
// Same string-command doctrine as queryDistTagsSync: no args array
|
|
105
|
+
// under shell (DEP0190 on Node 24), static words only.
|
|
106
|
+
child = spawn(`${NPM_BIN} view huaweicloud-devkit dist-tags --json`, {
|
|
101
107
|
windowsHide: true,
|
|
102
108
|
cwd,
|
|
103
109
|
shell: true,
|
|
@@ -10,7 +10,14 @@ import { queryDistTags, errorMessage } from "./update-registry.js";
|
|
|
10
10
|
import { invalidateUpdateCache } from "./update-cache.js";
|
|
11
11
|
const NPX_BIN = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
12
12
|
function defaultSpawn(command, args, options) {
|
|
13
|
-
|
|
13
|
+
// The args join into the command string before the spawn: options carries
|
|
14
|
+
// shell:true (the #643 npm.cmd routing; the target interpolation stays
|
|
15
|
+
// guarded by the SUPPORTED_AGENT_TARGETS allowlist, review #717), and an
|
|
16
|
+
// args array under shell is DEP0190 on Node 24. shell:true already
|
|
17
|
+
// concatenates args unescaped, so the join is behavior-identical minus
|
|
18
|
+
// the warning; the seam's (command, args) contract is unchanged for the
|
|
19
|
+
// injected test doubles.
|
|
20
|
+
return spawnSync([command, ...args].join(' '), options);
|
|
14
21
|
}
|
|
15
22
|
function restartMessage(target) {
|
|
16
23
|
if (target === 'officeace') {
|
|
@@ -34,6 +34,7 @@ HOOK_EVENTS_PATH = TELEMETRY_DIR / "hook-events.jsonl"
|
|
|
34
34
|
CONFIG_FILE_RE = None
|
|
35
35
|
SECRET_READ_RE = None
|
|
36
36
|
SECRET_CLI_RE = None
|
|
37
|
+
APPROVAL_CLI_RE = None
|
|
37
38
|
WRITE_OPERATION_RE = None
|
|
38
39
|
WRITE_VOCAB_RE = None
|
|
39
40
|
READ_OPERATION_RE = None
|
|
@@ -73,7 +74,7 @@ OBS_MARKER_RE = re.compile(r"\bOBS\b", re.I)
|
|
|
73
74
|
|
|
74
75
|
|
|
75
76
|
def load_policy():
|
|
76
|
-
global CONFIG_FILE_RE, SECRET_READ_RE, SECRET_CLI_RE, WRITE_OPERATION_RE, WRITE_VOCAB_RE, READ_OPERATION_RE, READ_OPERATION_EXCEPTIONS
|
|
77
|
+
global CONFIG_FILE_RE, SECRET_READ_RE, SECRET_CLI_RE, APPROVAL_CLI_RE, WRITE_OPERATION_RE, WRITE_VOCAB_RE, READ_OPERATION_RE, READ_OPERATION_EXCEPTIONS
|
|
77
78
|
try:
|
|
78
79
|
with POLICY_PATH.open("r", encoding="utf-8") as file_obj:
|
|
79
80
|
policy = json.load(file_obj)
|
|
@@ -188,6 +189,22 @@ def load_policy():
|
|
|
188
189
|
blocked_secret_cli = policy.get("blockedSecretCliPatterns", [])
|
|
189
190
|
if blocked_secret_cli:
|
|
190
191
|
SECRET_CLI_RE = re.compile("|".join(blocked_secret_cli), re.I)
|
|
192
|
+
# The approval CLI's terminal-confirm verb. No order-independent
|
|
193
|
+
# bin+verb pair guard here, unlike the reveal pair below: `approve`
|
|
194
|
+
# is a common word, so a Huawei Cloud operation named e.g.
|
|
195
|
+
# ApproveThing must never trip this gate. These anchored patterns
|
|
196
|
+
# fire only when a devkit binary spelling is present too.
|
|
197
|
+
blocked_approval_cli = policy.get("blockedApprovalCliPatterns", [])
|
|
198
|
+
if isinstance(blocked_approval_cli, list):
|
|
199
|
+
blocked_approval_cli = [p for p in blocked_approval_cli if isinstance(p, str)]
|
|
200
|
+
if blocked_approval_cli:
|
|
201
|
+
try:
|
|
202
|
+
APPROVAL_CLI_RE = re.compile("|".join(blocked_approval_cli), re.I)
|
|
203
|
+
except re.error:
|
|
204
|
+
# Isolate this gate's degradation: a malformed pattern
|
|
205
|
+
# leaves APPROVAL_CLI_RE None instead of aborting the
|
|
206
|
+
# whole policy load.
|
|
207
|
+
APPROVAL_CLI_RE = None
|
|
191
208
|
except Exception:
|
|
192
209
|
pass
|
|
193
210
|
|
|
@@ -2601,6 +2618,8 @@ def evaluate(tool_name, tool_input):
|
|
|
2601
2618
|
return "reading Huawei Cloud credential/profile files can expose AK/SK or tokens. Use redacted toolkit tools."
|
|
2602
2619
|
if SECRET_CLI_RE and any(SECRET_CLI_RE.search(candidate) for candidate in candidates):
|
|
2603
2620
|
return "printing vault secrets into the agent context is blocked. Use secret exec so the value reaches only the child process environment."
|
|
2621
|
+
if APPROVAL_CLI_RE and any(APPROVAL_CLI_RE.search(candidate) for candidate in candidates):
|
|
2622
|
+
return "running the approval CLI from the agent Bash face is blocked: the confirmation must come from the user's own interactive terminal, where the PIN is checked. Ask the user to run the printed npx huaweicloud-devkit approve <token> line themselves (first use: npx huaweicloud-devkit pin, once), then retry the same call."
|
|
2604
2623
|
# Order-independent reveal pair: xargs reorders the argv while every word
|
|
2605
2624
|
# stays literal — a devkit bin plus a `secret get` pair anywhere is a
|
|
2606
2625
|
# reveal regardless of order (both shadow candidates — the decoded one
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
3
|
"id": "huaweicloud-devkit",
|
|
4
4
|
"displayName": "HuaweiCloud DevKit",
|
|
5
|
-
"version": "2.0.0-next.
|
|
5
|
+
"version": "2.0.0-next.1",
|
|
6
6
|
"family": "bundle-plugin",
|
|
7
7
|
"bundleFormat": "codex",
|
|
8
8
|
"description": "Guide coding agents to use Huawei Cloud safely — KooCLI, APIs, SDKs, 40 MCP tools, skills, and safety guardrails.",
|
|
@@ -45,6 +45,14 @@
|
|
|
45
45
|
"setup-cli\\.(js|mjs|ts)(\\s+--)?\\s+secret\\s+get\\b",
|
|
46
46
|
"setup\\.cjs(\\s+--)?\\s+secret\\s+get\\b"
|
|
47
47
|
],
|
|
48
|
+
"blockedApprovalCliPatterns": [
|
|
49
|
+
"huaweicloud-devkit(@[\\w.+-]+)?(\\.(js|cjs|mjs|exe|ts))?(\\s+--)?\\s+approve\\b",
|
|
50
|
+
"setup-cli\\.(js|mjs|ts)(\\s+--)?\\s+approve\\b",
|
|
51
|
+
"setup\\.cjs(\\s+--)?\\s+approve\\b",
|
|
52
|
+
"huaweicloud-devkit(@[\\w.+-]+)?(\\.(js|cjs|mjs|exe|ts))?(\\s+--)?\\s+pin\\b",
|
|
53
|
+
"setup-cli\\.(js|mjs|ts)(\\s+--)?\\s+pin\\b",
|
|
54
|
+
"setup\\.cjs(\\s+--)?\\s+pin\\b"
|
|
55
|
+
],
|
|
48
56
|
"writeOperationPrefixes": [
|
|
49
57
|
"Create",
|
|
50
58
|
"BatchCreate",
|
|
@@ -99,7 +99,10 @@ curl -sSL https://cn-north-4-hdn-koocli.obs.cn-north-4.myhuaweicloud.com/cli/lat
|
|
|
99
99
|
- Read-only: `List*`, `Show*`, `Get*`, `Describe*`.
|
|
100
100
|
- Write: `Create*`, `Delete*`, `Update*`, `Resize*`, `Start*`, `Stop*`, `Authorize*`, and similar.
|
|
101
101
|
- Secret: any operation returning secret string, binary secret, token, or password.
|
|
102
|
-
9. For write operations,
|
|
102
|
+
9. For write operations, follow the terminal confirmation contract:
|
|
103
|
+
- Call `huaweicloud_plan_cli_command` and read `userConfirmation`. When `needed` is true, show the user the command echo and the `userConfirmation.command` line.
|
|
104
|
+
- The user runs `npx huaweicloud-devkit approve <approvalToken>` in their own terminal. Never run it yourself. First use: the user runs `npx huaweicloud-devkit pin` once in their own terminal to enroll the approvals PIN.
|
|
105
|
+
- Then call `huaweicloud_run_approved_command` with that token. An unconfirmed non-read command is rejected with `USER_CONFIRMATION_REQUIRED`; the token stays usable, so retry the same call after the user confirms.
|
|
103
106
|
|
|
104
107
|
## KooCLI Syntax Notes
|
|
105
108
|
|
|
@@ -23,21 +23,27 @@ Use this skill before any Huawei Cloud action that may expose secrets, change re
|
|
|
23
23
|
- IAM/security
|
|
24
24
|
- cost/payment
|
|
25
25
|
- public exposure
|
|
26
|
-
5. For any non-read-only operation, show the
|
|
26
|
+
5. For any non-read-only operation, follow the plan, confirm, run contract: plan with `huaweicloud_plan_cli_command`, show the user the command and the terminal confirmation line, wait for the user to confirm in their own terminal, then run with `huaweicloud_run_approved_command`. See `references/approvals.md`.
|
|
27
27
|
6. Redact secrets from command output, errors, JSON, logs, and generated reports.
|
|
28
28
|
7. If a command contains `adminPass`, `password`, token, or any secret-like field, warn that plaintext can remain in shell history. Prefer local-only input, runtime injection, or user-side execution.
|
|
29
29
|
|
|
30
30
|
## Enforcement Layers
|
|
31
31
|
|
|
32
|
-
- Hooks: `hooks/huaweicloud-safety.mjs` blocks risky Codex native hook calls without requiring Python; `hooks/huaweicloud-safety.py` remains for Hermes/Python hook compatibility.
|
|
33
|
-
- MCP wrapper: the Node MCP server applies the same safety policy for Codex/OpenCode paths that do not enforce hooks.
|
|
32
|
+
- Hooks: `hooks/huaweicloud-safety.mjs` blocks risky Codex native hook calls without requiring Python; `hooks/huaweicloud-safety.py` remains for Hermes/Python hook compatibility. The hook also denies the `approve` and `pin` verbs on the agent Bash face.
|
|
33
|
+
- MCP wrapper: the Node MCP server applies the same safety policy for Codex/OpenCode paths that do not enforce hooks, and the run tool refuses a non-read command without the user's terminal confirmation.
|
|
34
34
|
- Skills: this document teaches agents the rule before they act.
|
|
35
35
|
|
|
36
36
|
## Write Execution Boundary
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
1. Plan: call `huaweicloud_plan_cli_command`. The result echoes the exact command and carries `userConfirmation: { needed, command }`.
|
|
39
|
+
2. Confirm: when `needed` is true, show the user the plan echo and the `userConfirmation.command` line (`npx huaweicloud-devkit approve <approvalToken>`), then wait. The USER runs that line in their own terminal, where a TTY check and a PIN gate the confirmation. First use: the user runs `npx huaweicloud-devkit pin` once in their own terminal to enroll the PIN.
|
|
40
|
+
3. Run: call `huaweicloud_run_approved_command` with the same `approvalToken` and `approvedByUser: true`.
|
|
41
|
+
|
|
42
|
+
A non-read command without that terminal confirmation is rejected with `USER_CONFIRMATION_REQUIRED`. The refusal does not consume the token, so retry the same call after the user confirms. Re-running a write needs a fresh plan and a fresh confirmation.
|
|
43
|
+
|
|
44
|
+
Never run the approve or pin commands yourself; the hook denies both verbs on the agent's Bash face. The `approvedByUser: true` argument is not the terminal confirmation and never replaces it.
|
|
45
|
+
|
|
46
|
+
Without the devkit tools, show the reviewed command and let the user execute it in their own terminal. After a write, verify with `huaweicloud_run_readonly_command` or another read-only check.
|
|
41
47
|
|
|
42
48
|
## Proactive Hook Checks
|
|
43
49
|
|
|
@@ -58,5 +64,6 @@ Hook checks inspect the command or plan text that is available before execution.
|
|
|
58
64
|
- Use redacted profile inspection instead of raw `hcloud configure show`.
|
|
59
65
|
- Use runtime secret injection instead of fetching secret values into chat.
|
|
60
66
|
- Use the encrypted secret vault for durable secrets: store values as `secret://<scope>/<name>` refs and pass refs, never values. See `references/secrets.md`.
|
|
67
|
+
- Use the terminal confirmation contract for writes: plan, user confirm, run. See `references/approvals.md`.
|
|
61
68
|
- Use read-only verification after a write.
|
|
62
69
|
- Prefer reviewed IaC for durable infrastructure changes.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<!-- generated from src/packs/core/skills/huaweicloud-safety - do not edit -->
|
|
2
|
+
|
|
3
|
+
# Terminal Confirmation For Write Commands
|
|
4
|
+
|
|
5
|
+
A write or execution command runs only after the user confirms the plan token in their own interactive terminal. The agent plans, the user confirms, the agent runs. One confirmation covers exactly one execution.
|
|
6
|
+
|
|
7
|
+
## The three-step contract
|
|
8
|
+
|
|
9
|
+
1. Plan: call `huaweicloud_plan_cli_command` with the final hcloud arguments. The result echoes the exact command and carries `userConfirmation`.
|
|
10
|
+
- `needed: true` means the command is a write or has execution side effects, and `command` is the exact line the user must run: `npx huaweicloud-devkit approve <approvalToken>`.
|
|
11
|
+
- `needed: false` means the command is read-only, so the terminal confirmation does not apply.
|
|
12
|
+
2. Confirm: show the user the plan echo and the `userConfirmation.command` line, then wait. The user runs that line in their own terminal. The terminal prints the redacted command and states that this authorizes one execution.
|
|
13
|
+
3. Run: call `huaweicloud_run_approved_command` with the same `approvalToken`, the same `args`, and `approvedByUser: true`.
|
|
14
|
+
|
|
15
|
+
An unconfirmed non-read command is rejected with `status: "rejected"` and `code: "USER_CONFIRMATION_REQUIRED"`, plus a `nextStep` naming the approve line. The refusal does not consume the token, so retry the same call after the user confirms.
|
|
16
|
+
|
|
17
|
+
## The PIN and the TTY check
|
|
18
|
+
|
|
19
|
+
The approve command refuses to record a confirmation unless stdin and stdout are both terminals. A pipe cannot answer a prompt, so an agent that shells out to Bash cannot drive the confirmation. A human at an interactive terminal can.
|
|
20
|
+
|
|
21
|
+
First use is two steps, both in the user's own terminal: run `npx huaweicloud-devkit pin` once to choose an approvals PIN (at least 6 characters, typed twice), then confirm plans with `npx huaweicloud-devkit approve <approvalToken>`. The approve command refuses outright on a machine with no enrolled PIN instead of enrolling one inline. Every confirmation verifies the PIN with three attempts per invocation.
|
|
22
|
+
|
|
23
|
+
A wrong PIN also counts toward a persistent failure lockout: every sixth cumulative failure locks verification for 5 minutes, doubling per lockout episode and capped at 24 hours, and a correct PIN clears the counter. The failure lockout is guidance, not a boundary — a same-user process can edit the PIN record the same way it can edit any file under `~/.config/huaweicloud/`.
|
|
24
|
+
|
|
25
|
+
The PIN record stores only a mac over the vault custody master key, never the plaintext. The PIN proves presence at the terminal. It does not prove the user read the command.
|
|
26
|
+
|
|
27
|
+
## One confirmation per execution
|
|
28
|
+
|
|
29
|
+
The confirmation authorizes one execution of one command.
|
|
30
|
+
|
|
31
|
+
- The plan token expires 5 minutes after the plan. An expired token is refused, and the agent must plan the command again.
|
|
32
|
+
- A run consumes the token. A repeat run of the same token reports `outcome: "already_processed"`, never a second execution.
|
|
33
|
+
- A run result's plan is minted without a token, so it never carries a usable approval. Re-running the command needs a fresh `huaweicloud_plan_cli_command` call and a fresh terminal confirmation.
|
|
34
|
+
- Changing the arguments rejects the run, because the token pins the exact command hash and any real secret values in it.
|
|
35
|
+
|
|
36
|
+
## What the agent must not do
|
|
37
|
+
|
|
38
|
+
- Never run `npx huaweicloud-devkit approve` or `npx huaweicloud-devkit pin` yourself, in any spelling. The confirmation's value is that the user's own terminal records it, and the safety hook denies both verbs on the agent Bash face for exactly that reason.
|
|
39
|
+
- Never treat `approvedByUser: true` as the confirmation. It is the agent's statement that the user approved the exact command, and the run tool still requires the terminal-confirmed grant.
|
|
40
|
+
- Never ask the user for their PIN, and never enter a PIN on the user's behalf.
|
|
41
|
+
- Never retry a run with different arguments under the same token. Plan again and get a fresh confirmation.
|
|
42
|
+
|
|
43
|
+
## Honest security boundary
|
|
44
|
+
|
|
45
|
+
The terminal confirmation defends: execution needs a user-recorded, PIN-checked grant made at an interactive terminal; the grant is a custody-keyed mac bound to the token, the confirmation time, and every stored field the run gate trusts (command hash, pin view, redacted form, secret-pinning flag, mint time), so a same-user edit of the state string or any trusted field does not verify; and a non-read command without a valid grant never runs.
|
|
46
|
+
|
|
47
|
+
It does NOT defend against: a socially engineered user who approves a command they did not read (the terminal prints the command, but the PIN proves presence, not comprehension); a same-user process that holds BOTH the custody master key and write access to `~/.config/huaweicloud/`, which can forge a grant for any pending token on the keyfile tier; a harness without the safety hook, where the TTY check is the only barrier and an agent driving a pseudo-terminal looks like a terminal; or the hook's text gate missing variable-indirect verbs (`V=approve; npx huaweicloud-devkit $V` — the same indirection residual the shell shadow documents for the secret gate), where the agent reaches the CLI spelling through a shell variable. This is a consent gate, not an isolation boundary.
|
|
@@ -44,11 +44,20 @@ function toSqliteModule(value: unknown): SqliteModule | null {
|
|
|
44
44
|
return typeof ctor === 'function' ? (value as SqliteModule) : null;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
// The builtin is required inside a function, never at module scope: loading
|
|
48
|
+
// the setup-cli graph is the CLI's boot, and node:sqlite is experimental
|
|
49
|
+
// through Node 22.x (the declared floor) — at module scope it printed
|
|
50
|
+
// "(node:xxxx) ExperimentalWarning: SQLite is an experimental feature" on
|
|
51
|
+
// every CLI run, install included, and throws outright below Node 22.5,
|
|
52
|
+
// though only the officeace packs/doctor paths ever open the connector db.
|
|
53
|
+
// agent-registration.ts keeps the same doctrine for the MCP graph's probe.
|
|
54
|
+
function loadDatabaseSync(): new (_path: string) => SqliteDatabase {
|
|
55
|
+
const sqliteModule = toSqliteModule(createRequire(import.meta.url)('node:sqlite'));
|
|
56
|
+
if (!sqliteModule) {
|
|
57
|
+
throw new Error('node:sqlite is unavailable; the OfficeAce integration requires Node.js >= 22');
|
|
58
|
+
}
|
|
59
|
+
return sqliteModule.DatabaseSync;
|
|
50
60
|
}
|
|
51
|
-
const { DatabaseSync } = sqliteModule;
|
|
52
61
|
|
|
53
62
|
export function officeaceSqlitePath(): string {
|
|
54
63
|
const capDir = officeaceCapabilitiesDirSafe();
|
|
@@ -56,6 +65,7 @@ export function officeaceSqlitePath(): string {
|
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
export function openOfficeaceDb(): SqliteDatabase {
|
|
68
|
+
const DatabaseSync = loadDatabaseSync();
|
|
59
69
|
return new DatabaseSync(officeaceSqlitePath());
|
|
60
70
|
}
|
|
61
71
|
|
|
@@ -56,7 +56,11 @@ function probeOpencodeVersion(): string | null {
|
|
|
56
56
|
const probeEnv = { ...process.env, XDG_CONFIG_HOME: probeRoot };
|
|
57
57
|
const run = (cmd: string, shell: boolean): string | null => {
|
|
58
58
|
try {
|
|
59
|
-
|
|
59
|
+
// Args ride the command string whenever shell is true: an args array
|
|
60
|
+
// under shell is DEP0190 on Node 24+ (and would double the --version
|
|
61
|
+
// the win32 fallback string already carries). Without a shell the
|
|
62
|
+
// array stays — spawn needs the separated argument there.
|
|
63
|
+
const r = spawnSync(cmd, shell ? undefined : ['--version'], {
|
|
60
64
|
shell,
|
|
61
65
|
windowsHide: true,
|
|
62
66
|
stdio: 'pipe',
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { confirmApprovalToken, inspectApprovalToken, type ApprovalEntry } from './lib/approval-tokens.ts';
|
|
2
|
+
import { enrollApprovalsPin, isApprovalsPinEnrolled, verifyApprovalsPin } from './lib/approvals-pin.ts';
|
|
3
|
+
import { readSecret } from './lib/cli-io.ts';
|
|
4
|
+
|
|
5
|
+
// The human half of the approval gate: `npx huaweicloud-devkit approve <token>`
|
|
6
|
+
// is the only channel that writes a user confirmation, so it must be driven
|
|
7
|
+
// by a person at a terminal. The command refuses every non-interactive
|
|
8
|
+
// caller (an agent piping into Bash cannot pass), and it refuses to record
|
|
9
|
+
// the confirmation without the PIN. The door has no flags, because a flag
|
|
10
|
+
// would be an escape hatch for the caller the gate is built to stop.
|
|
11
|
+
//
|
|
12
|
+
// PIN enrollment is its own verb (`pin`): approve refuses outright on a
|
|
13
|
+
// machine with no enrolled PIN instead of enrolling inline — an inline
|
|
14
|
+
// first-use enroll would let any pseudo-terminal caller choose the PIN.
|
|
15
|
+
//
|
|
16
|
+
// The token lifecycle and the PIN record are pure state/crypto modules
|
|
17
|
+
// (lib/approval-tokens.ts, lib/approvals-pin.ts); this file owns prompts and
|
|
18
|
+
// exit codes, and takes its terminal as an injected ApproveIo so tests can
|
|
19
|
+
// drive both the refusal and the interactive paths without a real TTY.
|
|
20
|
+
|
|
21
|
+
const USAGE = 'Usage: npx huaweicloud-devkit approve <token>';
|
|
22
|
+
const PIN_USAGE = 'Usage: npx huaweicloud-devkit pin';
|
|
23
|
+
|
|
24
|
+
const PIN_ATTEMPTS = 3;
|
|
25
|
+
const ENROLL_ATTEMPTS = 2;
|
|
26
|
+
|
|
27
|
+
export interface ApproveIo {
|
|
28
|
+
isTTY: boolean;
|
|
29
|
+
write(text: string): void;
|
|
30
|
+
readLine(): Promise<string>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function createProcessApproveIo(): ApproveIo {
|
|
34
|
+
return {
|
|
35
|
+
// Both ends must be terminals: stdout-only TTY (agent captures output)
|
|
36
|
+
// and stdin-only TTY (agent feeds input) are both agent-shaped pipes.
|
|
37
|
+
isTTY: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
38
|
+
write: (text) => {
|
|
39
|
+
process.stdout.write(text);
|
|
40
|
+
},
|
|
41
|
+
readLine: () => readSecret(''),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function renderCommand(argsRedacted: unknown): string {
|
|
46
|
+
if (Array.isArray(argsRedacted)) {
|
|
47
|
+
const rendered = argsRedacted.map((arg) => (typeof arg === 'string' ? arg : JSON.stringify(arg)));
|
|
48
|
+
return `hcloud ${rendered.join(' ')}`;
|
|
49
|
+
}
|
|
50
|
+
return JSON.stringify(argsRedacted);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function printRefusal(io: ApproveIo, inspectionState: string): number {
|
|
54
|
+
if (inspectionState === 'not_found') {
|
|
55
|
+
io.write('No pending approval matches that token.\n');
|
|
56
|
+
} else if (inspectionState === 'expired') {
|
|
57
|
+
io.write(
|
|
58
|
+
'That approval expired. A confirmation must happen within 5 minutes of the plan; ask the agent to plan the command again.\n',
|
|
59
|
+
);
|
|
60
|
+
} else {
|
|
61
|
+
io.write('This approval was already used.\n');
|
|
62
|
+
}
|
|
63
|
+
return inspectionState === 'already_consumed' ? 0 : 1;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function enrollPin(io: ApproveIo): Promise<boolean> {
|
|
67
|
+
io.write('Choose a PIN of at least 6 characters.\n');
|
|
68
|
+
for (let attempt = 1; attempt <= ENROLL_ATTEMPTS; attempt++) {
|
|
69
|
+
io.write('Choose a PIN: ');
|
|
70
|
+
const first = await io.readLine();
|
|
71
|
+
io.write('Re-type the PIN: ');
|
|
72
|
+
const second = await io.readLine();
|
|
73
|
+
if (first !== second) {
|
|
74
|
+
io.write(attempt < ENROLL_ATTEMPTS ? 'The PINs did not match, try again.\n' : 'The PINs did not match.\n');
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const enrolled = enrollApprovalsPin(first);
|
|
78
|
+
if (!enrolled.ok) {
|
|
79
|
+
io.write(`Cannot enroll the approvals PIN: ${enrolled.reason ?? 'unknown error'}.\n`);
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
io.write('Approvals PIN enrolled.\n');
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function verifyPin(io: ApproveIo): Promise<boolean> {
|
|
89
|
+
for (let attempt = 1; attempt <= PIN_ATTEMPTS; attempt++) {
|
|
90
|
+
io.write('PIN: ');
|
|
91
|
+
const pin = await io.readLine();
|
|
92
|
+
if (verifyApprovalsPin(pin).ok) return true;
|
|
93
|
+
if (attempt < PIN_ATTEMPTS) io.write(`Incorrect PIN (${attempt}/${PIN_ATTEMPTS}), try again.\n`);
|
|
94
|
+
}
|
|
95
|
+
io.write('Too many incorrect PIN attempts.\n');
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function printConfirmResult(
|
|
100
|
+
io: ApproveIo,
|
|
101
|
+
status: ReturnType<typeof confirmApprovalToken>['status'],
|
|
102
|
+
reason: string | undefined,
|
|
103
|
+
): number {
|
|
104
|
+
switch (status) {
|
|
105
|
+
case 'confirmed':
|
|
106
|
+
io.write('Confirmed. The agent may now run this command once.\n');
|
|
107
|
+
return 0;
|
|
108
|
+
case 'already_confirmed':
|
|
109
|
+
io.write('This approval was already confirmed. The agent may run this command once.\n');
|
|
110
|
+
return 0;
|
|
111
|
+
case 'already_consumed':
|
|
112
|
+
io.write('This approval was already used.\n');
|
|
113
|
+
return 0;
|
|
114
|
+
case 'expired':
|
|
115
|
+
io.write(
|
|
116
|
+
'That approval expired. A confirmation must happen within 5 minutes of the plan; ask the agent to plan the command again.\n',
|
|
117
|
+
);
|
|
118
|
+
return 1;
|
|
119
|
+
case 'custody_unavailable':
|
|
120
|
+
io.write(`Cannot record the confirmation: ${reason ?? 'the vault master key is unavailable'}.\n`);
|
|
121
|
+
return 1;
|
|
122
|
+
case 'not_found':
|
|
123
|
+
io.write('No pending approval matches that token.\n');
|
|
124
|
+
return 1;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function runApproveCommand(argv: string[], io: ApproveIo): Promise<number> {
|
|
129
|
+
const token = argv[0];
|
|
130
|
+
// No flags: any extra argv is a caller trying to steer the confirmation.
|
|
131
|
+
if (!token || token.startsWith('-') || argv.length > 1) {
|
|
132
|
+
io.write(`${USAGE}\n`);
|
|
133
|
+
return 1;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const inspection = inspectApprovalToken(token);
|
|
137
|
+
if (inspection.state !== 'valid') return printRefusal(io, inspection.state);
|
|
138
|
+
|
|
139
|
+
const entry: ApprovalEntry | undefined = inspection.entry;
|
|
140
|
+
if (!entry) {
|
|
141
|
+
io.write('No pending approval matches that token.\n');
|
|
142
|
+
return 1;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
io.write(`Confirming: ${renderCommand(entry.argsRedacted)}\n`);
|
|
146
|
+
io.write('This authorizes ONE execution of exactly this command.\n');
|
|
147
|
+
|
|
148
|
+
// The TTY gate sits after the description so a human sees what would have
|
|
149
|
+
// been confirmed, and before any prompt so no pipe can answer one.
|
|
150
|
+
if (!io.isTTY) {
|
|
151
|
+
io.write('Approvals must be confirmed in your own interactive terminal.\n');
|
|
152
|
+
return 1;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Enrollment is a deliberate separate step, never an inline fallback: a
|
|
156
|
+
// first confirm that mints its own PIN would enroll whatever the current
|
|
157
|
+
// caller typed, and a pseudo-terminal makes even an agent "interactive".
|
|
158
|
+
if (!isApprovalsPinEnrolled()) {
|
|
159
|
+
io.write(
|
|
160
|
+
'No approvals PIN is enrolled yet. Run "npx huaweicloud-devkit pin" in your own terminal once, then confirm plans with "approve".\n',
|
|
161
|
+
);
|
|
162
|
+
return 1;
|
|
163
|
+
}
|
|
164
|
+
if (!(await verifyPin(io))) {
|
|
165
|
+
return 1;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const result = confirmApprovalToken(token);
|
|
169
|
+
return printConfirmResult(io, result.status, result.reason);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// `npx huaweicloud-devkit pin`: the deliberate enrollment step the approve
|
|
173
|
+
// command refuses to perform inline. Same door shape as approve — no flags,
|
|
174
|
+
// TTY-gated, injected io — because it writes the credential the confirmation
|
|
175
|
+
// gate trusts.
|
|
176
|
+
export async function runPinCommand(argv: string[], io: ApproveIo): Promise<number> {
|
|
177
|
+
// No flags: any extra argv is a caller trying to steer the enrollment.
|
|
178
|
+
if (argv.length > 0) {
|
|
179
|
+
io.write(`${PIN_USAGE}\n`);
|
|
180
|
+
return 1;
|
|
181
|
+
}
|
|
182
|
+
if (!io.isTTY) {
|
|
183
|
+
io.write('The approvals PIN must be enrolled in your own interactive terminal.\n');
|
|
184
|
+
return 1;
|
|
185
|
+
}
|
|
186
|
+
return (await enrollPin(io)) ? 0 : 1;
|
|
187
|
+
}
|