huaweicloud-devkit 2.0.0-next.2 → 2.0.0-next.3
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 +1 -1
- 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/opencode-config.js +73 -2
- package/plugins/huaweicloud-core/dist/agents/opencode.js +62 -1
- package/plugins/huaweicloud-core/dist/hcloud-plan.js +25 -5
- package/plugins/huaweicloud-core/dist/lib/approval-mode.js +30 -0
- package/plugins/huaweicloud-core/dist/lib/opencode-ask-rule.js +116 -0
- package/plugins/huaweicloud-core/dist/mcp-protocol.js +20 -1
- package/plugins/huaweicloud-core/dist/mcp-server.js +86 -18
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +3 -3
- package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +74 -22
- package/plugins/huaweicloud-core/dist/setup-cli.js +6 -3
- package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
- package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +4 -4
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +8 -7
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +10 -0
- package/plugins/huaweicloud-core/src/agents/opencode-config.ts +82 -2
- package/plugins/huaweicloud-core/src/agents/opencode.ts +86 -1
- package/plugins/huaweicloud-core/src/hcloud-plan.ts +38 -6
- package/plugins/huaweicloud-core/src/lib/approval-mode.ts +32 -0
- package/plugins/huaweicloud-core/src/lib/opencode-ask-rule.ts +131 -0
- package/plugins/huaweicloud-core/src/mcp-protocol.ts +20 -1
- package/plugins/huaweicloud-core/src/mcp-server.ts +13 -0
- package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +81 -24
- package/plugins/huaweicloud-core/src/setup-cli.ts +6 -2
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// The OpenCode ask-mode permission rule — pure merge/cleanup logic.
|
|
2
|
+
//
|
|
3
|
+
// Purpose: in the ASK approval posture (DEVKIT_APPROVAL_MODE=ask), the
|
|
4
|
+
// user's confirmation for an hcloud write is the harness client's own
|
|
5
|
+
// permission prompt on the huaweicloud_run_approved_command call — which
|
|
6
|
+
// only happens when the client is made to ASK for that tool. Measured on
|
|
7
|
+
// opencode 2.2.7: the V2 config key is a top-level `permissions` ARRAY of
|
|
8
|
+
// { action, resource, effect } objects; the MCP tool action is
|
|
9
|
+
// `<server>_<tool>`, and our server key is `huaweicloud-devkit`, so the
|
|
10
|
+
// action is `huaweicloud-devkit_huaweicloud_run_approved_command`; the
|
|
11
|
+
// config hot-reloads without restarting opencode; and a `deny` on that
|
|
12
|
+
// exact action prunes the tool from the live catalog (restored when the
|
|
13
|
+
// deny is removed) — which is also why an allow on it silently removes
|
|
14
|
+
// the gate. 2.2.7 still parses the V1 `permission` object the skills-tree
|
|
15
|
+
// seam writes (the bundle migrates it), but the array is the documented
|
|
16
|
+
// V2 shape — this rule rides ONLY the array form and is gated on opencode
|
|
17
|
+
// major >= 2; the V1 seam is untouched.
|
|
18
|
+
//
|
|
19
|
+
// Ownership rules: an entry on the ask action is user-owned by
|
|
20
|
+
// construction — add-only-if-absent (a pre-existing entry with ANY effect
|
|
21
|
+
// is the user's and survives the write; `skipped` reports it) and
|
|
22
|
+
// value-exact deletion (only the exact action + resource '*' + effect
|
|
23
|
+
// 'ask' triple is removed at uninstall) are the whole contract. The
|
|
24
|
+
// accepted edge is the same one the seam records: a user-authored
|
|
25
|
+
// same-shape rule that predates the write is removed together with it.
|
|
26
|
+
//
|
|
27
|
+
// This module is pure: no fs, no spawn, no console — opencode-config.ts
|
|
28
|
+
// owns I/O, the version probe, and logging; tests import these functions
|
|
29
|
+
// directly.
|
|
30
|
+
|
|
31
|
+
import { asRecord } from './as-record.ts';
|
|
32
|
+
|
|
33
|
+
export const ASK_RULE_ACTION = 'huaweicloud-devkit_huaweicloud_run_approved_command';
|
|
34
|
+
export const ASK_RULE_RESOURCE = '*';
|
|
35
|
+
|
|
36
|
+
export interface AskRuleApplyResult {
|
|
37
|
+
changed: boolean;
|
|
38
|
+
// True when nothing was written because the user owns the territory: an
|
|
39
|
+
// entry on the ask action already exists (any effect — including one
|
|
40
|
+
// identical to ours, indistinguishable from a pre-existing user rule),
|
|
41
|
+
// or `permissions` is present but not an array.
|
|
42
|
+
skipped: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isRuleRecord(value: unknown): value is Record<string, unknown> {
|
|
46
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Mutates config in place. Fresh configs get the single-entry array;
|
|
50
|
+
// arrays without an entry on the ask action get ours APPENDED — OpenCode
|
|
51
|
+
// evaluates last-matching-rule-wins, so the appended entry is the
|
|
52
|
+
// effective one. Arrays that already carry an entry on the action, and
|
|
53
|
+
// non-array `permissions` shapes, are the user's: nothing is written.
|
|
54
|
+
export function applyAskPermissionRule(config: Record<string, unknown>): AskRuleApplyResult {
|
|
55
|
+
if (config.permissions === undefined) {
|
|
56
|
+
config.permissions = [{ action: ASK_RULE_ACTION, resource: ASK_RULE_RESOURCE, effect: 'ask' }];
|
|
57
|
+
return { changed: true, skipped: false };
|
|
58
|
+
}
|
|
59
|
+
if (!Array.isArray(config.permissions)) {
|
|
60
|
+
return { changed: false, skipped: true };
|
|
61
|
+
}
|
|
62
|
+
const rules: unknown[] = config.permissions;
|
|
63
|
+
if (rules.some((rule) => isRuleRecord(rule) && rule.action === ASK_RULE_ACTION)) {
|
|
64
|
+
return { changed: false, skipped: true };
|
|
65
|
+
}
|
|
66
|
+
rules.push({ action: ASK_RULE_ACTION, resource: ASK_RULE_RESOURCE, effect: 'ask' });
|
|
67
|
+
return { changed: true, skipped: false };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Mutates config in place. Value-exact deletion only — an entry matching
|
|
71
|
+
// action + resource '*' + effect 'ask' exactly is ours; a user-modified
|
|
72
|
+
// entry (any other effect or resource) survives. The array key is pruned
|
|
73
|
+
// only when OUR removals emptied it; a pre-existing empty array is left
|
|
74
|
+
// untouched. Returns whether anything changed.
|
|
75
|
+
export function removeAskPermissionRule(config: Record<string, unknown>): boolean {
|
|
76
|
+
if (!Array.isArray(config.permissions)) return false;
|
|
77
|
+
const rules: unknown[] = config.permissions;
|
|
78
|
+
const kept = rules.filter(
|
|
79
|
+
(rule) =>
|
|
80
|
+
!(
|
|
81
|
+
isRuleRecord(rule) &&
|
|
82
|
+
rule.action === ASK_RULE_ACTION &&
|
|
83
|
+
rule.resource === ASK_RULE_RESOURCE &&
|
|
84
|
+
rule.effect === 'ask'
|
|
85
|
+
),
|
|
86
|
+
);
|
|
87
|
+
if (kept.length === rules.length) return false;
|
|
88
|
+
if (kept.length === 0) {
|
|
89
|
+
delete config.permissions;
|
|
90
|
+
} else {
|
|
91
|
+
config.permissions = kept;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// The effective posture of the ask action. OpenCode evaluates
|
|
97
|
+
// last-matching-rule-wins, so the LAST entry on the action is the
|
|
98
|
+
// effective one — read that, never the first. Returns its effect
|
|
99
|
+
// ('ask' / 'allow' / 'deny'), 'absent' when no entry matches (or the
|
|
100
|
+
// array is empty / the key is missing), and 'foreign' for an unreadable
|
|
101
|
+
// posture: `permissions` present but not an array, or the last matching
|
|
102
|
+
// entry carrying an effect outside the allow/ask/deny vocabulary.
|
|
103
|
+
export function inspectAskPermissionRule(
|
|
104
|
+
config: Record<string, unknown>,
|
|
105
|
+
): 'ask' | 'allow' | 'deny' | 'absent' | 'foreign' {
|
|
106
|
+
if (config.permissions === undefined) return 'absent';
|
|
107
|
+
if (!Array.isArray(config.permissions)) return 'foreign';
|
|
108
|
+
const rules: unknown[] = config.permissions;
|
|
109
|
+
for (let i = rules.length - 1; i >= 0; i--) {
|
|
110
|
+
const rule = asRecord(rules[i]);
|
|
111
|
+
if (rule.action !== ASK_RULE_ACTION) continue;
|
|
112
|
+
if (rule.effect === 'ask' || rule.effect === 'allow' || rule.effect === 'deny') {
|
|
113
|
+
return rule.effect;
|
|
114
|
+
}
|
|
115
|
+
return 'foreign';
|
|
116
|
+
}
|
|
117
|
+
return 'absent';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Floor check for the probe result: the `permissions` array is the
|
|
121
|
+
// documented V2 shape, measured on 2.2.7 only. Opencode major >= 2 (the
|
|
122
|
+
// anchored `v<major>.` form, mirroring opencodeSeamVersionSupported's
|
|
123
|
+
// extract-not-pass-raw polarity); null and unparsable output are
|
|
124
|
+
// unsupported — the caller's polarity is skip, keeping BOTH the terminal
|
|
125
|
+
// token gate and its mcp env untouched rather than guessing.
|
|
126
|
+
export function opencodeAskRuleVersionSupported(version: string | null): boolean {
|
|
127
|
+
if (version === null) return false;
|
|
128
|
+
const match = /^v?(\d+)\./.exec(version.trim());
|
|
129
|
+
if (!match) return false;
|
|
130
|
+
return Number(match[1]) >= 2;
|
|
131
|
+
}
|
|
@@ -18,6 +18,7 @@ import { peekCachedUpdateInfo, applyUpdateHint, readInstalledVersion } from './u
|
|
|
18
18
|
import { initTelemetry } from './telemetry/telemetry.ts';
|
|
19
19
|
import { detectAgent } from './telemetry/agent-detect.ts';
|
|
20
20
|
import { asRecord } from './lib/as-record.ts';
|
|
21
|
+
import { approvalModeFromEnv } from './lib/approval-mode.ts';
|
|
21
22
|
|
|
22
23
|
const pkgVersion = readInstalledVersion() || '0.0.0';
|
|
23
24
|
|
|
@@ -262,6 +263,11 @@ export function createDevkitMcpServer({
|
|
|
262
263
|
remoteSurface = false,
|
|
263
264
|
}: DevkitServerOptions = {}): McpServer {
|
|
264
265
|
assertConstructedSchemas();
|
|
266
|
+
// The approval posture resolves once at construction: a bogus
|
|
267
|
+
// DEVKIT_APPROVAL_MODE throws here (boot fail-fast, the same doctrine
|
|
268
|
+
// DEVKIT_PACKS applies through syncDisclosure), and registerOne below is
|
|
269
|
+
// the one place the mode changes the wire surface.
|
|
270
|
+
const askMode = approvalModeFromEnv(process.env) === 'ask';
|
|
265
271
|
// The contradictory construction is refused, not cautioned: a remote that
|
|
266
272
|
// also carried runtime pack toggling would attach the onPacksChanged seam
|
|
267
273
|
// to every callOpts, publishing the server host's absolute install path
|
|
@@ -327,7 +333,20 @@ export function createDevkitMcpServer({
|
|
|
327
333
|
tool.name,
|
|
328
334
|
server.registerTool(
|
|
329
335
|
tool.name,
|
|
330
|
-
{
|
|
336
|
+
{
|
|
337
|
+
description: tool.description,
|
|
338
|
+
inputSchema: getToolSchema(tool.name),
|
|
339
|
+
// Ask mode only: Claude Code honors this flag by prompting the
|
|
340
|
+
// user on every call of this tool — even in acceptEdits/auto/
|
|
341
|
+
// bypassPermissions modes, with no "don't ask again" — and that
|
|
342
|
+
// client prompt IS the user's confirmation the mode trusts.
|
|
343
|
+
// Other clients ignore the flag. Declared only in ask mode so
|
|
344
|
+
// token-mode Claude Code users don't gain a second prompt on top
|
|
345
|
+
// of the terminal approve they already run.
|
|
346
|
+
...(askMode && tool.name === 'huaweicloud_run_approved_command'
|
|
347
|
+
? { _meta: { 'anthropic/requiresUserInteraction': true } }
|
|
348
|
+
: {}),
|
|
349
|
+
},
|
|
331
350
|
async (args): Promise<CallToolResult> => {
|
|
332
351
|
const callOpts: CallToolOptions = runtimePacks
|
|
333
352
|
? { sessionId, onPacksChanged: () => syncDisclosure() }
|
|
@@ -8,6 +8,7 @@ import { createDevkitMcpServer } from './mcp-protocol.ts';
|
|
|
8
8
|
import { DEFAULT_PORT, DEFAULT_HOST } from './mcp-server-remote.ts';
|
|
9
9
|
import { getCachedUpdateInfo, readInstalledVersion } from './update-check.ts';
|
|
10
10
|
import { maybePreinstallKooCli } from './preflight.ts';
|
|
11
|
+
import { approvalModeFromEnv } from './lib/approval-mode.ts';
|
|
11
12
|
|
|
12
13
|
const transportIdx = process.argv.indexOf('--transport');
|
|
13
14
|
const transport = transportIdx > -1 && process.argv[transportIdx + 1] ? process.argv[transportIdx + 1] : 'stdio';
|
|
@@ -57,6 +58,18 @@ try {
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
if (transport === 'remote') {
|
|
61
|
+
// Ask mode is a stdio-harness posture: its confirmation evidence is the
|
|
62
|
+
// harness client's per-call permission prompt, and this stateless remote
|
|
63
|
+
// face serves plain HTTP callers with no trustworthy per-call prompt —
|
|
64
|
+
// so the env is forced back to the token gate, loudly, before any
|
|
65
|
+
// request handler resolves it. This is the only production entry to the
|
|
66
|
+
// remote surface.
|
|
67
|
+
if (approvalModeFromEnv(process.env) === 'ask') {
|
|
68
|
+
process.env.DEVKIT_APPROVAL_MODE = 'token';
|
|
69
|
+
process.stderr.write(
|
|
70
|
+
'DEVKIT_APPROVAL_MODE=ask is not supported on the remote transport (no per-call permission prompt to trust); falling back to token approval.\n',
|
|
71
|
+
);
|
|
72
|
+
}
|
|
60
73
|
const { startRemoteServer } = await import('./mcp-server-remote.ts');
|
|
61
74
|
startRemoteServer({ port: remotePort, host: remoteHost }).catch((error: unknown) => {
|
|
62
75
|
process.stderr.write(
|
|
@@ -7,10 +7,12 @@ import {
|
|
|
7
7
|
firstPlaceholderSecretArg,
|
|
8
8
|
pinViewArgs,
|
|
9
9
|
type HcloudRunResult,
|
|
10
|
+
type HcloudRunOptions,
|
|
10
11
|
} from '../../hcloud-cli.ts';
|
|
11
12
|
import { hcloudProbeNextStep, hcloudProbeRaw, probeHcloud, type ProbeHcloudOptions } from '../../hcloud-probe.ts';
|
|
12
13
|
import { redactSecrets } from '../../safety-policy.ts';
|
|
13
14
|
import { asText } from '../../lib/as-text.ts';
|
|
15
|
+
import { approvalModeFromEnv, type ApprovalMode } from '../../lib/approval-mode.ts';
|
|
14
16
|
import { consumeApprovalToken, hashArgs, inspectApprovalToken } from '../../lib/approval-tokens.ts';
|
|
15
17
|
import { booleanArg, numericArg, stringArrayArg, vendorConfirmed } from '../../lib/tool-schema-parts.ts';
|
|
16
18
|
import type { PackToolDefinition, LooseToolSchema } from '../../lib/pack-types.ts';
|
|
@@ -21,7 +23,11 @@ import { asRecord } from '../../lib/as-record.ts';
|
|
|
21
23
|
// version/profile inspection, plan/read-only/approved command execution,
|
|
22
24
|
// operation discovery, and region listing. The consent layer is imported
|
|
23
25
|
// directly from src/lib/approval-tokens.ts (the CLI face's consent module),
|
|
24
|
-
// not the hcloud-cli.ts re-export shim. The
|
|
26
|
+
// not the hcloud-cli.ts re-export shim. The approval posture resolves from
|
|
27
|
+
// DEVKIT_APPROVAL_MODE (src/lib/approval-mode.ts): 'token' (default) keeps
|
|
28
|
+
// the out-of-band terminal gate; 'ask' makes the harness client's own
|
|
29
|
+
// permission prompt the user's confirmation, so the plan mints nothing and
|
|
30
|
+
// the run needs no token. The only allowWrites:true call site
|
|
25
31
|
// in the codebase (runApprovedCommand) lives here, so trimming this pack
|
|
26
32
|
// removes the CLI execution face and its approval tools together: a
|
|
27
33
|
// configuration trimmed of this pack has no devkit-side hcloud CLI write
|
|
@@ -201,10 +207,68 @@ async function listOperations(service: string | undefined, options: { timeoutMs?
|
|
|
201
207
|
};
|
|
202
208
|
}
|
|
203
209
|
|
|
210
|
+
// A placeholder-shaped secret VALUE at run time is never a real secret in
|
|
211
|
+
// either approval mode: executing a literal `<redacted>`/`<password>` as
|
|
212
|
+
// the password is always wrong. The guard is shared so the two modes can
|
|
213
|
+
// never drift on detection; only the re-run wording is mode-aware — token
|
|
214
|
+
// mode keeps the guidance followable on the SAME approval (the guard runs
|
|
215
|
+
// before the token is consumed; loop round 3, seat-1 B3: the guidance used
|
|
216
|
+
// to be a dead end because the rejection burned the only token), while
|
|
217
|
+
// ask mode has no token to preserve and must not reference one.
|
|
218
|
+
function assertNoPlaceholderSecret(args: string[], mode: ApprovalMode): void {
|
|
219
|
+
const placeholderArg = firstPlaceholderSecretArg(args);
|
|
220
|
+
if (!placeholderArg) return;
|
|
221
|
+
throw new Error(
|
|
222
|
+
`The argument "${placeholderArg}" still carries a placeholder secret value: replace <redacted> with the actual value the user approved, ` +
|
|
223
|
+
(mode === 'ask' ? 'then re-run.' : 'then re-run with the same approval token.'),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// The run options both approval modes execute under: allowWrites stays
|
|
228
|
+
// scoped to this file's call sites (the only ones in the codebase), and
|
|
229
|
+
// the pass-through fields keep their names verbatim.
|
|
230
|
+
function approvedRunOptions(args: ToolArgs): HcloudRunOptions {
|
|
231
|
+
return {
|
|
232
|
+
allowWrites: true,
|
|
233
|
+
timeoutMs: args.timeoutMs,
|
|
234
|
+
maxRetries: args.maxRetries,
|
|
235
|
+
cwd: args.cwd,
|
|
236
|
+
stdin: args.stdin,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Ask mode (DEVKIT_APPROVAL_MODE=ask): the harness client's permission
|
|
241
|
+
// prompt on this very call is the user's confirmation, so there is no
|
|
242
|
+
// token to inspect or consume. The safety floors are unchanged — the
|
|
243
|
+
// placeholder-secret guard above, and runHcloud's assertAllowed
|
|
244
|
+
// re-assertion of the strict classification (secret/credential/invalid
|
|
245
|
+
// denies still throw; allowWrites:true stays scoped to this one call
|
|
246
|
+
// site, the only one in the codebase).
|
|
247
|
+
async function runApprovedCommandAskMode(args: ToolArgs): Promise<unknown> {
|
|
248
|
+
const providedArgs = Array.isArray(args.args) ? args.args.map(String) : [];
|
|
249
|
+
// Same normalization as the token path: the strict plan and the executed
|
|
250
|
+
// argv must agree on the effective args.
|
|
251
|
+
const { args: effectiveArgs } = stripLeadingHcloudBinArgs(providedArgs);
|
|
252
|
+
assertNoPlaceholderSecret(effectiveArgs, 'ask');
|
|
253
|
+
const strictPlan = planHcloudCommand(effectiveArgs, {
|
|
254
|
+
allowWrites: false,
|
|
255
|
+
mintApprovalToken: false,
|
|
256
|
+
approvalMode: 'ask',
|
|
257
|
+
});
|
|
258
|
+
const result = await runHcloud(effectiveArgs, approvedRunOptions(args));
|
|
259
|
+
// Spread instead of in-place mutation, mirroring the token path: the
|
|
260
|
+
// HcloudRunResult shape stays owned by hcloud-cli.ts.
|
|
261
|
+
return { ...result, approved: true, plan: strictPlan };
|
|
262
|
+
}
|
|
263
|
+
|
|
204
264
|
async function runApprovedCommand(args: ToolArgs = {}) {
|
|
205
265
|
if (args.approvedByUser !== true) {
|
|
206
266
|
throw new Error('approvedByUser must be true after explicit user approval for this exact command.');
|
|
207
267
|
}
|
|
268
|
+
const approvalMode = approvalModeFromEnv(process.env);
|
|
269
|
+
if (approvalMode === 'ask') {
|
|
270
|
+
return runApprovedCommandAskMode(args);
|
|
271
|
+
}
|
|
208
272
|
const token = String(args.approvalToken || '');
|
|
209
273
|
|
|
210
274
|
// D4-24 precise JSON contract (#745): expired and already-consumed tokens
|
|
@@ -233,18 +297,9 @@ async function runApprovedCommand(args: ToolArgs = {}) {
|
|
|
233
297
|
// burned the single-use token on a mismatch (2026-11-05 UX report #6, the
|
|
234
298
|
// approval-trap probe).
|
|
235
299
|
const { args: effectiveArgs } = stripLeadingHcloudBinArgs(providedArgs);
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
|
|
239
|
-
// (replace the value, then re-run) stays followable on the same approval
|
|
240
|
-
// (loop round 3, seat-1 B3: the guidance used to be a dead end — the
|
|
241
|
-
// rejection burned the only token).
|
|
242
|
-
const placeholderArg = firstPlaceholderSecretArg(effectiveArgs);
|
|
243
|
-
if (placeholderArg) {
|
|
244
|
-
throw new Error(
|
|
245
|
-
`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.`,
|
|
246
|
-
);
|
|
247
|
-
}
|
|
300
|
+
// Placeholder guard before the consume: the shared helper's token-mode
|
|
301
|
+
// wording keeps the guidance followable on the same approval.
|
|
302
|
+
assertNoPlaceholderSecret(effectiveArgs, 'token');
|
|
248
303
|
|
|
249
304
|
// The strict plan is pure, so it is computed before the token is consumed:
|
|
250
305
|
// its userConfirmation.needed decides whether the consume requires a grant,
|
|
@@ -306,13 +361,7 @@ async function runApprovedCommand(args: ToolArgs = {}) {
|
|
|
306
361
|
);
|
|
307
362
|
}
|
|
308
363
|
}
|
|
309
|
-
const result = await runHcloud(effectiveArgs,
|
|
310
|
-
allowWrites: true,
|
|
311
|
-
timeoutMs: args.timeoutMs,
|
|
312
|
-
maxRetries: args.maxRetries,
|
|
313
|
-
cwd: args.cwd,
|
|
314
|
-
stdin: args.stdin,
|
|
315
|
-
});
|
|
364
|
+
const result = await runHcloud(effectiveArgs, approvedRunOptions(args));
|
|
316
365
|
// Spread instead of in-place mutation: identical serialized content, minus a
|
|
317
366
|
// write to the HcloudRunResult shape owned by hcloud-cli.ts.
|
|
318
367
|
return { ...result, approved: true, plan: strictPlan };
|
|
@@ -370,7 +419,10 @@ async function handleCheckCli(_args: ToolArgs = {}, _opts: CallToolOptions = {})
|
|
|
370
419
|
}
|
|
371
420
|
|
|
372
421
|
async function handlePlanCliCommand(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
|
|
373
|
-
return planHcloudCommand(args.args || [], {
|
|
422
|
+
return planHcloudCommand(args.args || [], {
|
|
423
|
+
allowWrites: args.allowWrites === true,
|
|
424
|
+
approvalMode: approvalModeFromEnv(process.env),
|
|
425
|
+
});
|
|
374
426
|
}
|
|
375
427
|
|
|
376
428
|
async function handleRunReadonlyCommand(args: ToolArgs = {}, _opts: CallToolOptions = {}) {
|
|
@@ -419,7 +471,12 @@ const listOperationsSchema = z.looseObject({
|
|
|
419
471
|
const runApprovedCommandSchema = z.looseObject({
|
|
420
472
|
vendorConfirmed,
|
|
421
473
|
args: stringArrayArg.describe('hcloud arguments, excluding the hcloud executable.'),
|
|
422
|
-
approvalToken: z
|
|
474
|
+
approvalToken: z
|
|
475
|
+
.string()
|
|
476
|
+
.optional()
|
|
477
|
+
.describe(
|
|
478
|
+
'Required in token-approval mode (from huaweicloud_plan_cli_command); omit in ask mode where the harness client confirms at run time.',
|
|
479
|
+
),
|
|
423
480
|
approvedByUser: booleanArg.describe('Must be true only after the user explicitly approves this exact command.'),
|
|
424
481
|
timeoutMs: numericArg.optional().describe('Optional timeout in milliseconds. Defaults to 60000.'),
|
|
425
482
|
maxRetries: numericArg.optional().describe('Optional retry count for transient network errors. Defaults to 1.'),
|
|
@@ -442,7 +499,7 @@ export const HUAWEICLOUD_CLI_TOOLS = [
|
|
|
442
499
|
{
|
|
443
500
|
name: 'huaweicloud_plan_cli_command',
|
|
444
501
|
description:
|
|
445
|
-
"Classify and plan a Huawei Cloud hcloud command without executing it. When the result's userConfirmation.needed is true, the
|
|
502
|
+
"Classify and plan a Huawei Cloud hcloud command without executing it. When the result's userConfirmation.needed is true, the command waits on user confirmation before huaweicloud_run_approved_command will accept it: in the default token mode the USER runs the userConfirmation.command line (npx huaweicloud-devkit approve <approvalToken>) in their own terminal, and under DEVKIT_APPROVAL_MODE=ask the harness client itself prompts the user on the run call — no token is needed. Vendor-gated (vendorConfirmed): call only when the vendor is established — see the vendorConfirmed parameter description; when unknown, ask which cloud the user means first.",
|
|
446
503
|
schema: planCliCommandSchema,
|
|
447
504
|
handler: handlePlanCliCommand,
|
|
448
505
|
},
|
|
@@ -463,7 +520,7 @@ export const HUAWEICLOUD_CLI_TOOLS = [
|
|
|
463
520
|
{
|
|
464
521
|
name: 'huaweicloud_run_approved_command',
|
|
465
522
|
description:
|
|
466
|
-
|
|
523
|
+
"Run a write-capable hcloud command only after the exact command has been shown and explicitly approved by the user. In the default token mode the user must also confirm 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. Under DEVKIT_APPROVAL_MODE=ask the harness client's permission prompt on this call is the confirmation: pass the same args with approvedByUser: true and no approvalToken. Vendor-gated (vendorConfirmed): call only when the vendor is established — see the vendorConfirmed parameter description; when unknown, ask which cloud the user means first.",
|
|
467
524
|
schema: runApprovedCommandSchema,
|
|
468
525
|
handler: handleRunApprovedCommand,
|
|
469
526
|
},
|
|
@@ -119,6 +119,7 @@ import { deployDsh, dshStatus, uninstallDsh } from './agents/dsh.ts';
|
|
|
119
119
|
import { dshDoctorMcpConfigured, dshPayloadDoctorSection } from './agents/dsh-patch.ts';
|
|
120
120
|
import {
|
|
121
121
|
deployOpenCode,
|
|
122
|
+
opencodeDoctorAskRule,
|
|
122
123
|
opencodeDoctorMcpConfigured,
|
|
123
124
|
opencodeDoctorSeam,
|
|
124
125
|
opencodeStatus,
|
|
@@ -1047,10 +1048,13 @@ async function cmdDoctor(): Promise<void> {
|
|
|
1047
1048
|
mcpCfgTarget ? `Found in ${mcpCfgTarget} config` : 'Run: npx huaweicloud-devkit install',
|
|
1048
1049
|
);
|
|
1049
1050
|
|
|
1050
|
-
//
|
|
1051
|
-
// agents/opencode.ts owns the per-glob kept/missing
|
|
1051
|
+
// OpenCode-only installer seams — the skills-tree permission check (the
|
|
1052
|
+
// section in agents/opencode.ts owns the per-glob kept/missing
|
|
1053
|
+
// evaluation) and the ASK approval posture check (the same file owns the
|
|
1054
|
+
// client-rule/server-env pair evaluation).
|
|
1052
1055
|
if (installedPayload?.id === 'opencode') {
|
|
1053
1056
|
opencodeDoctorSeam(ctx);
|
|
1057
|
+
opencodeDoctorAskRule(ctx);
|
|
1054
1058
|
}
|
|
1055
1059
|
|
|
1056
1060
|
// Hermes MCP Python SDK (only checked when Hermes config is found).
|