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
package/README.md
CHANGED
|
@@ -404,7 +404,7 @@ Debug logs are written to the plugin's `telemetry/telemetry-debug.log` file.
|
|
|
404
404
|
- **Sandbox (DevStation)** — temporary cloud runtime for web app deployment with instant public URL preview
|
|
405
405
|
- **Capability packs (56 MCP tools)** — the devkit ships ten packs (core 12 tools; huaweicloud-cli carries the 20 service skills plus the 7 KooCLI execution tools; sandbox, auth, obs, voucher, update, discovery, secrets, huaweicloud-open-mcp for the rest). The huaweicloud-open-mcp pack proxies Huawei Cloud's full OpenAPI catalog through the local huaweicloud-open-mcp gateway with one generic call tool (`huaweicloud_gateway_call`: search_apis → list_apis → get_api discovery, execute_api with gateway-engine-gated consent; install the gateway with pip or uv, or just have `uvx` on PATH — no persistent install needed). Discover packs with `huaweicloud_list_packs` → `huaweicloud_pack_info`, browse the effective skill catalog with `huaweicloud_list_skills` (every enabled pack's skills with name, description, version, and reference filenames in one call, plus `skillRoot` — the tree's absolute location; which skills are ENABLED is pack-gated and can change at runtime, so a `huawei-*` service skill absent from the catalog belongs to a trimmed pack — the six `huaweicloud-*` meta-skills never appear in it and are always available), read the skill files directly under `skillRoot` on a same-machine install (the stdio server instructions state the location at initialize, so no catalog call is needed just to start reading; the taught policy is action-first — attempt the direct read, the attempt itself is the reachability check), and fall back to `huaweicloud_retrieve_skill` only when the attempted read fails or is denied — the taught reaction is falling back (the loader needs no file access), never repeatedly requesting. (the gated, telemetry-bearing, portable fallback, whose stdio payload also carries `skillRoot`; the six core meta-skills are additionally installed as native skill copies on directory-loading agents for system-prompt visibility). Trim the surface with `DEVKIT_PACKS` (comma-separated pack ids, e.g. `DEVKIT_PACKS=core,sandbox`); unset means all packs, unknown ids fail fast at startup, and core (pack meta, safety and discovery surface) is always included — trimming huaweicloud-cli removes the CLI execution face and its approval tools together. In a live stdio agent session, `huaweicloud_packs_configure` enables or disables packs on the spot (session-scoped; the refreshed tool list is pushed to the agent, and restarting the session restores the operator posture; the stateless remote surface does not carry it). Manage the surface persistently after install with `npx huaweicloud-devkit packs status | enable <ids> | disable <ids> | all [--target <agent>]`: the command rewrites `DEVKIT_PACKS` inside every installed agent's MCP config (the install-time `--packs` flag never overwrites an existing value), and the change takes effect on the agent's next session restart.
|
|
406
406
|
|
|
407
|
-
Harness permission notes (skill-tree reads outside the workspace): the taught reaction above is universal — when a direct read fails or is denied, fall back to `huaweicloud_retrieve_skill`, never repeatedly request. The OpenCode installer writes a persistent permission seam (external_directory allow + edit deny over the tree globs); on other harnesses the operator can pre-allow the tree in the harness's own config if prompts bother them. Honest semantics for the seam: the allow covers every path-taking tool including bash (an allowed external directory inherits workspace defaults), so shell-mediated writes to the tree stop asking too — the edit deny governs only the edit tools; the tree is regenerated on every install/update, and the devkit's PreToolUse hook still denies hcloud writes.
|
|
407
|
+
Harness permission notes (skill-tree reads outside the workspace): the taught reaction above is universal — when a direct read fails or is denied, fall back to `huaweicloud_retrieve_skill`, never repeatedly request. The OpenCode installer writes a persistent permission seam (external_directory allow + edit deny over the tree globs); on other harnesses the operator can pre-allow the tree in the harness's own config if prompts bother them. Honest semantics for the seam: the allow covers every path-taking tool including bash (an allowed external directory inherits workspace defaults), so shell-mediated writes to the tree stop asking too — the edit deny governs only the edit tools; the tree is regenerated on every install/update, and the devkit's PreToolUse hook still denies hcloud writes. On opencode >= 2.0 the installer additionally writes the ASK approval posture — a top-level `permissions` entry with effect `ask` on the `huaweicloud-devkit_huaweicloud_run_approved_command` action plus `DEVKIT_APPROVAL_MODE=ask` in the mcp entry's environment — so every hcloud write makes OpenCode itself prompt (no terminal approve trip, no token UUID; below 2.0 neither half is written). Honest residual for that posture: answering OpenCode's prompt with "Allow always" saves an `allow` rule on the same action that removes the gate — `npx huaweicloud-devkit doctor` fails that state; see the huaweicloud-safety skill's approvals reference.
|
|
408
408
|
|
|
409
409
|
| Harness | Outside-workspace reads | Operator relief |
|
|
410
410
|
| ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
3
|
"mcpName": "io.github.huaweicloud/huaweicloud-devkit",
|
|
4
|
-
"version": "2.0.0-next.
|
|
4
|
+
"version": "2.0.0-next.3",
|
|
5
5
|
"kooCliVersion": "7.3.12",
|
|
6
6
|
"description": "Agent toolkit that helps coding agents use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities safely and accurately.",
|
|
7
7
|
"type": "module",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"mcpServers": "./.mcp.json",
|
|
18
18
|
"description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
|
|
19
|
-
"version": "2.0.0-next.
|
|
19
|
+
"version": "2.0.0-next.3",
|
|
20
20
|
"author": {
|
|
21
21
|
"name": "HuaweiCloud Mate",
|
|
22
22
|
"url": "https://github.com/huaweicloud"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"mcpServers": "./.mcp.json",
|
|
21
21
|
"description": "Agent toolkit that helps coding agents use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities safely and accurately.",
|
|
22
|
-
"version": "2.0.0-next.
|
|
22
|
+
"version": "2.0.0-next.3",
|
|
23
23
|
"author": {
|
|
24
24
|
"name": "HuaweiCloud Mate",
|
|
25
25
|
"url": "https://github.com/huaweicloud"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"mcpServers": "./.mcp.json",
|
|
18
18
|
"description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
|
|
19
|
-
"version": "2.0.0-next.
|
|
19
|
+
"version": "2.0.0-next.3",
|
|
20
20
|
"author": {
|
|
21
21
|
"name": "HuaweiCloud Mate",
|
|
22
22
|
"url": "https://github.com/huaweicloud"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.3",
|
|
4
4
|
"description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "HuaweiCloud Mate",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "huaweicloud-devkit",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.3",
|
|
4
4
|
"description": "Guide coding agents to use Huawei Cloud Skills, KooCLI, APIs, SDKs, and future MCP capabilities with safer execution and less context.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "HuaweiCloud Mate",
|
|
@@ -15,6 +15,7 @@ import { mergeCommandStyle, extractUserDelta, applyUserDelta } from "../mcp-conf
|
|
|
15
15
|
import { saveAgentDelta, takeAgentDelta } from "../mcp-config-backup.js";
|
|
16
16
|
import { readJsonRecord, writeMcpSettingsFile } from "../mcp-config-io.js";
|
|
17
17
|
import { applySkillTreePermissionSeam, opencodeSeamVersionSupported, removeSkillTreePermissionSeam, skillTreePermissionGlobs, } from "../lib/opencode-permission-seam.js";
|
|
18
|
+
import { ASK_RULE_ACTION, applyAskPermissionRule, opencodeAskRuleVersionSupported, removeAskPermissionRule, } from "../lib/opencode-ask-rule.js";
|
|
18
19
|
import { asRecord } from "../lib/as-record.js";
|
|
19
20
|
import { devkitOwnedSkillNames, tryCoreSkillNames } from "../install-payload.js";
|
|
20
21
|
// The seam's version gate. HUAWEICLOUD_OPENCODE_PERMISSION_SEAM=on|off is
|
|
@@ -87,6 +88,41 @@ export function openCodeSeamGate() {
|
|
|
87
88
|
return forced;
|
|
88
89
|
return opencodeSeamVersionSupported(probeOpencodeVersion()) ? 'on' : 'off';
|
|
89
90
|
}
|
|
91
|
+
// The ask rule's version gate, same doctrine as the seam's:
|
|
92
|
+
// HUAWEICLOUD_OPENCODE_ASK_RULE=on|off is the deterministic override for
|
|
93
|
+
// the installer test suite (e2e strips it — the runner's install relies on
|
|
94
|
+
// the natural probe); unset runs the probe. Unknown polarity is off: the
|
|
95
|
+
// `permissions` array is the V2 shape measured on 2.2.7 only, so a
|
|
96
|
+
// below-2.0, absent, or unparsable opencode writes NEITHER half of the
|
|
97
|
+
// posture — the client rule without the server env double-gates, the env
|
|
98
|
+
// without the rule fail-opens, and the pair must move together.
|
|
99
|
+
export function openCodeAskGate() {
|
|
100
|
+
const forced = process.env.HUAWEICLOUD_OPENCODE_ASK_RULE;
|
|
101
|
+
if (forced === 'on' || forced === 'off')
|
|
102
|
+
return forced;
|
|
103
|
+
return opencodeAskRuleVersionSupported(probeOpencodeVersion()) ? 'on' : 'off';
|
|
104
|
+
}
|
|
105
|
+
// The server half of the ask posture: DEVKIT_APPROVAL_MODE=ask in the mcp
|
|
106
|
+
// entry's environment (the field OpenCode reads — the applyPacksToEntry
|
|
107
|
+
// 'environment' precedent). Add-only-if-absent with the packs-write
|
|
108
|
+
// doctrine: a user-set value other than 'ask' is theirs and wins with a
|
|
109
|
+
// one-line WARN; 'ask' already present needs no write. An absent or empty
|
|
110
|
+
// environment object is created. No delete path: uninstall removes the
|
|
111
|
+
// whole mcp entry wholesale. Runs ONLY under the ask gate — see
|
|
112
|
+
// openCodeAskGate for why the halves must move together.
|
|
113
|
+
function applyApprovalModeToEntry(entry) {
|
|
114
|
+
const env = asRecord(entry.environment);
|
|
115
|
+
const current = env.DEVKIT_APPROVAL_MODE;
|
|
116
|
+
if (current === 'ask')
|
|
117
|
+
return false;
|
|
118
|
+
if (current !== undefined) {
|
|
119
|
+
const shown = typeof current === 'string' ? current : JSON.stringify(current);
|
|
120
|
+
console.log(` \x1b[33m[WARN]\x1b[0m OpenCode mcp entry already sets DEVKIT_APPROVAL_MODE=${shown} — keeping the user's value; it may not match the permissions ask rule (see README, Harness permission notes).`);
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
entry.environment = { ...env, DEVKIT_APPROVAL_MODE: 'ask' };
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
90
126
|
// The glob set the seam covers: the plugin-dir tree actually deployed by
|
|
91
127
|
// this run plus per-skill globs for the native core meta-skill copies
|
|
92
128
|
// (under the XDG opencode skills dir). An unusable manifest degrades to the
|
|
@@ -129,11 +165,30 @@ export function updateOpenCodeConfig(pluginDir) {
|
|
|
129
165
|
else {
|
|
130
166
|
console.log(' \x1b[33m[INFO]\x1b[0m opencode not verifiably at or above the measured permission floor — skipping the skills-tree permission write; see README (Harness permission notes) if direct skill reads prompt for approval.');
|
|
131
167
|
}
|
|
168
|
+
const askOn = openCodeAskGate() === 'on';
|
|
169
|
+
// The ask rule is a FOURTH change source, computed before the unchanged
|
|
170
|
+
// short-circuit for the same reason as the seam: an unchanged mcp entry
|
|
171
|
+
// is the dominant update shape, and every install made before the ask
|
|
172
|
+
// posture existed is exactly the population this must heal. The rule
|
|
173
|
+
// mutates config in place (ownership rules in lib/opencode-ask-rule.ts),
|
|
174
|
+
// so the single write below carries it.
|
|
175
|
+
let askRuleChanged = false;
|
|
176
|
+
if (askOn) {
|
|
177
|
+
const applied = applyAskPermissionRule(config);
|
|
178
|
+
askRuleChanged = applied.changed;
|
|
179
|
+
if (applied.skipped) {
|
|
180
|
+
console.log(` \x1b[33m[WARN]\x1b[0m opencode permissions already has an entry for ${ASK_RULE_ACTION} — keeping it as the user's (the posture follows its effect; see README, Harness permission notes).`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
console.log(' \x1b[33m[INFO]\x1b[0m opencode not verifiably at or above 2.0 — keeping the terminal token approval gate; no permissions ask rule or DEVKIT_APPROVAL_MODE is written.');
|
|
185
|
+
}
|
|
132
186
|
const existing = asRecord(config.mcp)['huaweicloud-devkit'];
|
|
133
187
|
if (existing) {
|
|
134
188
|
const { entry, changed } = mergeCommandStyle(existing, { mcpPath });
|
|
135
189
|
const packsChanged = applyPacksToEntry(entry, 'environment', 'OpenCode');
|
|
136
|
-
|
|
190
|
+
const askEnvChanged = askOn && applyApprovalModeToEntry(entry);
|
|
191
|
+
if (!changed && !packsChanged && !permChanged && !askRuleChanged && !askEnvChanged) {
|
|
137
192
|
console.log(` OpenCode MCP config unchanged: ${configPath}`);
|
|
138
193
|
return;
|
|
139
194
|
}
|
|
@@ -142,6 +197,9 @@ export function updateOpenCodeConfig(pluginDir) {
|
|
|
142
197
|
config.mcp = mcpMap;
|
|
143
198
|
writeMcpSettingsFile(configPath, config);
|
|
144
199
|
console.log(` OpenCode MCP config merged (user fields preserved): ${configPath}`);
|
|
200
|
+
if (askRuleChanged || askEnvChanged) {
|
|
201
|
+
console.log(` ASK approval (permissions ask rule + DEVKIT_APPROVAL_MODE) -> ${configPath}`);
|
|
202
|
+
}
|
|
145
203
|
return;
|
|
146
204
|
}
|
|
147
205
|
const mcpMap = asRecord(config.mcp);
|
|
@@ -152,10 +210,14 @@ export function updateOpenCodeConfig(pluginDir) {
|
|
|
152
210
|
if (delta)
|
|
153
211
|
entry = asRecord(applyUserDelta(entry, delta, 'command'));
|
|
154
212
|
applyPacksToEntry(entry, 'environment', 'OpenCode');
|
|
213
|
+
const askEnvChanged = askOn && applyApprovalModeToEntry(entry);
|
|
155
214
|
mcpMap['huaweicloud-devkit'] = entry;
|
|
156
215
|
config.mcp = mcpMap;
|
|
157
216
|
writeMcpSettingsFile(configPath, config);
|
|
158
217
|
console.log(` OpenCode config updated: ${configPath}`);
|
|
218
|
+
if (askRuleChanged || askEnvChanged) {
|
|
219
|
+
console.log(` ASK approval (permissions ask rule + DEVKIT_APPROVAL_MODE) -> ${configPath}`);
|
|
220
|
+
}
|
|
159
221
|
}
|
|
160
222
|
export function removeOpenCodeConfig() {
|
|
161
223
|
const configPath = opencodeConfigFile();
|
|
@@ -182,11 +244,20 @@ export function removeOpenCodeConfig() {
|
|
|
182
244
|
// value-exact deletion keeps user-modified rules (the ownership contract
|
|
183
245
|
// lives in lib/opencode-permission-seam.ts).
|
|
184
246
|
const permCleaned = removeSkillTreePermissionSeam(config, openCodeSeamGlobs(opencodePluginsDir()));
|
|
185
|
-
|
|
247
|
+
// The ask-rule cleanup also runs unconditionally of the version gate: an
|
|
248
|
+
// uninstall must remove what any past install wrote — the opencode that
|
|
249
|
+
// gated the write may since have been upgraded, downgraded, or removed
|
|
250
|
+
// from PATH. Value-exact deletion keeps user-modified entries (the
|
|
251
|
+
// ownership contract lives in lib/opencode-ask-rule.ts); the mcp entry
|
|
252
|
+
// (and its DEVKIT_APPROVAL_MODE env) is already gone wholesale above.
|
|
253
|
+
const askCleaned = removeAskPermissionRule(config);
|
|
254
|
+
if (!hadEntry && !permCleaned && !askCleaned)
|
|
186
255
|
return;
|
|
187
256
|
writeMcpSettingsFile(configPath, config);
|
|
188
257
|
if (hadEntry)
|
|
189
258
|
console.log(` OpenCode MCP config cleaned: ${configPath}`);
|
|
190
259
|
if (permCleaned)
|
|
191
260
|
console.log(` Skills-tree permission rules removed: ${configPath}`);
|
|
261
|
+
if (askCleaned)
|
|
262
|
+
console.log(` ASK permission rule removed: ${configPath}`);
|
|
192
263
|
}
|
|
@@ -9,7 +9,8 @@ import { join } from 'node:path';
|
|
|
9
9
|
import { configRoot, opencodeCommandsDir, opencodeConfigFile, opencodePluginsDir, opencodeSkillsDir, } from "../targets.js";
|
|
10
10
|
import { printMcpConfigStatus } from "../mcp-config-io.js";
|
|
11
11
|
import { PACKAGE_ROOT, copyDir, copyServerPayload, deployWord, installRuntimeDeps, payloadStatusLines, pruneStale, removeHuaweiCommandsFrom, removeIfExists, } from "../install-payload.js";
|
|
12
|
-
import { removeOpenCodeConfig, updateOpenCodeConfig, openCodeSeamGate, openCodeSeamGlobs } from "./opencode-config.js";
|
|
12
|
+
import { removeOpenCodeConfig, updateOpenCodeConfig, openCodeSeamGate, openCodeSeamGlobs, openCodeAskGate, } from "./opencode-config.js";
|
|
13
|
+
import { inspectAskPermissionRule } from "../lib/opencode-ask-rule.js";
|
|
13
14
|
import { asRecord } from "../lib/as-record.js";
|
|
14
15
|
// Doctor: the OpenCode MCP-configured candidate — the opencode config's
|
|
15
16
|
// mcp.huaweicloud-devkit entry.
|
|
@@ -27,6 +28,66 @@ export function opencodeDoctorMcpConfigured() {
|
|
|
27
28
|
}
|
|
28
29
|
return null;
|
|
29
30
|
}
|
|
31
|
+
// Doctor: the ASK approval posture check — OpenCode installs only. The
|
|
32
|
+
// posture is a PAIR: the client half (the permissions ask rule that makes
|
|
33
|
+
// opencode itself prompt on huaweicloud_run_approved_command) and the
|
|
34
|
+
// server half (DEVKIT_APPROVAL_MODE=ask in the mcp entry's env). A
|
|
35
|
+
// gate-off opencode is a SKIP — token mode is that install's legitimate
|
|
36
|
+
// posture — and so are configs the installer itself refuses to touch.
|
|
37
|
+
// Every mixed state is a FAIL because each lies in a known direction:
|
|
38
|
+
// the rule without the env double-gates (the client prompts AND the
|
|
39
|
+
// server still demands a token), the env without the rule fail-opens
|
|
40
|
+
// (the server trusts a prompt nobody shows), and an allow/deny rule
|
|
41
|
+
// destroys the ask contract outright ("always allow" stops prompting;
|
|
42
|
+
// deny bricks the write tool entirely).
|
|
43
|
+
export function opencodeDoctorAskRule(ctx) {
|
|
44
|
+
if (openCodeAskGate() === 'off') {
|
|
45
|
+
ctx.skip('ASK approval posture (opencode not verifiably at or above 2.0)');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
let cfg;
|
|
49
|
+
try {
|
|
50
|
+
cfg = asRecord(JSON.parse(readFileSync(opencodeConfigFile(), 'utf8')));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
cfg = null;
|
|
54
|
+
}
|
|
55
|
+
const posture = cfg !== null ? inspectAskPermissionRule(cfg) : null;
|
|
56
|
+
if (cfg === null || posture === 'foreign') {
|
|
57
|
+
ctx.skip('ASK approval posture: opencode config unreadable or permissions not array-shaped — the installer keeps it untouched; add the ask rule and DEVKIT_APPROVAL_MODE manually (see README, Harness permission notes)');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// The mcp entry carries the server half; a missing entry counts as no
|
|
61
|
+
// env, so the halves are judged independently of entry presence.
|
|
62
|
+
const env = asRecord(asRecord(asRecord(cfg.mcp)['huaweicloud-devkit']).environment);
|
|
63
|
+
const envAsk = env.DEVKIT_APPROVAL_MODE === 'ask';
|
|
64
|
+
const label = 'ASK approval posture (client prompt + server env)';
|
|
65
|
+
if (posture === 'ask') {
|
|
66
|
+
ctx.check(label, envAsk, envAsk
|
|
67
|
+
? ''
|
|
68
|
+
: 'DEVKIT_APPROVAL_MODE=ask missing from the mcp entry — the client prompts AND the server still demands a token (re-run: npx huaweicloud-devkit install --target opencode)');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (posture === 'allow') {
|
|
72
|
+
// FAIL, never a warn: with the env also ask this is fail-open (the
|
|
73
|
+
// always-allow rule suppresses the prompt the server trusts); without
|
|
74
|
+
// it the run degrades to the token gate. Either way the ask contract
|
|
75
|
+
// is silently gone.
|
|
76
|
+
ctx.check(label, false, 'the permissions rule for the run tool is "allow" (always allow) — writes no longer prompt: fail-open when DEVKIT_APPROVAL_MODE=ask, a plain token gate otherwise. Delete that rule or set its effect to "ask" (see README, Harness permission notes)');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (posture === 'deny') {
|
|
80
|
+
ctx.check(label, false, 'the permissions rule for the run tool is "deny" — the write tool is blocked entirely. Delete that rule or set its effect to "ask" (see README, Harness permission notes)');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (envAsk) {
|
|
84
|
+
// posture === 'absent': the fail-open direction.
|
|
85
|
+
ctx.check(label, false, 'DEVKIT_APPROVAL_MODE=ask is set but the permissions ask rule is missing — the server trusts a client prompt nobody shows (re-run: npx huaweicloud-devkit install --target opencode, or unset DEVKIT_APPROVAL_MODE in the mcp entry)');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// Token mode is the legitimate default posture, not an error.
|
|
89
|
+
ctx.check('ASK approval posture (token mode)', true, '');
|
|
90
|
+
}
|
|
30
91
|
// Doctor: the skills-tree permission seam check — OpenCode installs only
|
|
31
92
|
// (the seam is the installer's zero-prompt path for direct skill reads on
|
|
32
93
|
// that harness). Verifies the two keys and their values, honoring the
|
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
// classification, OBS/SG/parameter warnings, required-parameter
|
|
5
5
|
// validation, and the approval token. The consent layer itself lives in
|
|
6
6
|
// src/lib/approval-tokens.ts.
|
|
7
|
+
//
|
|
8
|
+
// The plan's approval posture is mode-dependent (HcloudPlanOptions.
|
|
9
|
+
// approvalMode): 'ask' (DEVKIT_APPROVAL_MODE=ask) plans for the harness
|
|
10
|
+
// client's own permission prompt as the user's confirmation, so no token
|
|
11
|
+
// is minted and userConfirmation carries the ask note instead of a
|
|
12
|
+
// terminal approve line; 'token' (the default) keeps the mint + approve
|
|
13
|
+
// line contract above.
|
|
7
14
|
import { classifyHcloudArgs, redactSecrets, stripExecutable } from "./safety-policy.js";
|
|
8
15
|
import { isHcloudToken } from "./safety/tokens.js";
|
|
9
16
|
import { createApprovalToken } from "./lib/approval-tokens.js";
|
|
@@ -287,7 +294,12 @@ export function planHcloudCommand(args, options = {}) {
|
|
|
287
294
|
warnings.push(`${triage.message} ${triage.nextStep}`);
|
|
288
295
|
}
|
|
289
296
|
}
|
|
290
|
-
const
|
|
297
|
+
const approvalMode = options.approvalMode ?? 'token';
|
|
298
|
+
// Ask mode never mints: the confirmation is the harness client's prompt
|
|
299
|
+
// on the run call, so there is no token to hand the model and nothing
|
|
300
|
+
// lands in the approvals store. Run paths keep mintApprovalToken:false
|
|
301
|
+
// in both modes.
|
|
302
|
+
const approvalToken = approvalMode === 'ask' || options.mintApprovalToken === false
|
|
291
303
|
? undefined
|
|
292
304
|
: createApprovalToken(normalizedArgs, {
|
|
293
305
|
secretsSubstitutable: secretsSubstitutable(normalizedArgs),
|
|
@@ -309,11 +321,19 @@ export function planHcloudCommand(args, options = {}) {
|
|
|
309
321
|
...(approvalToken !== undefined ? { approvalToken } : {}),
|
|
310
322
|
// `command` exists only where a token was minted: a run-path plan stays
|
|
311
323
|
// silent rather than name a line for a token the run cannot offer.
|
|
324
|
+
// Ask mode names the posture instead — the confirmation happens at the
|
|
325
|
+
// run call, and the note teaches exactly that.
|
|
312
326
|
userConfirmation: needsConfirmation
|
|
313
|
-
?
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
327
|
+
? approvalMode === 'ask'
|
|
328
|
+
? {
|
|
329
|
+
needed: true,
|
|
330
|
+
mode: 'ask',
|
|
331
|
+
note: 'The harness client confirms this command with the user when huaweicloud_run_approved_command is called. Call it with the same args and approvedByUser: true. No terminal approval line or token is needed.',
|
|
332
|
+
}
|
|
333
|
+
: {
|
|
334
|
+
needed: true,
|
|
335
|
+
...(approvalToken !== undefined ? { command: `npx huaweicloud-devkit approve ${approvalToken}` } : {}),
|
|
336
|
+
}
|
|
317
337
|
: { needed: false },
|
|
318
338
|
safeToRun: effectiveClassification.decision === 'allow',
|
|
319
339
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The hcloud write-approval posture, resolved from DEVKIT_APPROVAL_MODE.
|
|
2
|
+
//
|
|
3
|
+
// 'token' (the default) is the out-of-band terminal gate: the plan mints
|
|
4
|
+
// an approval token, the user confirms it in their own terminal
|
|
5
|
+
// (`npx huaweicloud-devkit approve <uuid>`), and run_approved_command
|
|
6
|
+
// consumes the token before executing. 'ask' moves the confirmation onto
|
|
7
|
+
// the harness client's own permission prompt: the operator opts in via
|
|
8
|
+
// the env var (normally written by the installer together with the
|
|
9
|
+
// client's ask rule), and accepting that client prompt IS the user's
|
|
10
|
+
// confirmation — no terminal trip, no UUID in the model's context; the
|
|
11
|
+
// plan mints nothing and the run needs only approvedByUser.
|
|
12
|
+
//
|
|
13
|
+
// Resolution is exact-match and fail-loud, mirroring the DEVKIT_PACKS
|
|
14
|
+
// unknown-id doctrine: a typo'd mode must not silently fall back to the
|
|
15
|
+
// weaker gate, so anything but 'ask' or 'token' throws with the env name
|
|
16
|
+
// and the bad value (case included — 'ASK' throws). Unset or empty keeps
|
|
17
|
+
// 'token'. The resolver is pure and takes the env as a parameter; every
|
|
18
|
+
// reader re-resolves from process.env (the mode is process-stable for the
|
|
19
|
+
// life of the process), so there is deliberately no cached module state
|
|
20
|
+
// to disagree with a fresh read. The module imports nothing: it feeds
|
|
21
|
+
// both the bundled mcp-server graph and the unbundled setup-cli graph.
|
|
22
|
+
export const APPROVAL_MODE_ENV = 'DEVKIT_APPROVAL_MODE';
|
|
23
|
+
export function approvalModeFromEnv(env) {
|
|
24
|
+
const raw = env[APPROVAL_MODE_ENV];
|
|
25
|
+
if (raw === undefined || raw === '')
|
|
26
|
+
return 'token';
|
|
27
|
+
if (raw === 'ask' || raw === 'token')
|
|
28
|
+
return raw;
|
|
29
|
+
throw new Error(`DEVKIT_APPROVAL_MODE must be "ask" or "token" (got "${raw}")`);
|
|
30
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
import { asRecord } from "./as-record.js";
|
|
31
|
+
export const ASK_RULE_ACTION = 'huaweicloud-devkit_huaweicloud_run_approved_command';
|
|
32
|
+
export const ASK_RULE_RESOURCE = '*';
|
|
33
|
+
function isRuleRecord(value) {
|
|
34
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
35
|
+
}
|
|
36
|
+
// Mutates config in place. Fresh configs get the single-entry array;
|
|
37
|
+
// arrays without an entry on the ask action get ours APPENDED — OpenCode
|
|
38
|
+
// evaluates last-matching-rule-wins, so the appended entry is the
|
|
39
|
+
// effective one. Arrays that already carry an entry on the action, and
|
|
40
|
+
// non-array `permissions` shapes, are the user's: nothing is written.
|
|
41
|
+
export function applyAskPermissionRule(config) {
|
|
42
|
+
if (config.permissions === undefined) {
|
|
43
|
+
config.permissions = [{ action: ASK_RULE_ACTION, resource: ASK_RULE_RESOURCE, effect: 'ask' }];
|
|
44
|
+
return { changed: true, skipped: false };
|
|
45
|
+
}
|
|
46
|
+
if (!Array.isArray(config.permissions)) {
|
|
47
|
+
return { changed: false, skipped: true };
|
|
48
|
+
}
|
|
49
|
+
const rules = config.permissions;
|
|
50
|
+
if (rules.some((rule) => isRuleRecord(rule) && rule.action === ASK_RULE_ACTION)) {
|
|
51
|
+
return { changed: false, skipped: true };
|
|
52
|
+
}
|
|
53
|
+
rules.push({ action: ASK_RULE_ACTION, resource: ASK_RULE_RESOURCE, effect: 'ask' });
|
|
54
|
+
return { changed: true, skipped: false };
|
|
55
|
+
}
|
|
56
|
+
// Mutates config in place. Value-exact deletion only — an entry matching
|
|
57
|
+
// action + resource '*' + effect 'ask' exactly is ours; a user-modified
|
|
58
|
+
// entry (any other effect or resource) survives. The array key is pruned
|
|
59
|
+
// only when OUR removals emptied it; a pre-existing empty array is left
|
|
60
|
+
// untouched. Returns whether anything changed.
|
|
61
|
+
export function removeAskPermissionRule(config) {
|
|
62
|
+
if (!Array.isArray(config.permissions))
|
|
63
|
+
return false;
|
|
64
|
+
const rules = config.permissions;
|
|
65
|
+
const kept = rules.filter((rule) => !(isRuleRecord(rule) &&
|
|
66
|
+
rule.action === ASK_RULE_ACTION &&
|
|
67
|
+
rule.resource === ASK_RULE_RESOURCE &&
|
|
68
|
+
rule.effect === 'ask'));
|
|
69
|
+
if (kept.length === rules.length)
|
|
70
|
+
return false;
|
|
71
|
+
if (kept.length === 0) {
|
|
72
|
+
delete config.permissions;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
config.permissions = kept;
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
// The effective posture of the ask action. OpenCode evaluates
|
|
80
|
+
// last-matching-rule-wins, so the LAST entry on the action is the
|
|
81
|
+
// effective one — read that, never the first. Returns its effect
|
|
82
|
+
// ('ask' / 'allow' / 'deny'), 'absent' when no entry matches (or the
|
|
83
|
+
// array is empty / the key is missing), and 'foreign' for an unreadable
|
|
84
|
+
// posture: `permissions` present but not an array, or the last matching
|
|
85
|
+
// entry carrying an effect outside the allow/ask/deny vocabulary.
|
|
86
|
+
export function inspectAskPermissionRule(config) {
|
|
87
|
+
if (config.permissions === undefined)
|
|
88
|
+
return 'absent';
|
|
89
|
+
if (!Array.isArray(config.permissions))
|
|
90
|
+
return 'foreign';
|
|
91
|
+
const rules = config.permissions;
|
|
92
|
+
for (let i = rules.length - 1; i >= 0; i--) {
|
|
93
|
+
const rule = asRecord(rules[i]);
|
|
94
|
+
if (rule.action !== ASK_RULE_ACTION)
|
|
95
|
+
continue;
|
|
96
|
+
if (rule.effect === 'ask' || rule.effect === 'allow' || rule.effect === 'deny') {
|
|
97
|
+
return rule.effect;
|
|
98
|
+
}
|
|
99
|
+
return 'foreign';
|
|
100
|
+
}
|
|
101
|
+
return 'absent';
|
|
102
|
+
}
|
|
103
|
+
// Floor check for the probe result: the `permissions` array is the
|
|
104
|
+
// documented V2 shape, measured on 2.2.7 only. Opencode major >= 2 (the
|
|
105
|
+
// anchored `v<major>.` form, mirroring opencodeSeamVersionSupported's
|
|
106
|
+
// extract-not-pass-raw polarity); null and unparsable output are
|
|
107
|
+
// unsupported — the caller's polarity is skip, keeping BOTH the terminal
|
|
108
|
+
// token gate and its mcp env untouched rather than guessing.
|
|
109
|
+
export function opencodeAskRuleVersionSupported(version) {
|
|
110
|
+
if (version === null)
|
|
111
|
+
return false;
|
|
112
|
+
const match = /^v?(\d+)\./.exec(version.trim());
|
|
113
|
+
if (!match)
|
|
114
|
+
return false;
|
|
115
|
+
return Number(match[1]) >= 2;
|
|
116
|
+
}
|
|
@@ -8,6 +8,7 @@ import { peekCachedUpdateInfo, applyUpdateHint, readInstalledVersion } from "./u
|
|
|
8
8
|
import { initTelemetry } from "./telemetry/telemetry.js";
|
|
9
9
|
import { detectAgent } from "./telemetry/agent-detect.js";
|
|
10
10
|
import { asRecord } from "./lib/as-record.js";
|
|
11
|
+
import { approvalModeFromEnv } from "./lib/approval-mode.js";
|
|
11
12
|
const pkgVersion = readInstalledVersion() || '0.0.0';
|
|
12
13
|
// Server-level instructions ride the initialize handshake result — the one
|
|
13
14
|
// teaching surface that needs neither a skill load nor a description read.
|
|
@@ -217,6 +218,11 @@ export function normalizeToolCallParams(message) {
|
|
|
217
218
|
}
|
|
218
219
|
export function createDevkitMcpServer({ sessionId, runtimePacks = false, remoteSurface = false, } = {}) {
|
|
219
220
|
assertConstructedSchemas();
|
|
221
|
+
// The approval posture resolves once at construction: a bogus
|
|
222
|
+
// DEVKIT_APPROVAL_MODE throws here (boot fail-fast, the same doctrine
|
|
223
|
+
// DEVKIT_PACKS applies through syncDisclosure), and registerOne below is
|
|
224
|
+
// the one place the mode changes the wire surface.
|
|
225
|
+
const askMode = approvalModeFromEnv(process.env) === 'ask';
|
|
220
226
|
// The contradictory construction is refused, not cautioned: a remote that
|
|
221
227
|
// also carried runtime pack toggling would attach the onPacksChanged seam
|
|
222
228
|
// to every callOpts, publishing the server host's absolute install path
|
|
@@ -270,7 +276,20 @@ export function createDevkitMcpServer({ sessionId, runtimePacks = false, remoteS
|
|
|
270
276
|
(runtimePacks || tool.name !== 'huaweicloud_packs_configure') &&
|
|
271
277
|
(!remoteSurface || (PACK_OF[tool.name] !== 'secrets' && !REMOTE_WITHHELD_LOCAL_WRITERS.has(tool.name)));
|
|
272
278
|
const registerOne = (tool) => {
|
|
273
|
-
registered.set(tool.name, server.registerTool(tool.name, {
|
|
279
|
+
registered.set(tool.name, server.registerTool(tool.name, {
|
|
280
|
+
description: tool.description,
|
|
281
|
+
inputSchema: getToolSchema(tool.name),
|
|
282
|
+
// Ask mode only: Claude Code honors this flag by prompting the
|
|
283
|
+
// user on every call of this tool — even in acceptEdits/auto/
|
|
284
|
+
// bypassPermissions modes, with no "don't ask again" — and that
|
|
285
|
+
// client prompt IS the user's confirmation the mode trusts.
|
|
286
|
+
// Other clients ignore the flag. Declared only in ask mode so
|
|
287
|
+
// token-mode Claude Code users don't gain a second prompt on top
|
|
288
|
+
// of the terminal approve they already run.
|
|
289
|
+
...(askMode && tool.name === 'huaweicloud_run_approved_command'
|
|
290
|
+
? { _meta: { 'anthropic/requiresUserInteraction': true } }
|
|
291
|
+
: {}),
|
|
292
|
+
}, async (args) => {
|
|
274
293
|
const callOpts = runtimePacks
|
|
275
294
|
? { sessionId, onPacksChanged: () => syncDisclosure() }
|
|
276
295
|
: { sessionId };
|