huaweicloud-devkit 2.0.0-next.1 → 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 +3 -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/codearts-work.js +4 -0
- package/plugins/huaweicloud-core/dist/agents/codearts.js +4 -0
- 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/auth/s1-store.js +43 -22
- 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/approval-tokens.js +3 -3
- package/plugins/huaweicloud-core/dist/lib/opencode-ask-rule.js +116 -0
- package/plugins/huaweicloud-core/dist/lib/pack-state.js +23 -19
- package/plugins/huaweicloud-core/dist/lib/param-warnings.js +70 -0
- package/plugins/huaweicloud-core/dist/lib/state-dir.js +125 -0
- package/plugins/huaweicloud-core/dist/mcp-protocol.js +20 -1
- package/plugins/huaweicloud-core/dist/mcp-server.js +849 -585
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
- package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +74 -22
- package/plugins/huaweicloud-core/dist/setup-cli.js +22 -3
- package/plugins/huaweicloud-core/dist/tool-schemas.js +15 -0
- package/plugins/huaweicloud-core/dist/tools.js +36 -4
- package/plugins/huaweicloud-core/dist/update-skip.js +5 -6
- package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +78 -2
- 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/codearts-work.ts +3 -0
- package/plugins/huaweicloud-core/src/agents/codearts.ts +4 -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/auth/s1-store.ts +41 -20
- 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/approval-tokens.ts +3 -3
- package/plugins/huaweicloud-core/src/lib/opencode-ask-rule.ts +131 -0
- package/plugins/huaweicloud-core/src/lib/pack-state.ts +23 -20
- package/plugins/huaweicloud-core/src/lib/param-warnings.ts +69 -0
- package/plugins/huaweicloud-core/src/lib/state-dir.ts +128 -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 +27 -2
- package/plugins/huaweicloud-core/src/tool-schemas.ts +16 -0
- package/plugins/huaweicloud-core/src/tools.ts +39 -4
- package/plugins/huaweicloud-core/src/update-skip.ts +5 -6
|
@@ -1,26 +1,33 @@
|
|
|
1
1
|
import { chmodSync, lstatSync, mkdirSync, realpathSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
3
|
import { basename, dirname, join, resolve, sep } from 'node:path';
|
|
4
4
|
|
|
5
5
|
import type { PackId } from './pack-types.ts';
|
|
6
|
+
import { devkitStateBase, huaweiConfigBase } from './state-dir.ts';
|
|
7
|
+
|
|
8
|
+
export { devkitStateBase, huaweiConfigBase };
|
|
6
9
|
|
|
7
10
|
// The pack-scoped state space and the single resolver for the devkit's
|
|
8
11
|
// config tree (~/.config/huaweicloud, relocatable whole-tree via
|
|
9
|
-
// HUAWEICLOUD_HOME).
|
|
12
|
+
// HUAWEICLOUD_HOME) and its writable state tree (state-dir.ts: the same tree
|
|
13
|
+
// by default, the agent-owned devkit-state directory on a read-only home).
|
|
10
14
|
//
|
|
11
15
|
// Ownership criterion, stated here so the next state file does not have to
|
|
12
16
|
// guess: the writer/reader set decides where state lives. approvals.json
|
|
13
17
|
// is the CLI approval face's store (plan_cli_command /
|
|
14
18
|
// run_approved_command mint and consume), credentials.json is the
|
|
15
19
|
// devkit-wide S1 store, and deps/ belongs to the dependency domain — all
|
|
16
|
-
// three
|
|
20
|
+
// three live in the state tree. State with exactly one pack as writer
|
|
17
21
|
// and reader (the open-mcp gateway's policy file) lives under packs/<id>/,
|
|
18
22
|
// so ownership is derivable from the directory name and an uninstall can
|
|
19
23
|
// preserve user state without a manifest. Modules that still hand-roll
|
|
20
|
-
// the base (
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
+
// the base (dep/receipts, update-check, proxy-config, officeace-paths)
|
|
25
|
+
// migrate when next touched; the guard below already resolves through this
|
|
26
|
+
// module, so guard and store cannot disagree about where the trees are.
|
|
27
|
+
//
|
|
28
|
+
// S1 is the one exception: credentials are WRITTEN to the state tree but
|
|
29
|
+
// READ from the state tree first and the config tree second, so a
|
|
30
|
+
// pre-provisioned credentials.json in a read-only home keeps resolving.
|
|
24
31
|
//
|
|
25
32
|
// The same resolver backs the protected-tree guard the gateway face uses:
|
|
26
33
|
// anything the devkit or its operator considers consent infrastructure (the
|
|
@@ -34,16 +41,8 @@ import type { PackId } from './pack-types.ts';
|
|
|
34
41
|
// — the installer chain (dist/setup-cli.js, plain tsc output) must never
|
|
35
42
|
// pull zod, same contract as dependency-model.ts and dep-resolve.ts.
|
|
36
43
|
|
|
37
|
-
export function huaweiConfigBase(env: NodeJS.ProcessEnv = process.env): string {
|
|
38
|
-
// resolve() absolutizes once, here, so every consumer — store writes and
|
|
39
|
-
// the guard below — shares one anchor even for a relative
|
|
40
|
-
// HUAWEICLOUD_HOME (a relative base previously made the store land at
|
|
41
|
-
// the process cwd while the guard protected a tmpdir-anchored tree).
|
|
42
|
-
return resolve(env.HUAWEICLOUD_HOME || homedir(), '.config', 'huaweicloud');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
44
|
export function packStateDir(packId: PackId, env: NodeJS.ProcessEnv = process.env): string {
|
|
46
|
-
return join(
|
|
45
|
+
return join(devkitStateBase(env), 'packs', packId);
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
export interface PackStateLayout {
|
|
@@ -153,20 +152,24 @@ function resolveForWrite(target: string): string | null {
|
|
|
153
152
|
}
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
// The roots a gateway file write must never touch: the devkit config tree
|
|
157
|
-
//
|
|
158
|
-
//
|
|
155
|
+
// The roots a gateway file write must never touch: the devkit config tree,
|
|
156
|
+
// the writable state tree (they differ on a read-only-home fallback), plus
|
|
157
|
+
// whatever policy/audit paths the operator configured (the LIVE paths, not
|
|
158
|
+
// what the devkit would have provisioned). Returns null when a root is
|
|
159
159
|
// present-but-unresolvable — callers deny everything in that case.
|
|
160
160
|
export function protectedTreeRoots(env: NodeJS.ProcessEnv = process.env): string[] | null {
|
|
161
|
-
const candidates: string[] = [huaweiConfigBase(env)];
|
|
161
|
+
const candidates: string[] = [huaweiConfigBase(env), devkitStateBase(env)];
|
|
162
162
|
for (const key of ['HUAWEICLOUD_MCP_POLICY_FILE', 'HUAWEICLOUD_MCP_AUDIT_FILE'] as const) {
|
|
163
163
|
const value = (env[key] ?? '').trim();
|
|
164
164
|
if (value !== '') candidates.push(value);
|
|
165
165
|
}
|
|
166
166
|
const roots: string[] = [];
|
|
167
|
+
const seen = new Set<string>();
|
|
167
168
|
for (const candidate of candidates) {
|
|
168
169
|
const resolved = resolveForWrite(candidate);
|
|
169
170
|
if (resolved === null) return null;
|
|
171
|
+
if (seen.has(resolved)) continue;
|
|
172
|
+
seen.add(resolved);
|
|
170
173
|
roots.push(resolved);
|
|
171
174
|
}
|
|
172
175
|
return roots;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Unknown-parameter warnings for the MCP boundary. The #530 leniency keeps
|
|
2
|
+
// accepting keys a tool does not declare (model wire shapes are noisy and a
|
|
3
|
+
// rejection used to cost the whole call), but silently dropping a typo makes
|
|
4
|
+
// `pack` vs `pak` invisible — this module turns that into an additive
|
|
5
|
+
// `warnings` entry without changing the acceptance decision.
|
|
6
|
+
|
|
7
|
+
const MAX_WARNINGS = 5;
|
|
8
|
+
const SUGGESTION_DISTANCE = 2;
|
|
9
|
+
|
|
10
|
+
function levenshtein(a: string, b: string): number {
|
|
11
|
+
const rows = a.length + 1;
|
|
12
|
+
const cols = b.length + 1;
|
|
13
|
+
const previous = new Array<number>(cols);
|
|
14
|
+
const current = new Array<number>(cols);
|
|
15
|
+
for (let j = 0; j < cols; j++) previous[j] = j;
|
|
16
|
+
for (let i = 1; i < rows; i++) {
|
|
17
|
+
current[0] = i;
|
|
18
|
+
for (let j = 1; j < cols; j++) {
|
|
19
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
20
|
+
current[j] = Math.min(previous[j]! + 1, current[j - 1]! + 1, previous[j - 1]! + cost);
|
|
21
|
+
}
|
|
22
|
+
for (let j = 0; j < cols; j++) previous[j] = current[j]!;
|
|
23
|
+
}
|
|
24
|
+
return previous[cols - 1]!;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function suggestParam(key: string, knownKeys: Iterable<string>): string | null {
|
|
28
|
+
let best: string | null = null;
|
|
29
|
+
let bestDistance = SUGGESTION_DISTANCE + 1;
|
|
30
|
+
const lowerKey = key.toLowerCase();
|
|
31
|
+
for (const candidate of knownKeys) {
|
|
32
|
+
if (candidate === key) continue;
|
|
33
|
+
const distance = levenshtein(lowerKey, candidate.toLowerCase());
|
|
34
|
+
if (distance > SUGGESTION_DISTANCE) continue;
|
|
35
|
+
if (distance < bestDistance || (distance === bestDistance && best !== null && candidate < best)) {
|
|
36
|
+
best = candidate;
|
|
37
|
+
bestDistance = distance;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return best;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function unknownParamWarnings(args: Record<string, unknown>, knownKeys: ReadonlySet<string>): string[] {
|
|
44
|
+
const unknown = Object.keys(args)
|
|
45
|
+
.filter((key) => !knownKeys.has(key))
|
|
46
|
+
.sort((a, b) => a.localeCompare(b));
|
|
47
|
+
return unknown.slice(0, MAX_WARNINGS).map((key) => {
|
|
48
|
+
const suggestion = suggestParam(key, knownKeys);
|
|
49
|
+
return suggestion
|
|
50
|
+
? `Unknown parameter "${key}" was ignored. Did you mean "${suggestion}"?`
|
|
51
|
+
: `Unknown parameter "${key}" was ignored (no matching parameter).`;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Additive by construction: a warnings array is merged, an absent field is
|
|
56
|
+
// created, and any other existing shape is left untouched under paramWarnings.
|
|
57
|
+
// Non-object results (there are none on the shipped surface) pass through.
|
|
58
|
+
export function attachParamWarnings(result: unknown, warnings: string[]): unknown {
|
|
59
|
+
if (warnings.length === 0) return result;
|
|
60
|
+
if (result === null || typeof result !== 'object' || Array.isArray(result)) return result;
|
|
61
|
+
const record = result as Record<string, unknown>;
|
|
62
|
+
if (Array.isArray(record.warnings)) {
|
|
63
|
+
return { ...record, warnings: [...(record.warnings as unknown[]), ...warnings] };
|
|
64
|
+
}
|
|
65
|
+
if (record.warnings === undefined) {
|
|
66
|
+
return { ...record, warnings };
|
|
67
|
+
}
|
|
68
|
+
return { ...record, paramWarnings: warnings };
|
|
69
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { existsSync, lstatSync, mkdirSync, rmSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
|
+
|
|
5
|
+
// The devkit's two directory roots. `configBase` is the historical
|
|
6
|
+
// ~/.config/huaweicloud tree (credentials, approvals, pack state, proxy and
|
|
7
|
+
// update state); `stateBase` is the same tree by default and moves to a
|
|
8
|
+
// writable agent-owned directory only when the config tree cannot be written.
|
|
9
|
+
//
|
|
10
|
+
// The split exists because some agent sandboxes ship a read-only home: the
|
|
11
|
+
// gateway's pack state, approval tokens, S1 writes and update state all need
|
|
12
|
+
// a writable directory, while the pre-provisioned credentials.json must stay
|
|
13
|
+
// readable at its original location. The installer/CLI and the MCP server
|
|
14
|
+
// resolve the same paths from the same filesystem, so no env plumbing is
|
|
15
|
+
// required for them to agree.
|
|
16
|
+
//
|
|
17
|
+
// Runtime import graph stays at node builtins — pack-state.ts (the stable
|
|
18
|
+
// resolver face) and the installer graph import this module.
|
|
19
|
+
|
|
20
|
+
const STATE_DIR_ENV = 'HUAWEICLOUD_STATE_DIR';
|
|
21
|
+
const AGENT_STATE_MARKERS = ['.codearts', '.codeartswork', '.codeartsdoer'] as const;
|
|
22
|
+
|
|
23
|
+
const stateBaseCache = new Map<string, string>();
|
|
24
|
+
|
|
25
|
+
export function huaweiConfigBase(env: NodeJS.ProcessEnv = process.env): string {
|
|
26
|
+
// resolve() absolutizes once, here, so every consumer — store writes and
|
|
27
|
+
// the protected-tree guard — shares one anchor even for a relative
|
|
28
|
+
// HUAWEICLOUD_HOME (a relative base previously made the store land at
|
|
29
|
+
// the process cwd while the guard protected a tmpdir-anchored tree).
|
|
30
|
+
return resolve(env.HUAWEICLOUD_HOME || homedir(), '.config', 'huaweicloud');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function agentHomeBase(env: NodeJS.ProcessEnv): string {
|
|
34
|
+
return resolve(env.HUAWEICLOUD_HOME || homedir());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function nearestExisting(path: string): string | null {
|
|
38
|
+
let current = resolve(path);
|
|
39
|
+
for (;;) {
|
|
40
|
+
try {
|
|
41
|
+
lstatSync(current);
|
|
42
|
+
return current;
|
|
43
|
+
} catch {
|
|
44
|
+
const parent = dirname(current);
|
|
45
|
+
if (parent === current) return null;
|
|
46
|
+
current = parent;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// A real create/remove probe, not access(W_OK): Windows ACLs and WSL drvfs
|
|
52
|
+
// can report a writable mode while mkdir still fails, and the gateway's first
|
|
53
|
+
// pack-state provisioning is exactly a mkdir under the config tree.
|
|
54
|
+
export function probeWritableDir(path: string): boolean {
|
|
55
|
+
const anchor = nearestExisting(path);
|
|
56
|
+
if (!anchor) return false;
|
|
57
|
+
const probe = join(anchor, `.devkit-write-probe-${process.pid}-${Math.random().toString(36).slice(2)}`);
|
|
58
|
+
try {
|
|
59
|
+
mkdirSync(probe, { mode: 0o700 });
|
|
60
|
+
return true;
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
63
|
+
} finally {
|
|
64
|
+
try {
|
|
65
|
+
rmSync(probe, { recursive: true, force: true });
|
|
66
|
+
} catch {
|
|
67
|
+
// best-effort cleanup; the probe directory is empty and 0700
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Agent-owned writable roots, checked in the same order the installer targets
|
|
73
|
+
// them: CodeArts Work's new layout, its legacy home, then CodeArts.
|
|
74
|
+
function codeArtsStateBase(env: NodeJS.ProcessEnv): string | null {
|
|
75
|
+
const home = agentHomeBase(env);
|
|
76
|
+
for (const marker of AGENT_STATE_MARKERS) {
|
|
77
|
+
const root = join(home, marker);
|
|
78
|
+
if (!existsSync(root) || !probeWritableDir(root)) continue;
|
|
79
|
+
return join(root, 'devkit-state');
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function explicitStateBase(env: NodeJS.ProcessEnv): string | null {
|
|
85
|
+
const value = (env[STATE_DIR_ENV] ?? '').trim();
|
|
86
|
+
if (value === '') return null;
|
|
87
|
+
if (!isAbsolute(value)) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`${STATE_DIR_ENV} must be an absolute path (got "${value}"): the CLI and the MCP server resolve relative paths against different working directories.`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return resolve(value);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function devkitStateBase(env: NodeJS.ProcessEnv = process.env): string {
|
|
96
|
+
const explicit = explicitStateBase(env);
|
|
97
|
+
if (explicit) return explicit;
|
|
98
|
+
const configBase = huaweiConfigBase(env);
|
|
99
|
+
const cached = stateBaseCache.get(configBase);
|
|
100
|
+
if (cached) return cached;
|
|
101
|
+
const stateBase = probeWritableDir(configBase) ? configBase : (codeArtsStateBase(env) ?? configBase);
|
|
102
|
+
stateBaseCache.set(configBase, stateBase);
|
|
103
|
+
return stateBase;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Doctor/installer display form: home-relative paths stay stable in the
|
|
107
|
+
// golden fixtures and read better to a human. Forward slashes keep the
|
|
108
|
+
// rendered form identical on Windows and POSIX (the goldens are committed
|
|
109
|
+
// once, not per platform).
|
|
110
|
+
export function displayStatePath(path: string, env: NodeJS.ProcessEnv = process.env): string {
|
|
111
|
+
const home = agentHomeBase(env).replace(/\\/g, '/');
|
|
112
|
+
const normalized = path.replace(/\\/g, '/');
|
|
113
|
+
if (normalized === home) return '~';
|
|
114
|
+
return normalized.startsWith(home + '/') ? `~${normalized.slice(home.length)}` : normalized;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function stateDirNotice(env: NodeJS.ProcessEnv = process.env): string | null {
|
|
118
|
+
const configBase = huaweiConfigBase(env);
|
|
119
|
+
const stateBase = devkitStateBase(env);
|
|
120
|
+
if (stateBase === configBase) return null;
|
|
121
|
+
return `state directory ${displayStatePath(stateBase, env)} (${displayStatePath(configBase, env)} is not writable; set ${STATE_DIR_ENV} to pin it)`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Tests swap HUAWEICLOUD_HOME between cases; the cache is keyed by configBase,
|
|
125
|
+
// so this is only for a case that changes permissions under one home.
|
|
126
|
+
export function _resetStateDirCache(): void {
|
|
127
|
+
stateBaseCache.clear();
|
|
128
|
+
}
|
|
@@ -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
|
},
|
|
@@ -46,6 +46,7 @@ import { queryDistTagsFetch, determineTarget, semverCompare } from './update-che
|
|
|
46
46
|
import { getKooCliVersion, compareVersion, kooCliDownloadBase } from './koocli-version.ts';
|
|
47
47
|
import { hcloudProbeNextStep, hcloudProbeRaw, probeHcloud } from './hcloud-probe.ts';
|
|
48
48
|
import { asRecord } from './lib/as-record.ts';
|
|
49
|
+
import { devkitStateBase, displayStatePath, huaweiConfigBase, probeWritableDir } from './lib/state-dir.ts';
|
|
49
50
|
import { DEPENDENCIES, DEPENDENCY_IDS, requiredDependencies, type DependencyId } from './lib/dependency-model.ts';
|
|
50
51
|
import { resolveDependencyCommand } from './lib/dep-resolve.ts';
|
|
51
52
|
// The installer's payload machinery: file ops, server payload placement,
|
|
@@ -118,6 +119,7 @@ import { deployDsh, dshStatus, uninstallDsh } from './agents/dsh.ts';
|
|
|
118
119
|
import { dshDoctorMcpConfigured, dshPayloadDoctorSection } from './agents/dsh-patch.ts';
|
|
119
120
|
import {
|
|
120
121
|
deployOpenCode,
|
|
122
|
+
opencodeDoctorAskRule,
|
|
121
123
|
opencodeDoctorMcpConfigured,
|
|
122
124
|
opencodeDoctorSeam,
|
|
123
125
|
opencodeStatus,
|
|
@@ -924,6 +926,26 @@ async function cmdDoctor(): Promise<void> {
|
|
|
924
926
|
const nodeOk = nodeParts[0]! > 22 || (nodeParts[0]! === 22 && nodeParts[1]! >= 19);
|
|
925
927
|
check('Node.js >= 22.19', nodeOk, 'Run: nvm install 22.19 && nvm use 22.19');
|
|
926
928
|
|
|
929
|
+
// State directory — gateway pack state, approval tokens, S1 writes and
|
|
930
|
+
// update state all write here. A read-only home falls back to an
|
|
931
|
+
// agent-owned dir (state-dir.ts); the fallback is a warning, not a failure.
|
|
932
|
+
const configBase = huaweiConfigBase();
|
|
933
|
+
const stateBase = devkitStateBase();
|
|
934
|
+
const stateDisplay = displayStatePath(stateBase);
|
|
935
|
+
if (stateBase === configBase) {
|
|
936
|
+
check(
|
|
937
|
+
`State directory writable (${stateDisplay})`,
|
|
938
|
+
probeWritableDir(stateBase),
|
|
939
|
+
'Fix permissions, or set HUAWEICLOUD_STATE_DIR to a writable path',
|
|
940
|
+
);
|
|
941
|
+
} else if (probeWritableDir(stateBase)) {
|
|
942
|
+
ctx.warn(
|
|
943
|
+
`State directory fallback: ${stateDisplay} (${displayStatePath(configBase)} is not writable; set HUAWEICLOUD_STATE_DIR to pin it)`,
|
|
944
|
+
);
|
|
945
|
+
} else {
|
|
946
|
+
check(`State directory writable (${stateDisplay})`, false, 'Set HUAWEICLOUD_STATE_DIR to a writable path');
|
|
947
|
+
}
|
|
948
|
+
|
|
927
949
|
// MCP server — derived from the per-row doctor bindings (one membership
|
|
928
950
|
// table for every payload check in this doctor run). The bindings run the
|
|
929
951
|
// pure triple probes here; their native-freshness halves run late, after
|
|
@@ -1026,10 +1048,13 @@ async function cmdDoctor(): Promise<void> {
|
|
|
1026
1048
|
mcpCfgTarget ? `Found in ${mcpCfgTarget} config` : 'Run: npx huaweicloud-devkit install',
|
|
1027
1049
|
);
|
|
1028
1050
|
|
|
1029
|
-
//
|
|
1030
|
-
// 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).
|
|
1031
1055
|
if (installedPayload?.id === 'opencode') {
|
|
1032
1056
|
opencodeDoctorSeam(ctx);
|
|
1057
|
+
opencodeDoctorAskRule(ctx);
|
|
1033
1058
|
}
|
|
1034
1059
|
|
|
1035
1060
|
// Hermes MCP Python SDK (only checked when Hermes config is found).
|
|
@@ -165,6 +165,22 @@ export function toolSchemaEntries(): Array<[ToolName, LooseToolSchema]> {
|
|
|
165
165
|
return Object.entries(TOOL_SCHEMAS) as Array<[ToolName, LooseToolSchema]>;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
const argKeyCache = new Map<ToolName, ReadonlySet<string>>();
|
|
169
|
+
|
|
170
|
+
// The keys a tool's input schema declares, plus the central vendorConfirmed
|
|
171
|
+
// part (rendered only on cloud-facing tools but accepted by the dispatch gate
|
|
172
|
+
// everywhere). callTool's unknown-parameter warning reads this; the #530
|
|
173
|
+
// pass-through leniency itself is unchanged.
|
|
174
|
+
export function toolArgKeys(name: ToolName): ReadonlySet<string> {
|
|
175
|
+
const cached = argKeyCache.get(name);
|
|
176
|
+
if (cached) return cached;
|
|
177
|
+
const def = (TOOL_SCHEMAS[name] as unknown as { _zod?: { def?: { shape?: Record<string, unknown> } } })._zod?.def;
|
|
178
|
+
const keys = new Set<string>(Object.keys(def?.shape ?? {}));
|
|
179
|
+
keys.add('vendorConfirmed');
|
|
180
|
+
argKeyCache.set(name, keys);
|
|
181
|
+
return keys;
|
|
182
|
+
}
|
|
183
|
+
|
|
168
184
|
// Runtime guard: every entry must be a constructed zod loose-object. A bare
|
|
169
185
|
// raw shape would be wrapped by the SDK into STRIP semantics, silently
|
|
170
186
|
// dropping client keys instead of passing them through.
|