huaweicloud-devkit 2.0.0-next.2 → 2.0.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/package.json +3 -1
- package/plugins/huaweicloud-core/.claude-plugin/plugin.json +16 -3
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +16 -3
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +16 -3
- package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +16 -3
- package/plugins/huaweicloud-core/.mcp.json +55 -1
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +16 -3
- package/plugins/huaweicloud-core/dist/agents/codex-config.js +374 -0
- package/plugins/huaweicloud-core/dist/agents/codex-desktop.js +8 -1
- package/plugins/huaweicloud-core/dist/agents/codex.js +9 -0
- package/plugins/huaweicloud-core/dist/agents/opencode-config.js +157 -31
- package/plugins/huaweicloud-core/dist/agents/opencode.js +129 -1
- package/plugins/huaweicloud-core/dist/approval-gate.js +1185 -0
- package/plugins/huaweicloud-core/dist/approval-ledger.js +2331 -0
- package/plugins/huaweicloud-core/dist/approval-roster.js +89 -0
- package/plugins/huaweicloud-core/dist/approval-types.js +1 -0
- package/plugins/huaweicloud-core/dist/approvals-cli.js +4 -4
- package/plugins/huaweicloud-core/dist/data/icons-manifest.v1.json +23 -5
- package/plugins/huaweicloud-core/dist/dep/receipts.js +65 -5
- package/plugins/huaweicloud-core/dist/hcloud-cli.js +1 -1
- package/plugins/huaweicloud-core/dist/hcloud-plan.js +77 -56
- package/plugins/huaweicloud-core/dist/lib/approval-mode.js +32 -0
- package/plugins/huaweicloud-core/dist/lib/approval-tokens.js +18 -4
- package/plugins/huaweicloud-core/dist/lib/call-trace.js +7 -14
- package/plugins/huaweicloud-core/dist/lib/confirm-language.js +50 -0
- package/plugins/huaweicloud-core/dist/lib/credentials.js +9 -9
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkit-gate.js +1398 -0
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +362 -32
- package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +6 -16
- package/plugins/huaweicloud-core/dist/lib/opencode-ask-rule.js +262 -0
- package/plugins/huaweicloud-core/dist/lib/opencode-saved-perms.js +282 -0
- package/plugins/huaweicloud-core/dist/lib/supplemental-redaction.js +116 -0
- package/plugins/huaweicloud-core/dist/lib/tool-schema-parts.js +31 -0
- package/plugins/huaweicloud-core/dist/lib/workspace-glob.js +442 -0
- package/plugins/huaweicloud-core/dist/mcp-config-io.js +28 -1
- package/plugins/huaweicloud-core/dist/mcp-protocol.js +75 -4
- package/plugins/huaweicloud-core/dist/mcp-server.js +6560 -898
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
- package/plugins/huaweicloud-core/dist/mcp-stdio-transport.js +14 -4
- package/plugins/huaweicloud-core/dist/packs/auth/approval.js +249 -0
- package/plugins/huaweicloud-core/dist/packs/auth/tools.js +44 -44
- package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +119 -112
- package/plugins/huaweicloud-core/dist/packs/obs/approval.js +110 -0
- package/plugins/huaweicloud-core/dist/packs/obs/tools.js +7 -2
- package/plugins/huaweicloud-core/dist/packs/registry.js +19 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +245 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +156 -23
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-credentials.js +13 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-hwexec.js +136 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-session.js +11 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +1 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +79 -9
- package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +28 -9
- package/plugins/huaweicloud-core/dist/packs/secrets/approval.js +46 -0
- package/plugins/huaweicloud-core/dist/packs/secrets/tools.js +4 -1
- package/plugins/huaweicloud-core/dist/packs/update/approval.js +79 -0
- package/plugins/huaweicloud-core/dist/packs/update/tools.js +8 -1
- package/plugins/huaweicloud-core/dist/packs/voucher/tools.js +1 -1
- package/plugins/huaweicloud-core/dist/packs-configure.js +74 -0
- package/plugins/huaweicloud-core/dist/safety/classify-text.js +36 -0
- package/plugins/huaweicloud-core/dist/safety/policy.js +2 -0
- package/plugins/huaweicloud-core/dist/sandbox/deploy-check.js +1 -1
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-auth.js +65 -14
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-cleanup.js +422 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose-flow.js +66 -16
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose.js +13 -10
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-keepalive.js +42 -2
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-key.js +11 -3
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-tunnel.js +6 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-validation.js +10 -1
- package/plugins/huaweicloud-core/dist/sandbox/hwexec-task.js +244 -0
- package/plugins/huaweicloud-core/dist/setup-cli.js +42 -4
- package/plugins/huaweicloud-core/dist/tool-definitions.js +9 -1
- package/plugins/huaweicloud-core/dist/tool-schemas.js +32 -6
- package/plugins/huaweicloud-core/dist/tools.js +76 -9
- package/plugins/huaweicloud-core/dist/update-registry.js +358 -5
- package/plugins/huaweicloud-core/dist/update-upgrade.js +1083 -14
- package/plugins/huaweicloud-core/dist/vendor-gate.js +2 -2
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +150 -1
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +53 -3
- package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
- package/plugins/huaweicloud-core/safety/policy.json +18 -11
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +114 -10
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +190 -138
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +36 -12
- package/plugins/huaweicloud-core/skills/huawei-voucher/SKILL.md +2 -0
- package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +5 -5
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +13 -8
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +78 -23
- package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/SKILL.md +21 -19
- package/plugins/huaweicloud-core/src/agents/codex-config.ts +432 -0
- package/plugins/huaweicloud-core/src/agents/codex-desktop.ts +8 -1
- package/plugins/huaweicloud-core/src/agents/codex.ts +10 -0
- package/plugins/huaweicloud-core/src/agents/opencode-config.ts +198 -30
- package/plugins/huaweicloud-core/src/agents/opencode.ts +157 -1
- package/plugins/huaweicloud-core/src/approval-gate.ts +1306 -0
- package/plugins/huaweicloud-core/src/approval-ledger.ts +2446 -0
- package/plugins/huaweicloud-core/src/approval-roster.ts +127 -0
- package/plugins/huaweicloud-core/src/approval-types.ts +237 -0
- package/plugins/huaweicloud-core/src/approvals-cli.ts +4 -4
- package/plugins/huaweicloud-core/src/data/icons-manifest.v1.json +23 -5
- package/plugins/huaweicloud-core/src/dep/receipts.ts +84 -5
- package/plugins/huaweicloud-core/src/hcloud-cli.ts +3 -0
- package/plugins/huaweicloud-core/src/hcloud-plan.ts +93 -63
- package/plugins/huaweicloud-core/src/lib/approval-mode.ts +34 -0
- package/plugins/huaweicloud-core/src/lib/approval-tokens.ts +19 -4
- package/plugins/huaweicloud-core/src/lib/call-trace.ts +7 -17
- package/plugins/huaweicloud-core/src/lib/confirm-language.ts +51 -0
- package/plugins/huaweicloud-core/src/lib/credentials.ts +9 -8
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkit-gate.ts +1428 -0
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +377 -30
- package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +8 -15
- package/plugins/huaweicloud-core/src/lib/opencode-ask-rule.ts +350 -0
- package/plugins/huaweicloud-core/src/lib/opencode-saved-perms.ts +354 -0
- package/plugins/huaweicloud-core/src/lib/supplemental-redaction.ts +129 -0
- package/plugins/huaweicloud-core/src/lib/tool-schema-parts.ts +40 -0
- package/plugins/huaweicloud-core/src/lib/workspace-glob.ts +414 -0
- package/plugins/huaweicloud-core/src/mcp-config-io.ts +27 -1
- package/plugins/huaweicloud-core/src/mcp-protocol.ts +88 -5
- package/plugins/huaweicloud-core/src/mcp-server.ts +13 -0
- package/plugins/huaweicloud-core/src/mcp-stdio-transport.ts +14 -4
- package/plugins/huaweicloud-core/src/packs/auth/approval.ts +302 -0
- package/plugins/huaweicloud-core/src/packs/auth/tools.ts +54 -45
- package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +139 -120
- package/plugins/huaweicloud-core/src/packs/obs/approval.ts +122 -0
- package/plugins/huaweicloud-core/src/packs/obs/tools.ts +7 -2
- package/plugins/huaweicloud-core/src/packs/registry.ts +42 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +296 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +168 -23
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-credentials.ts +11 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-hwexec.ts +228 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-session.ts +11 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +1 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +100 -8
- package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +31 -8
- package/plugins/huaweicloud-core/src/packs/secrets/approval.ts +50 -0
- package/plugins/huaweicloud-core/src/packs/secrets/tools.ts +4 -1
- package/plugins/huaweicloud-core/src/packs/update/approval.ts +87 -0
- package/plugins/huaweicloud-core/src/packs/update/tools.ts +8 -1
- package/plugins/huaweicloud-core/src/packs/voucher/tools.ts +1 -1
- package/plugins/huaweicloud-core/src/packs-configure.ts +75 -0
- package/plugins/huaweicloud-core/src/safety/classify-text.ts +40 -0
- package/plugins/huaweicloud-core/src/safety/policy.ts +7 -0
- package/plugins/huaweicloud-core/src/sandbox/deploy-check.ts +1 -1
- package/plugins/huaweicloud-core/src/sandbox/devbridge-auth.ts +74 -14
- package/plugins/huaweicloud-core/src/sandbox/devbridge-cleanup.ts +509 -0
- package/plugins/huaweicloud-core/src/sandbox/devbridge-expose-flow.ts +70 -18
- package/plugins/huaweicloud-core/src/sandbox/devbridge-expose.ts +26 -10
- package/plugins/huaweicloud-core/src/sandbox/devbridge-keepalive.ts +41 -2
- package/plugins/huaweicloud-core/src/sandbox/devbridge-key.ts +9 -3
- package/plugins/huaweicloud-core/src/sandbox/devbridge-tunnel.ts +24 -0
- package/plugins/huaweicloud-core/src/sandbox/devbridge-validation.ts +11 -1
- package/plugins/huaweicloud-core/src/sandbox/hwexec-task.ts +304 -0
- package/plugins/huaweicloud-core/src/setup-cli.ts +45 -3
- package/plugins/huaweicloud-core/src/tool-definitions.ts +9 -1
- package/plugins/huaweicloud-core/src/tool-schemas.ts +39 -6
- package/plugins/huaweicloud-core/src/tools.ts +124 -10
- package/plugins/huaweicloud-core/src/update-registry.ts +340 -5
- package/plugins/huaweicloud-core/src/update-upgrade.ts +1130 -14
- package/plugins/huaweicloud-core/src/vendor-gate.ts +2 -2
|
@@ -59,6 +59,37 @@ export const gitConfig = z.looseObject({
|
|
|
59
59
|
target_path: z.string().optional(),
|
|
60
60
|
open_type: z.string().optional(),
|
|
61
61
|
});
|
|
62
|
+
// The shared approval-gate parameters, declared once for every roster tool
|
|
63
|
+
// the gate covers (the hcloud run face today; the PR-3 pack registrations
|
|
64
|
+
// join by spreading the same parts into their schemas). Both are optional
|
|
65
|
+
// in the schema ON PURPOSE, same doctrine as vendorConfirmed: a missing
|
|
66
|
+
// value must reach callTool's gate, which owns the refusal teaching —
|
|
67
|
+
// SDK-level required-field rejects would silence the consent instruction.
|
|
68
|
+
// The gate, not zod, is the enforcement.
|
|
69
|
+
export const approvalTokenArg = z
|
|
70
|
+
.string()
|
|
71
|
+
.optional()
|
|
72
|
+
.describe("Required in token-approval mode (from the minting face — the plan tool, or the approval gate's USER_CONFIRMATION_REQUIRED envelope); omit in ask mode, where the server-run gate confirms at run time.");
|
|
73
|
+
// Optional in the schema for the same reason: in token mode the gate throws
|
|
74
|
+
// the teaching rejection when it is absent, and in ask mode the server-run
|
|
75
|
+
// confirmation owns the gate — the first arrival has no attestation yet (the
|
|
76
|
+
// chat round-trip envelope asks for it), so a required field here would kill
|
|
77
|
+
// the T3 flow in SDK validation before the gate ever saw it.
|
|
78
|
+
export const approvedByUserArg = booleanArg
|
|
79
|
+
.optional()
|
|
80
|
+
.describe('Must be true only after the user explicitly approves this exact call. In token mode the gate requires it; in ask mode the server-run confirmation asks the user itself, and this flag is the chat round-trip retry marker (posture trust) when the client cannot render a form.');
|
|
81
|
+
// The confirm-language hint, injected on every roster tool by
|
|
82
|
+
// src/tool-schemas.ts (the approval domain's parameter, not any pack's).
|
|
83
|
+
// The model relays the user's conversation language so the human-facing
|
|
84
|
+
// confirmation form renders its display text in it — the MCP server never
|
|
85
|
+
// sees the chat, so the model is the only context observer. Optional and
|
|
86
|
+
// soft-failing by design (lib/confirm-language.ts): an unrecognized value
|
|
87
|
+
// falls through to the operator's DEVKIT_CONFIRM_LANG pin, then the machine
|
|
88
|
+
// locale; the enum VALUES and every refusal stay English in both languages.
|
|
89
|
+
export const confirmLanguageArg = z
|
|
90
|
+
.string()
|
|
91
|
+
.optional()
|
|
92
|
+
.describe("Optional: the user's conversation language, 'zh' (Chinese) or 'en' — the approval confirmation form renders its display text in that language.");
|
|
62
93
|
export const workspaceId = z
|
|
63
94
|
.string()
|
|
64
95
|
.optional()
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
// Workspace-pattern matching with npm's semantics. `@npmcli/map-workspaces`
|
|
2
|
+
// expands the declared patterns with `glob` (minimatch) and ignores the
|
|
3
|
+
// negated ones; this module ports the slice of that language a workspace
|
|
4
|
+
// declaration realistically uses: brace expansion, character classes,
|
|
5
|
+
// extglob alternatives, `*` inside one segment, `**` across whole segments,
|
|
6
|
+
// `dot: false`, `!!` parity, the per-pattern negation cancellation order, and
|
|
7
|
+
// the trailing-`**` parent directory. It stays dependency-free so the update
|
|
8
|
+
// graph can carry it into both the unbundled setup CLI and the bundled server.
|
|
9
|
+
// Edges outside the port: a POSIX bracket class (`[[:alpha:]]`) is refused
|
|
10
|
+
// (never-matching) instead of expanded; an explicit dot segment after `**`
|
|
11
|
+
// (`packages/**/.*`) is a member here where map-workspaces' partial post-filter
|
|
12
|
+
// drops it; and a `..` immediately after `**` is not pre-resolved the way glob
|
|
13
|
+
// does. An extglob alternative containing `/` is literalized; both sides match
|
|
14
|
+
// nothing there. Brace expansion is capped like npm's 100k-entry limit, and
|
|
15
|
+
// segment matching is memoized so stacked `**` cannot backtrack exponentially.
|
|
16
|
+
const GLOBSTAR = '\u0000globstar';
|
|
17
|
+
function escapeRegExp(char) {
|
|
18
|
+
return /[.*+?^${}()|[\]\\]/.test(char) ? `\\${char}` : char;
|
|
19
|
+
}
|
|
20
|
+
function findBrace(pattern) {
|
|
21
|
+
let start = -1;
|
|
22
|
+
let depth = 0;
|
|
23
|
+
let escaped = false;
|
|
24
|
+
for (let index = 0; index < pattern.length; index += 1) {
|
|
25
|
+
const char = pattern[index];
|
|
26
|
+
if (escaped) {
|
|
27
|
+
escaped = false;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (char === '\\') {
|
|
31
|
+
escaped = true;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (char === '{') {
|
|
35
|
+
if (depth === 0)
|
|
36
|
+
start = index;
|
|
37
|
+
depth += 1;
|
|
38
|
+
}
|
|
39
|
+
else if (char === '}' && depth > 0) {
|
|
40
|
+
depth -= 1;
|
|
41
|
+
if (depth === 0)
|
|
42
|
+
return { start, end: index };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
function splitBraceAlternatives(body) {
|
|
48
|
+
const parts = [];
|
|
49
|
+
let depth = 0;
|
|
50
|
+
let from = 0;
|
|
51
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
52
|
+
const char = body[index];
|
|
53
|
+
if (char === '{')
|
|
54
|
+
depth += 1;
|
|
55
|
+
else if (char === '}')
|
|
56
|
+
depth -= 1;
|
|
57
|
+
else if (char === ',' && depth === 0) {
|
|
58
|
+
parts.push(body.slice(from, index));
|
|
59
|
+
from = index + 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (!parts.length)
|
|
63
|
+
return undefined;
|
|
64
|
+
parts.push(body.slice(from));
|
|
65
|
+
return parts;
|
|
66
|
+
}
|
|
67
|
+
function expandBraceRange(body, limit) {
|
|
68
|
+
const match = /^(-?\d+|[A-Za-z])\.\.(-?\d+|[A-Za-z])(?:\.\.(-?\d+))?$/.exec(body);
|
|
69
|
+
if (!match)
|
|
70
|
+
return undefined;
|
|
71
|
+
const [, fromRaw, toRaw, stepRaw] = match;
|
|
72
|
+
const numeric = /^-?\d+$/.test(fromRaw) && /^-?\d+$/.test(toRaw);
|
|
73
|
+
const from = numeric ? Number(fromRaw) : (fromRaw.codePointAt(0) ?? 0);
|
|
74
|
+
const to = numeric ? Number(toRaw) : (toRaw.codePointAt(0) ?? 0);
|
|
75
|
+
const step = Math.abs(Number(stepRaw ?? 1)) || 1;
|
|
76
|
+
// npm formats at the width of the raw endpoints (sign included), padding a
|
|
77
|
+
// negative after its sign, and truncates the sequence at the expansion cap.
|
|
78
|
+
const width = Math.max(fromRaw.length, toRaw.length);
|
|
79
|
+
const paddedParts = stepRaw === undefined ? [fromRaw, toRaw] : [fromRaw, toRaw, stepRaw];
|
|
80
|
+
// npm's isPadded tests every sequence part, the step included.
|
|
81
|
+
const padded = numeric && paddedParts.some((part) => /^-?0\d/.test(part));
|
|
82
|
+
const out = [];
|
|
83
|
+
const direction = from <= to ? 1 : -1;
|
|
84
|
+
for (let value = from; direction > 0 ? value <= to : value >= to; value += direction * step) {
|
|
85
|
+
if (out.length >= limit)
|
|
86
|
+
break;
|
|
87
|
+
if (numeric) {
|
|
88
|
+
let text = String(value);
|
|
89
|
+
const need = width - text.length;
|
|
90
|
+
if (padded && need > 0) {
|
|
91
|
+
const zeros = '0'.repeat(need);
|
|
92
|
+
text = value < 0 ? `-${zeros}${text.slice(1)}` : `${zeros}${text}`;
|
|
93
|
+
}
|
|
94
|
+
out.push(text);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
out.push(String.fromCodePoint(value));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
// npm's brace-expansion refuses beyond 100k entries; the same budget keeps a
|
|
103
|
+
// hostile declaration bounded instead of exhausting memory.
|
|
104
|
+
const BRACE_EXPANSION_LIMIT = 100_000;
|
|
105
|
+
// npm also bounds the total expanded characters (EXPANSION_MAX_LENGTH).
|
|
106
|
+
const BRACE_CHARACTER_LIMIT = 4_000_000;
|
|
107
|
+
// INVARIANT (budget first-to-bind): every expansion node checks BOTH budgets;
|
|
108
|
+
// the walk returns the accumulated output the moment EITHER is spent, so the
|
|
109
|
+
// entry order and the character order are both bounded by the same guard. A
|
|
110
|
+
// rejected leaf poisons the character budget (chars = -1) so the loop's single
|
|
111
|
+
// early return fires instead of walking the remaining paths.
|
|
112
|
+
const budgetSpent = (budget) => budget.left <= 0 || budget.chars < 0;
|
|
113
|
+
function expandBraces(pattern, budget = { left: BRACE_EXPANSION_LIMIT, chars: BRACE_CHARACTER_LIMIT }) {
|
|
114
|
+
const brace = findBrace(pattern);
|
|
115
|
+
if (!brace) {
|
|
116
|
+
if (budgetSpent(budget))
|
|
117
|
+
return [];
|
|
118
|
+
if (budget.chars < pattern.length) {
|
|
119
|
+
budget.chars = -1;
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
budget.left -= 1;
|
|
123
|
+
budget.chars -= pattern.length;
|
|
124
|
+
return [pattern];
|
|
125
|
+
}
|
|
126
|
+
const body = pattern.slice(brace.start + 1, brace.end);
|
|
127
|
+
const prefix = pattern.slice(0, brace.start);
|
|
128
|
+
const suffix = pattern.slice(brace.end + 1);
|
|
129
|
+
const alternatives = splitBraceAlternatives(body) ?? expandBraceRange(body, Math.max(0, budget.left));
|
|
130
|
+
if (alternatives) {
|
|
131
|
+
const out = [];
|
|
132
|
+
for (const alt of alternatives) {
|
|
133
|
+
out.push(...expandBraces(prefix + alt + suffix, budget));
|
|
134
|
+
// The single early return for both budget orders: the remaining 2^N
|
|
135
|
+
// paths are never walked once either cap is spent.
|
|
136
|
+
if (budgetSpent(budget))
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
// A brace without a top-level comma or range is not an expansion point, but
|
|
142
|
+
// braces nested inside it may still expand (npm's `{a{b,c}}` → `{ab}`,`{ac}`).
|
|
143
|
+
const inner = expandBraces(body, budget);
|
|
144
|
+
if (budgetSpent(budget))
|
|
145
|
+
return [];
|
|
146
|
+
if (inner.length === 1 && inner[0] === body)
|
|
147
|
+
return [pattern];
|
|
148
|
+
return inner.map((alt) => `${prefix}{${alt}}${suffix}`);
|
|
149
|
+
}
|
|
150
|
+
function parseCharClass(pattern, start) {
|
|
151
|
+
let index = start + 1;
|
|
152
|
+
let negated = false;
|
|
153
|
+
if (pattern[index] === '!' || pattern[index] === '^') {
|
|
154
|
+
negated = true;
|
|
155
|
+
index += 1;
|
|
156
|
+
}
|
|
157
|
+
let content = '';
|
|
158
|
+
let first = true;
|
|
159
|
+
while (index < pattern.length) {
|
|
160
|
+
const char = pattern[index];
|
|
161
|
+
if (char === ']' && !first)
|
|
162
|
+
break;
|
|
163
|
+
content += char;
|
|
164
|
+
first = false;
|
|
165
|
+
index += 1;
|
|
166
|
+
}
|
|
167
|
+
if (pattern[index] !== ']')
|
|
168
|
+
return undefined;
|
|
169
|
+
// POSIX bracket classes are outside the ported subset: the first `]` of
|
|
170
|
+
// `[[:alpha:]]` would otherwise close the class early and match a bogus
|
|
171
|
+
// two-character name. Never-match instead of a false positive.
|
|
172
|
+
if (content.includes('[:'))
|
|
173
|
+
return { source: '(?!)', end: index + 1, dotOnly: false };
|
|
174
|
+
let body = '';
|
|
175
|
+
for (const char of content) {
|
|
176
|
+
if (char === '\\' || char === ']' || char === '^')
|
|
177
|
+
body += `\\${char}`;
|
|
178
|
+
else
|
|
179
|
+
body += char;
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
source: negated ? `[^${body}]` : `[${body}]`,
|
|
183
|
+
end: index + 1,
|
|
184
|
+
dotOnly: !negated && content === '.',
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function findCloseParen(pattern, start) {
|
|
188
|
+
let depth = 0;
|
|
189
|
+
for (let index = start; index < pattern.length; index += 1) {
|
|
190
|
+
const char = pattern[index];
|
|
191
|
+
if (char === '(')
|
|
192
|
+
depth += 1;
|
|
193
|
+
else if (char === ')') {
|
|
194
|
+
depth -= 1;
|
|
195
|
+
if (depth === 0)
|
|
196
|
+
return index;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return -1;
|
|
200
|
+
}
|
|
201
|
+
function splitExtglobAlternatives(body) {
|
|
202
|
+
const parts = [];
|
|
203
|
+
let depth = 0;
|
|
204
|
+
let classOpen = false;
|
|
205
|
+
let from = 0;
|
|
206
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
207
|
+
const char = body[index];
|
|
208
|
+
if (char === '[')
|
|
209
|
+
classOpen = true;
|
|
210
|
+
else if (char === ']')
|
|
211
|
+
classOpen = false;
|
|
212
|
+
else if (classOpen)
|
|
213
|
+
continue;
|
|
214
|
+
else if (char === '(')
|
|
215
|
+
depth += 1;
|
|
216
|
+
else if (char === ')')
|
|
217
|
+
depth -= 1;
|
|
218
|
+
else if (char === '|' && depth === 0) {
|
|
219
|
+
parts.push(body.slice(from, index));
|
|
220
|
+
from = index + 1;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
parts.push(body.slice(from));
|
|
224
|
+
return parts;
|
|
225
|
+
}
|
|
226
|
+
function segmentSource(segment) {
|
|
227
|
+
let source = '';
|
|
228
|
+
for (let index = 0; index < segment.length; index += 1) {
|
|
229
|
+
const char = segment[index];
|
|
230
|
+
if ('@+*?!'.includes(char) && segment[index + 1] === '(') {
|
|
231
|
+
const close = findCloseParen(segment, index + 1);
|
|
232
|
+
if (close < 0) {
|
|
233
|
+
source += escapeRegExp(char);
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
const alternatives = splitExtglobAlternatives(segment.slice(index + 2, close));
|
|
237
|
+
// Alternatives containing a path separator are outside the ported subset.
|
|
238
|
+
if (alternatives.some((alt) => alt.includes('/'))) {
|
|
239
|
+
source += escapeRegExp(segment.slice(index, close + 1));
|
|
240
|
+
index = close;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const inner = alternatives.map((alt) => segmentSource(alt)).join('|') || '';
|
|
244
|
+
if (char === '@')
|
|
245
|
+
source += `(?:${inner})`;
|
|
246
|
+
else if (char === '?')
|
|
247
|
+
source += `(?:${inner})?`;
|
|
248
|
+
else if (char === '*')
|
|
249
|
+
source += `(?:${inner})*`;
|
|
250
|
+
else if (char === '+')
|
|
251
|
+
source += `(?:${inner})+`;
|
|
252
|
+
else
|
|
253
|
+
source += `(?!(?:${inner})$)[^/]*`;
|
|
254
|
+
index = close;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (char === '*') {
|
|
258
|
+
// `**` glued to a literal stays inside one segment (minimatch's `*b`).
|
|
259
|
+
while (segment[index + 1] === '*')
|
|
260
|
+
index += 1;
|
|
261
|
+
source += '[^/]*';
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (char === '?') {
|
|
265
|
+
source += '[^/]';
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (char === '[') {
|
|
269
|
+
const parsed = parseCharClass(segment, index);
|
|
270
|
+
if (parsed) {
|
|
271
|
+
source += parsed.dotOnly ? '\\.' : parsed.source;
|
|
272
|
+
index = parsed.end - 1;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
source += escapeRegExp(char);
|
|
277
|
+
}
|
|
278
|
+
return source;
|
|
279
|
+
}
|
|
280
|
+
// A leading dot is visible to a wildcard only when the segment's first token
|
|
281
|
+
// names it: a literal `.`, a class that folds to exactly `.`, or an extglob
|
|
282
|
+
// alternative that allows it (minimatch's `dot: false`).
|
|
283
|
+
function segmentAllowsDot(segment) {
|
|
284
|
+
if (segment === '' || segment[0] === '.')
|
|
285
|
+
return true;
|
|
286
|
+
if (segment[0] === '[')
|
|
287
|
+
return parseCharClass(segment, 0)?.dotOnly ?? false;
|
|
288
|
+
const operator = segment[0];
|
|
289
|
+
if ('@+*?!'.includes(operator) && segment[1] === '(') {
|
|
290
|
+
if (operator === '!')
|
|
291
|
+
return false;
|
|
292
|
+
const close = findCloseParen(segment, 1);
|
|
293
|
+
if (close < 0)
|
|
294
|
+
return false;
|
|
295
|
+
return splitExtglobAlternatives(segment.slice(2, close)).some((alt) => segmentAllowsDot(alt));
|
|
296
|
+
}
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
function matchSegment(part, segment) {
|
|
300
|
+
if (segment === '')
|
|
301
|
+
return part === '';
|
|
302
|
+
if (part === '')
|
|
303
|
+
return false;
|
|
304
|
+
if (part.startsWith('.') && !segmentAllowsDot(segment))
|
|
305
|
+
return false;
|
|
306
|
+
try {
|
|
307
|
+
return new RegExp(`^${segmentSource(segment)}$`).test(part);
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
// npm/minimatch silently match nothing for an invalid class (a reversed
|
|
311
|
+
// range); a hostile declaration is input, never a crash source.
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function matchSegments(path, pattern) {
|
|
316
|
+
// Memoize (pattern index, path index): stacked `**` patterns otherwise
|
|
317
|
+
// backtrack exponentially, a stall npm never exhibits.
|
|
318
|
+
const memo = new Map();
|
|
319
|
+
const walk = (patternIndex, pathIndex) => {
|
|
320
|
+
const key = `${patternIndex}:${pathIndex}`;
|
|
321
|
+
const cached = memo.get(key);
|
|
322
|
+
if (cached !== undefined)
|
|
323
|
+
return cached;
|
|
324
|
+
let result;
|
|
325
|
+
if (patternIndex === pattern.length) {
|
|
326
|
+
result = pathIndex === path.length;
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
const segment = pattern[patternIndex];
|
|
330
|
+
if (segment === GLOBSTAR) {
|
|
331
|
+
result = walk(patternIndex + 1, pathIndex);
|
|
332
|
+
if (!result && pathIndex < path.length) {
|
|
333
|
+
const part = path[pathIndex];
|
|
334
|
+
if (part !== '.' && part !== '..' && !part.startsWith('.'))
|
|
335
|
+
result = walk(patternIndex, pathIndex + 1);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
else if (pathIndex >= path.length) {
|
|
339
|
+
result = false;
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
result = matchSegment(path[pathIndex], segment) && walk(patternIndex + 1, pathIndex + 1);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
memo.set(key, result);
|
|
346
|
+
return result;
|
|
347
|
+
};
|
|
348
|
+
return walk(0, 0);
|
|
349
|
+
}
|
|
350
|
+
function splitPath(value) {
|
|
351
|
+
// minimatch coalesces repeated slashes unless `preserveMultipleSlashes`.
|
|
352
|
+
const trimmed = value.replace(/\/+$/, '');
|
|
353
|
+
return trimmed ? trimmed.split(/\/+/) : [];
|
|
354
|
+
}
|
|
355
|
+
function patternSegments(pattern) {
|
|
356
|
+
const normalized = [];
|
|
357
|
+
for (const segment of splitPath(pattern)) {
|
|
358
|
+
if (segment === '..') {
|
|
359
|
+
const previous = normalized.at(-1);
|
|
360
|
+
if (previous !== undefined && previous !== '..' && previous !== GLOBSTAR)
|
|
361
|
+
normalized.pop();
|
|
362
|
+
else
|
|
363
|
+
normalized.push(segment);
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
normalized.push(segment === '**' ? GLOBSTAR : segment);
|
|
367
|
+
}
|
|
368
|
+
// glob drops a `.` only when it is the trailing segment; an interior `.` is
|
|
369
|
+
// a literal directory name npm never matches.
|
|
370
|
+
if (normalized.at(-1) === '.')
|
|
371
|
+
normalized.pop();
|
|
372
|
+
return normalized;
|
|
373
|
+
}
|
|
374
|
+
// A directory's membership: the path is matched as a directory (map-workspaces
|
|
375
|
+
// appends `/` to each positive glob), so a trailing `**` covers the glob's own
|
|
376
|
+
// parent (`packages/**` matches `packages`).
|
|
377
|
+
function matchDirectory(relativePath, pattern) {
|
|
378
|
+
return expandBraces(pattern).some((expanded) => matchSegments(splitPath(relativePath), patternSegments(expanded)));
|
|
379
|
+
}
|
|
380
|
+
// Pattern-vs-pattern comparisons inside the negation cancellation treat the
|
|
381
|
+
// first argument as a literal path string, as minimatch does.
|
|
382
|
+
function matchesPatternString(pathString, pattern) {
|
|
383
|
+
return expandBraces(pattern).some((expanded) => matchSegments(splitPath(pathString), patternSegments(expanded)));
|
|
384
|
+
}
|
|
385
|
+
function orderPatterns(globs) {
|
|
386
|
+
const patterns = [];
|
|
387
|
+
const negated = [];
|
|
388
|
+
for (const raw of globs) {
|
|
389
|
+
const excl = /^!+/.exec(raw);
|
|
390
|
+
let pattern = excl ? raw.slice(excl[0].length) : raw;
|
|
391
|
+
pattern = pattern.replace(/^\.?\/+/, '');
|
|
392
|
+
const negate = Boolean(excl && excl[0].length % 2 === 1);
|
|
393
|
+
// npm's getGlobPattern normalizes backslashes for positive globs only.
|
|
394
|
+
if (!negate)
|
|
395
|
+
pattern = pattern.replace(/\\/g, '/');
|
|
396
|
+
if (negate) {
|
|
397
|
+
negated.push(pattern);
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
// A later positive pattern overrides the earlier negation it covers.
|
|
401
|
+
for (let index = 0; index < negated.length; index += 1) {
|
|
402
|
+
if (matchesPatternString(pattern, negated[index]))
|
|
403
|
+
negated.splice(index, 1);
|
|
404
|
+
}
|
|
405
|
+
patterns.push(pattern);
|
|
406
|
+
}
|
|
407
|
+
// An un-cancelled negation removes the positive patterns it covers.
|
|
408
|
+
for (const blocked of negated) {
|
|
409
|
+
for (const pattern of [...patterns]) {
|
|
410
|
+
if (matchesPatternString(pattern, blocked))
|
|
411
|
+
patterns.splice(patterns.indexOf(pattern), 1);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return { patterns, negated };
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Whether `memberPath` (relative, POSIX separators) is a workspace member of
|
|
418
|
+
* the given declaration, matching `@npmcli/map-workspaces` semantics.
|
|
419
|
+
*/
|
|
420
|
+
export function workspaceMemberMatch(memberPath, globs) {
|
|
421
|
+
try {
|
|
422
|
+
if (!memberPath || memberPath === '..' || memberPath.startsWith('../'))
|
|
423
|
+
return false;
|
|
424
|
+
const segments = memberPath.split('/');
|
|
425
|
+
// map-workspaces ignores `**/node_modules/**` before the pattern list
|
|
426
|
+
// applies; glob's directory candidates end in `/`, so the node_modules
|
|
427
|
+
// directory itself is covered too.
|
|
428
|
+
if (segments.includes('node_modules'))
|
|
429
|
+
return false;
|
|
430
|
+
const { patterns, negated } = orderPatterns(globs);
|
|
431
|
+
if (negated.some((blocked) => matchDirectory(memberPath, blocked)))
|
|
432
|
+
return false;
|
|
433
|
+
return patterns.some((pattern) => matchDirectory(memberPath, pattern));
|
|
434
|
+
}
|
|
435
|
+
catch {
|
|
436
|
+
// Load-bearing: a pathological declaration can overflow the brace
|
|
437
|
+
// recursion (RangeError) or hit another unexpected syntax error; the
|
|
438
|
+
// per-segment regex compile is caught earlier. Degrading here keeps any
|
|
439
|
+
// such declaration a non-member instead of aborting the pre-flight.
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
@@ -18,6 +18,7 @@ import { applyUserDelta, extractUserDelta, mergeArgsStyle } from "./mcp-config-m
|
|
|
18
18
|
import { saveAgentDelta, takeAgentDelta } from "./mcp-config-backup.js";
|
|
19
19
|
import { applyPacksToEntry } from "./packs-policy.js";
|
|
20
20
|
import { copyDir, deployWord, PLUGIN_ROOT } from "./install-payload.js";
|
|
21
|
+
import { codexApprovalEnv, codexApprovalToolsBlock, CODEX_APPROVAL_MODE_ENV } from "./agents/codex-config.js";
|
|
21
22
|
// openclaw and codex-desktop both ship a .mcp.json plus the .codex-plugin
|
|
22
23
|
// manifest into their plugin dir — the codex-discoverable plugin-dir shape;
|
|
23
24
|
// the agentKey spells the delta-backup bucket in writeMcpServersFile. Moved
|
|
@@ -145,7 +146,33 @@ export function writeMcpServersFile(pluginDest, mcpPath, agentKey) {
|
|
|
145
146
|
finalEntry = asRecord(applyUserDelta(entry, delta, 'args'));
|
|
146
147
|
}
|
|
147
148
|
const packsChanged = applyPacksToEntry(finalEntry, 'env', agentKey === 'openclaw' ? 'OpenClaw' : 'Codex Desktop');
|
|
148
|
-
|
|
149
|
+
// The codex client yield (PR-5): the per-tool approve blocks inside the
|
|
150
|
+
// devkit-owned server entry — codex reads them from the plugin-provided
|
|
151
|
+
// server definition (the config.toml route is refused by codex's own
|
|
152
|
+
// bootstrap validation when the implied server has no transport; see
|
|
153
|
+
// agents/codex-config.ts). OpenClaw shares this writer but is not codex,
|
|
154
|
+
// so its .mcp.json stays block-free. The block is ours wholesale — the
|
|
155
|
+
// file is devkit-owned and regenerated — and a drift (an older deploy's
|
|
156
|
+
// missing or hand-stripped tools map) counts as a change so the next
|
|
157
|
+
// update heals it, same as the packs write above.
|
|
158
|
+
let toolsChanged = false;
|
|
159
|
+
let envChanged = false;
|
|
160
|
+
if (agentKey !== 'openclaw') {
|
|
161
|
+
const wanted = codexApprovalToolsBlock();
|
|
162
|
+
toolsChanged = JSON.stringify(finalEntry.tools) !== JSON.stringify(wanted);
|
|
163
|
+
if (toolsChanged)
|
|
164
|
+
finalEntry.tools = wanted;
|
|
165
|
+
// The ask-mode env half rides the same codex-only condition as the tools
|
|
166
|
+
// block (openclaw is not codex and stays both block- and env-free). The
|
|
167
|
+
// env is ours wholesale too — same doctrine, same drift healing: a stale
|
|
168
|
+
// or hand-edited copy is a change, so the next update restores it.
|
|
169
|
+
const entryEnv = asRecord(finalEntry.env);
|
|
170
|
+
if (entryEnv.DEVKIT_APPROVAL_MODE !== CODEX_APPROVAL_MODE_ENV) {
|
|
171
|
+
finalEntry.env = { ...entryEnv, ...codexApprovalEnv() };
|
|
172
|
+
envChanged = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (existing && !changed && !packsChanged && !toolsChanged && !envChanged) {
|
|
149
176
|
console.log(` MCP Config unchanged: ${configPath}`);
|
|
150
177
|
return;
|
|
151
178
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
3
|
+
import { ErrorCode, McpError, } from '@modelcontextprotocol/sdk/types.js';
|
|
3
4
|
import { TOOL_DEFINITIONS, callTool, verifySkillTree, SKILLS_ROOT, } from "./tools.js";
|
|
4
5
|
import { PACK_OF } from "./packs/registry.js";
|
|
5
6
|
import { resolveEnabledPacks } from "./packs/enable.js";
|
|
@@ -8,6 +9,7 @@ import { peekCachedUpdateInfo, applyUpdateHint, readInstalledVersion } from "./u
|
|
|
8
9
|
import { initTelemetry } from "./telemetry/telemetry.js";
|
|
9
10
|
import { detectAgent } from "./telemetry/agent-detect.js";
|
|
10
11
|
import { asRecord } from "./lib/as-record.js";
|
|
12
|
+
import { approvalModeFromEnv } from "./lib/approval-mode.js";
|
|
11
13
|
const pkgVersion = readInstalledVersion() || '0.0.0';
|
|
12
14
|
// Server-level instructions ride the initialize handshake result — the one
|
|
13
15
|
// teaching surface that needs neither a skill load nor a description read.
|
|
@@ -97,6 +99,21 @@ const VENDOR_BOUNDARY_RULE = 'Vendor boundary: tools or skills being available i
|
|
|
97
99
|
"For a request that involves cloud resources but names no vendor, infer the vendor only from an explicit mention, hcloud/KooCLI artifacts, myhuaweicloud endpoints, Huawei region IDs, or earlier turns of this conversation — generic service vocabulary (ECS, VPC, RDS, serverless) and the devkit's own presence do not infer it. " +
|
|
98
100
|
"When the vendor is still unknown, ask the user which cloud they mean before operating on cloud resources through any tool or hcloud command, and before probing Huawei Cloud tooling, credential, or account state (CLI install checks, profile reads, auth status). Cloud-facing tools enforce this with a vendorConfirmed parameter — pass the user's establishing words as its value, never an invented quote. " +
|
|
99
101
|
"Requests that are not cloud tasks are outside this rule; tasks for other clouds remain answerable from general knowledge — the devkit's tools themselves only operate on Huawei Cloud. ";
|
|
102
|
+
// Harness tool-routing failure, shared by the stdio instruction forms (the
|
|
103
|
+
// remote face rides no harness model wire — see the remote return).
|
|
104
|
+
// Measured failure (2026-11-13, live codex 0.167.2 session + reproduced
|
|
105
|
+
// against the same provider): codex presents MCP tools as namespace-type
|
|
106
|
+
// tools and dispatches ONLY through the `namespace` field on function_call
|
|
107
|
+
// items, with no flat-name fallback; a custom OpenAI-compatible model
|
|
108
|
+
// gateway that drops that field (request history and/or generated calls)
|
|
109
|
+
// turns every regenerated call namespace-less, codex's registry
|
|
110
|
+
// (namespace, name) exact-match misses, and the harness answers
|
|
111
|
+
// `unsupported call: <tool>` — 690 of 692 huaweicloud calls in the dump,
|
|
112
|
+
// none ever reaching the devkit server, while the model retried the
|
|
113
|
+
// identical call in a spin. The devkit cannot observe or fix these
|
|
114
|
+
// calls; the only devkit-side lever is teaching the agent what the
|
|
115
|
+
// signature means so the spin stops after one reply.
|
|
116
|
+
const UNSUPPORTED_CALL_RULE = 'Tool-routing note: a reply "unsupported call: <tool>" naming a huaweicloud tool comes from your harness client, not from the devkit or Huawei Cloud — the call never reached this server, so retrying the identical call cannot succeed; report it to the user once and stop. ';
|
|
100
117
|
export function instructionsFor(remote, runtimePacks = false) {
|
|
101
118
|
if (remote) {
|
|
102
119
|
return ('Skill loading: call huaweicloud_list_skills once for the effective skill catalog ' +
|
|
@@ -135,6 +152,7 @@ export function instructionsFor(remote, runtimePacks = false) {
|
|
|
135
152
|
// directory, and the stdio instructions render on both.
|
|
136
153
|
"Root disambiguation: huawei-* pack-owned service skills live only in this tree — on directory-loading agents, the native skills directory carrying the six huaweicloud-* meta-skill copies in your context is a different root, so never guess a service skill's path by analogy to it; the tree location stated above (skillRoot, the field a huaweicloud_list_skills payload carries) must be in hand before the first service-skill read, never fetched in parallel with a guessed one. " +
|
|
137
154
|
VENDOR_BOUNDARY_RULE +
|
|
155
|
+
UNSUPPORTED_CALL_RULE +
|
|
138
156
|
'Route Huawei Cloud tasks through the huaweicloud-core skill; browse packs with huaweicloud_list_packs.');
|
|
139
157
|
}
|
|
140
158
|
// 会话内首个非 check/upgrade 工具调用附加 _updateInfo,只消费一次。
|
|
@@ -215,8 +233,45 @@ export function normalizeToolCallParams(message) {
|
|
|
215
233
|
}
|
|
216
234
|
return message;
|
|
217
235
|
}
|
|
236
|
+
// The server-run confirmation seam (PR-1.5). The SDK captures the client's
|
|
237
|
+
// initialize params on the per-session Server instance (that IS the session
|
|
238
|
+
// record), so `capable` reads the declared `elicitation.form` capability and
|
|
239
|
+
// never re-probes. The prompt raises a form-mode elicitation with an
|
|
240
|
+
// explicit timeout and resolves every failure as a decision: the gate
|
|
241
|
+
// refuses fail-closed instead of surfacing a transport error as the tool
|
|
242
|
+
// result. Never wired on the remote face (it forces token mode and must not
|
|
243
|
+
// elicit).
|
|
244
|
+
// The SDK's request-timeout code (-32001) as a plain number: the enum type
|
|
245
|
+
// has no shared member with the wire error's numeric code, so compare numbers.
|
|
246
|
+
const REQUEST_TIMEOUT_CODE = ErrorCode.RequestTimeout;
|
|
247
|
+
function createElicitationSeam(server) {
|
|
248
|
+
return {
|
|
249
|
+
get capable() {
|
|
250
|
+
return server.server.getClientCapabilities()?.elicitation?.form !== undefined;
|
|
251
|
+
},
|
|
252
|
+
async prompt({ message, schema, timeoutMs }) {
|
|
253
|
+
try {
|
|
254
|
+
const result = await server.server.elicitInput({ mode: 'form', message, requestedSchema: schema }, { timeout: timeoutMs });
|
|
255
|
+
return { decision: result.action, content: result.content };
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
if (error instanceof McpError && error.code === REQUEST_TIMEOUT_CODE) {
|
|
259
|
+
return { decision: 'timeout', detail: error.message };
|
|
260
|
+
}
|
|
261
|
+
return { decision: 'error', detail: error instanceof Error ? error.message : String(error) };
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
}
|
|
218
266
|
export function createDevkitMcpServer({ sessionId, runtimePacks = false, remoteSurface = false, } = {}) {
|
|
219
267
|
assertConstructedSchemas();
|
|
268
|
+
// The approval posture resolves once at construction: a bogus
|
|
269
|
+
// DEVKIT_APPROVAL_MODE throws here (boot fail-fast, the same doctrine
|
|
270
|
+
// DEVKIT_PACKS applies through syncDisclosure). The value itself is read
|
|
271
|
+
// per call by the gate, and it no longer changes the wire surface: the
|
|
272
|
+
// PR-1.5 flip removed the client interaction flag, because the server
|
|
273
|
+
// raises the confirmation now.
|
|
274
|
+
approvalModeFromEnv(process.env);
|
|
220
275
|
// The contradictory construction is refused, not cautioned: a remote that
|
|
221
276
|
// also carried runtime pack toggling would attach the onPacksChanged seam
|
|
222
277
|
// to every callOpts, publishing the server host's absolute install path
|
|
@@ -270,10 +325,26 @@ export function createDevkitMcpServer({ sessionId, runtimePacks = false, remoteS
|
|
|
270
325
|
(runtimePacks || tool.name !== 'huaweicloud_packs_configure') &&
|
|
271
326
|
(!remoteSurface || (PACK_OF[tool.name] !== 'secrets' && !REMOTE_WITHHELD_LOCAL_WRITERS.has(tool.name)));
|
|
272
327
|
const registerOne = (tool) => {
|
|
273
|
-
registered.set(tool.name, server.registerTool(tool.name, {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
328
|
+
registered.set(tool.name, server.registerTool(tool.name, {
|
|
329
|
+
description: tool.description,
|
|
330
|
+
inputSchema: getToolSchema(tool.name),
|
|
331
|
+
// No client interaction flag (PR-1.5 flip). The confirmation runs
|
|
332
|
+
// on the server now: on an elicitation-capable client the gate
|
|
333
|
+
// raises its own form, and on the rest the T3 chat round-trip is
|
|
334
|
+
// the confirmation. A client dialog ahead of either would
|
|
335
|
+
// double-confirm (codex measured the two-interaction sequence:
|
|
336
|
+
// its own approval prompt, then the server form), so roster tools
|
|
337
|
+
// carry no `anthropic/requiresUserInteraction`. The machinery
|
|
338
|
+
// stays roster-driven where it lives: nothing here keys on the
|
|
339
|
+
// roster because the policy emits nothing for any tool.
|
|
340
|
+
}, async (args) => {
|
|
341
|
+
// The server-run confirmation seam rides every stdio call; the
|
|
342
|
+
// remote face never wires it (ask mode is force-downgraded there).
|
|
343
|
+
const elicitation = remoteSurface ? undefined : createElicitationSeam(server);
|
|
344
|
+
const callOpts = {
|
|
345
|
+
...(runtimePacks ? { sessionId, onPacksChanged: () => syncDisclosure() } : { sessionId }),
|
|
346
|
+
...(elicitation ? { elicitation } : {}),
|
|
347
|
+
};
|
|
277
348
|
const result = await callTool(tool.name, args, callOpts);
|
|
278
349
|
const decorated = _decorateResult(sessionId, tool.name, result);
|
|
279
350
|
return {
|