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
|
@@ -0,0 +1,414 @@
|
|
|
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
|
+
|
|
17
|
+
const GLOBSTAR = '\u0000globstar';
|
|
18
|
+
|
|
19
|
+
function escapeRegExp(char: string): string {
|
|
20
|
+
return /[.*+?^${}()|[\]\\]/.test(char) ? `\\${char}` : char;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function findBrace(pattern: string): { start: number; end: number } | undefined {
|
|
24
|
+
let start = -1;
|
|
25
|
+
let depth = 0;
|
|
26
|
+
let escaped = false;
|
|
27
|
+
for (let index = 0; index < pattern.length; index += 1) {
|
|
28
|
+
const char = pattern[index]!;
|
|
29
|
+
if (escaped) {
|
|
30
|
+
escaped = false;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (char === '\\') {
|
|
34
|
+
escaped = true;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (char === '{') {
|
|
38
|
+
if (depth === 0) start = index;
|
|
39
|
+
depth += 1;
|
|
40
|
+
} else if (char === '}' && depth > 0) {
|
|
41
|
+
depth -= 1;
|
|
42
|
+
if (depth === 0) return { start, end: index };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function splitBraceAlternatives(body: string): string[] | undefined {
|
|
49
|
+
const parts: string[] = [];
|
|
50
|
+
let depth = 0;
|
|
51
|
+
let from = 0;
|
|
52
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
53
|
+
const char = body[index]!;
|
|
54
|
+
if (char === '{') depth += 1;
|
|
55
|
+
else if (char === '}') depth -= 1;
|
|
56
|
+
else if (char === ',' && depth === 0) {
|
|
57
|
+
parts.push(body.slice(from, index));
|
|
58
|
+
from = index + 1;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!parts.length) return undefined;
|
|
62
|
+
parts.push(body.slice(from));
|
|
63
|
+
return parts;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function expandBraceRange(body: string, limit: number): string[] | undefined {
|
|
67
|
+
const match = /^(-?\d+|[A-Za-z])\.\.(-?\d+|[A-Za-z])(?:\.\.(-?\d+))?$/.exec(body);
|
|
68
|
+
if (!match) return undefined;
|
|
69
|
+
const [, fromRaw, toRaw, stepRaw] = match;
|
|
70
|
+
const numeric = /^-?\d+$/.test(fromRaw!) && /^-?\d+$/.test(toRaw!);
|
|
71
|
+
const from = numeric ? Number(fromRaw) : (fromRaw!.codePointAt(0) ?? 0);
|
|
72
|
+
const to = numeric ? Number(toRaw) : (toRaw!.codePointAt(0) ?? 0);
|
|
73
|
+
const step = Math.abs(Number(stepRaw ?? 1)) || 1;
|
|
74
|
+
// npm formats at the width of the raw endpoints (sign included), padding a
|
|
75
|
+
// negative after its sign, and truncates the sequence at the expansion cap.
|
|
76
|
+
const width = Math.max(fromRaw!.length, toRaw!.length);
|
|
77
|
+
const paddedParts = stepRaw === undefined ? [fromRaw!, toRaw!] : [fromRaw!, toRaw!, stepRaw];
|
|
78
|
+
// npm's isPadded tests every sequence part, the step included.
|
|
79
|
+
const padded = numeric && paddedParts.some((part) => /^-?0\d/.test(part));
|
|
80
|
+
const out: string[] = [];
|
|
81
|
+
const direction = from <= to ? 1 : -1;
|
|
82
|
+
for (let value = from; direction > 0 ? value <= to : value >= to; value += direction * step) {
|
|
83
|
+
if (out.length >= limit) break;
|
|
84
|
+
if (numeric) {
|
|
85
|
+
let text = String(value);
|
|
86
|
+
const need = width - text.length;
|
|
87
|
+
if (padded && need > 0) {
|
|
88
|
+
const zeros = '0'.repeat(need);
|
|
89
|
+
text = value < 0 ? `-${zeros}${text.slice(1)}` : `${zeros}${text}`;
|
|
90
|
+
}
|
|
91
|
+
out.push(text);
|
|
92
|
+
} else {
|
|
93
|
+
out.push(String.fromCodePoint(value));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// npm's brace-expansion refuses beyond 100k entries; the same budget keeps a
|
|
100
|
+
// hostile declaration bounded instead of exhausting memory.
|
|
101
|
+
const BRACE_EXPANSION_LIMIT = 100_000;
|
|
102
|
+
// npm also bounds the total expanded characters (EXPANSION_MAX_LENGTH).
|
|
103
|
+
const BRACE_CHARACTER_LIMIT = 4_000_000;
|
|
104
|
+
type BraceBudget = { left: number; chars: number };
|
|
105
|
+
// INVARIANT (budget first-to-bind): every expansion node checks BOTH budgets;
|
|
106
|
+
// the walk returns the accumulated output the moment EITHER is spent, so the
|
|
107
|
+
// entry order and the character order are both bounded by the same guard. A
|
|
108
|
+
// rejected leaf poisons the character budget (chars = -1) so the loop's single
|
|
109
|
+
// early return fires instead of walking the remaining paths.
|
|
110
|
+
const budgetSpent = (budget: BraceBudget) => budget.left <= 0 || budget.chars < 0;
|
|
111
|
+
|
|
112
|
+
function expandBraces(
|
|
113
|
+
pattern: string,
|
|
114
|
+
budget: BraceBudget = { left: BRACE_EXPANSION_LIMIT, chars: BRACE_CHARACTER_LIMIT },
|
|
115
|
+
): string[] {
|
|
116
|
+
const brace = findBrace(pattern);
|
|
117
|
+
if (!brace) {
|
|
118
|
+
if (budgetSpent(budget)) return [];
|
|
119
|
+
if (budget.chars < pattern.length) {
|
|
120
|
+
budget.chars = -1;
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
budget.left -= 1;
|
|
124
|
+
budget.chars -= pattern.length;
|
|
125
|
+
return [pattern];
|
|
126
|
+
}
|
|
127
|
+
const body = pattern.slice(brace.start + 1, brace.end);
|
|
128
|
+
const prefix = pattern.slice(0, brace.start);
|
|
129
|
+
const suffix = pattern.slice(brace.end + 1);
|
|
130
|
+
const alternatives = splitBraceAlternatives(body) ?? expandBraceRange(body, Math.max(0, budget.left));
|
|
131
|
+
if (alternatives) {
|
|
132
|
+
const out: string[] = [];
|
|
133
|
+
for (const alt of alternatives) {
|
|
134
|
+
out.push(...expandBraces(prefix + alt + suffix, budget));
|
|
135
|
+
// The single early return for both budget orders: the remaining 2^N
|
|
136
|
+
// paths are never walked once either cap is spent.
|
|
137
|
+
if (budgetSpent(budget)) 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)) return [];
|
|
145
|
+
if (inner.length === 1 && inner[0] === body) return [pattern];
|
|
146
|
+
return inner.map((alt) => `${prefix}{${alt}}${suffix}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
type CharClass = { source: string; end: number; dotOnly: boolean };
|
|
150
|
+
|
|
151
|
+
function parseCharClass(pattern: string, start: number): CharClass | undefined {
|
|
152
|
+
let index = start + 1;
|
|
153
|
+
let negated = false;
|
|
154
|
+
if (pattern[index] === '!' || pattern[index] === '^') {
|
|
155
|
+
negated = true;
|
|
156
|
+
index += 1;
|
|
157
|
+
}
|
|
158
|
+
let content = '';
|
|
159
|
+
let first = true;
|
|
160
|
+
while (index < pattern.length) {
|
|
161
|
+
const char = pattern[index]!;
|
|
162
|
+
if (char === ']' && !first) break;
|
|
163
|
+
content += char;
|
|
164
|
+
first = false;
|
|
165
|
+
index += 1;
|
|
166
|
+
}
|
|
167
|
+
if (pattern[index] !== ']') return undefined;
|
|
168
|
+
// POSIX bracket classes are outside the ported subset: the first `]` of
|
|
169
|
+
// `[[:alpha:]]` would otherwise close the class early and match a bogus
|
|
170
|
+
// two-character name. Never-match instead of a false positive.
|
|
171
|
+
if (content.includes('[:')) return { source: '(?!)', end: index + 1, dotOnly: false };
|
|
172
|
+
let body = '';
|
|
173
|
+
for (const char of content) {
|
|
174
|
+
if (char === '\\' || char === ']' || char === '^') body += `\\${char}`;
|
|
175
|
+
else body += char;
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
source: negated ? `[^${body}]` : `[${body}]`,
|
|
179
|
+
end: index + 1,
|
|
180
|
+
dotOnly: !negated && content === '.',
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function findCloseParen(pattern: string, start: number): number {
|
|
185
|
+
let depth = 0;
|
|
186
|
+
for (let index = start; index < pattern.length; index += 1) {
|
|
187
|
+
const char = pattern[index]!;
|
|
188
|
+
if (char === '(') depth += 1;
|
|
189
|
+
else if (char === ')') {
|
|
190
|
+
depth -= 1;
|
|
191
|
+
if (depth === 0) return index;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return -1;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function splitExtglobAlternatives(body: string): string[] {
|
|
198
|
+
const parts: string[] = [];
|
|
199
|
+
let depth = 0;
|
|
200
|
+
let classOpen = false;
|
|
201
|
+
let from = 0;
|
|
202
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
203
|
+
const char = body[index]!;
|
|
204
|
+
if (char === '[') classOpen = true;
|
|
205
|
+
else if (char === ']') classOpen = false;
|
|
206
|
+
else if (classOpen) continue;
|
|
207
|
+
else if (char === '(') depth += 1;
|
|
208
|
+
else if (char === ')') depth -= 1;
|
|
209
|
+
else if (char === '|' && depth === 0) {
|
|
210
|
+
parts.push(body.slice(from, index));
|
|
211
|
+
from = index + 1;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
parts.push(body.slice(from));
|
|
215
|
+
return parts;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function segmentSource(segment: string): string {
|
|
219
|
+
let source = '';
|
|
220
|
+
for (let index = 0; index < segment.length; index += 1) {
|
|
221
|
+
const char = segment[index]!;
|
|
222
|
+
if ('@+*?!'.includes(char) && segment[index + 1] === '(') {
|
|
223
|
+
const close = findCloseParen(segment, index + 1);
|
|
224
|
+
if (close < 0) {
|
|
225
|
+
source += escapeRegExp(char);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const alternatives = splitExtglobAlternatives(segment.slice(index + 2, close));
|
|
229
|
+
// Alternatives containing a path separator are outside the ported subset.
|
|
230
|
+
if (alternatives.some((alt) => alt.includes('/'))) {
|
|
231
|
+
source += escapeRegExp(segment.slice(index, close + 1));
|
|
232
|
+
index = close;
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const inner = alternatives.map((alt) => segmentSource(alt)).join('|') || '';
|
|
236
|
+
if (char === '@') source += `(?:${inner})`;
|
|
237
|
+
else if (char === '?') source += `(?:${inner})?`;
|
|
238
|
+
else if (char === '*') source += `(?:${inner})*`;
|
|
239
|
+
else if (char === '+') source += `(?:${inner})+`;
|
|
240
|
+
else source += `(?!(?:${inner})$)[^/]*`;
|
|
241
|
+
index = close;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (char === '*') {
|
|
245
|
+
// `**` glued to a literal stays inside one segment (minimatch's `*b`).
|
|
246
|
+
while (segment[index + 1] === '*') index += 1;
|
|
247
|
+
source += '[^/]*';
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (char === '?') {
|
|
251
|
+
source += '[^/]';
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (char === '[') {
|
|
255
|
+
const parsed = parseCharClass(segment, index);
|
|
256
|
+
if (parsed) {
|
|
257
|
+
source += parsed.dotOnly ? '\\.' : parsed.source;
|
|
258
|
+
index = parsed.end - 1;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
source += escapeRegExp(char);
|
|
263
|
+
}
|
|
264
|
+
return source;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// A leading dot is visible to a wildcard only when the segment's first token
|
|
268
|
+
// names it: a literal `.`, a class that folds to exactly `.`, or an extglob
|
|
269
|
+
// alternative that allows it (minimatch's `dot: false`).
|
|
270
|
+
function segmentAllowsDot(segment: string): boolean {
|
|
271
|
+
if (segment === '' || segment[0] === '.') return true;
|
|
272
|
+
if (segment[0] === '[') return parseCharClass(segment, 0)?.dotOnly ?? false;
|
|
273
|
+
const operator = segment[0]!;
|
|
274
|
+
if ('@+*?!'.includes(operator) && segment[1] === '(') {
|
|
275
|
+
if (operator === '!') return false;
|
|
276
|
+
const close = findCloseParen(segment, 1);
|
|
277
|
+
if (close < 0) return false;
|
|
278
|
+
return splitExtglobAlternatives(segment.slice(2, close)).some((alt) => segmentAllowsDot(alt));
|
|
279
|
+
}
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function matchSegment(part: string, segment: string): boolean {
|
|
284
|
+
if (segment === '') return part === '';
|
|
285
|
+
if (part === '') return false;
|
|
286
|
+
if (part.startsWith('.') && !segmentAllowsDot(segment)) return false;
|
|
287
|
+
try {
|
|
288
|
+
return new RegExp(`^${segmentSource(segment)}$`).test(part);
|
|
289
|
+
} catch {
|
|
290
|
+
// npm/minimatch silently match nothing for an invalid class (a reversed
|
|
291
|
+
// range); a hostile declaration is input, never a crash source.
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function matchSegments(path: readonly string[], pattern: readonly string[]): boolean {
|
|
297
|
+
// Memoize (pattern index, path index): stacked `**` patterns otherwise
|
|
298
|
+
// backtrack exponentially, a stall npm never exhibits.
|
|
299
|
+
const memo = new Map<string, boolean>();
|
|
300
|
+
const walk = (patternIndex: number, pathIndex: number): boolean => {
|
|
301
|
+
const key = `${patternIndex}:${pathIndex}`;
|
|
302
|
+
const cached = memo.get(key);
|
|
303
|
+
if (cached !== undefined) return cached;
|
|
304
|
+
let result: boolean;
|
|
305
|
+
if (patternIndex === pattern.length) {
|
|
306
|
+
result = pathIndex === path.length;
|
|
307
|
+
} else {
|
|
308
|
+
const segment = pattern[patternIndex]!;
|
|
309
|
+
if (segment === GLOBSTAR) {
|
|
310
|
+
result = walk(patternIndex + 1, pathIndex);
|
|
311
|
+
if (!result && pathIndex < path.length) {
|
|
312
|
+
const part = path[pathIndex]!;
|
|
313
|
+
if (part !== '.' && part !== '..' && !part.startsWith('.')) result = walk(patternIndex, pathIndex + 1);
|
|
314
|
+
}
|
|
315
|
+
} else if (pathIndex >= path.length) {
|
|
316
|
+
result = false;
|
|
317
|
+
} else {
|
|
318
|
+
result = matchSegment(path[pathIndex]!, segment) && walk(patternIndex + 1, pathIndex + 1);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
memo.set(key, result);
|
|
322
|
+
return result;
|
|
323
|
+
};
|
|
324
|
+
return walk(0, 0);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function splitPath(value: string): string[] {
|
|
328
|
+
// minimatch coalesces repeated slashes unless `preserveMultipleSlashes`.
|
|
329
|
+
const trimmed = value.replace(/\/+$/, '');
|
|
330
|
+
return trimmed ? trimmed.split(/\/+/) : [];
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function patternSegments(pattern: string): string[] {
|
|
334
|
+
const normalized: string[] = [];
|
|
335
|
+
for (const segment of splitPath(pattern)) {
|
|
336
|
+
if (segment === '..') {
|
|
337
|
+
const previous = normalized.at(-1);
|
|
338
|
+
if (previous !== undefined && previous !== '..' && previous !== GLOBSTAR) normalized.pop();
|
|
339
|
+
else normalized.push(segment);
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
normalized.push(segment === '**' ? GLOBSTAR : segment);
|
|
343
|
+
}
|
|
344
|
+
// glob drops a `.` only when it is the trailing segment; an interior `.` is
|
|
345
|
+
// a literal directory name npm never matches.
|
|
346
|
+
if (normalized.at(-1) === '.') normalized.pop();
|
|
347
|
+
return normalized;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// A directory's membership: the path is matched as a directory (map-workspaces
|
|
351
|
+
// appends `/` to each positive glob), so a trailing `**` covers the glob's own
|
|
352
|
+
// parent (`packages/**` matches `packages`).
|
|
353
|
+
function matchDirectory(relativePath: string, pattern: string): boolean {
|
|
354
|
+
return expandBraces(pattern).some((expanded) => matchSegments(splitPath(relativePath), patternSegments(expanded)));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// Pattern-vs-pattern comparisons inside the negation cancellation treat the
|
|
358
|
+
// first argument as a literal path string, as minimatch does.
|
|
359
|
+
function matchesPatternString(pathString: string, pattern: string): boolean {
|
|
360
|
+
return expandBraces(pattern).some((expanded) => matchSegments(splitPath(pathString), patternSegments(expanded)));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function orderPatterns(globs: readonly string[]): { patterns: string[]; negated: string[] } {
|
|
364
|
+
const patterns: string[] = [];
|
|
365
|
+
const negated: string[] = [];
|
|
366
|
+
for (const raw of globs) {
|
|
367
|
+
const excl = /^!+/.exec(raw);
|
|
368
|
+
let pattern = excl ? raw.slice(excl[0].length) : raw;
|
|
369
|
+
pattern = pattern.replace(/^\.?\/+/, '');
|
|
370
|
+
const negate = Boolean(excl && excl[0].length % 2 === 1);
|
|
371
|
+
// npm's getGlobPattern normalizes backslashes for positive globs only.
|
|
372
|
+
if (!negate) pattern = pattern.replace(/\\/g, '/');
|
|
373
|
+
if (negate) {
|
|
374
|
+
negated.push(pattern);
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
// A later positive pattern overrides the earlier negation it covers.
|
|
378
|
+
for (let index = 0; index < negated.length; index += 1) {
|
|
379
|
+
if (matchesPatternString(pattern, negated[index]!)) negated.splice(index, 1);
|
|
380
|
+
}
|
|
381
|
+
patterns.push(pattern);
|
|
382
|
+
}
|
|
383
|
+
// An un-cancelled negation removes the positive patterns it covers.
|
|
384
|
+
for (const blocked of negated) {
|
|
385
|
+
for (const pattern of [...patterns]) {
|
|
386
|
+
if (matchesPatternString(pattern, blocked)) patterns.splice(patterns.indexOf(pattern), 1);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return { patterns, negated };
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Whether `memberPath` (relative, POSIX separators) is a workspace member of
|
|
394
|
+
* the given declaration, matching `@npmcli/map-workspaces` semantics.
|
|
395
|
+
*/
|
|
396
|
+
export function workspaceMemberMatch(memberPath: string, globs: readonly string[]): boolean {
|
|
397
|
+
try {
|
|
398
|
+
if (!memberPath || memberPath === '..' || memberPath.startsWith('../')) return false;
|
|
399
|
+
const segments = memberPath.split('/');
|
|
400
|
+
// map-workspaces ignores `**/node_modules/**` before the pattern list
|
|
401
|
+
// applies; glob's directory candidates end in `/`, so the node_modules
|
|
402
|
+
// directory itself is covered too.
|
|
403
|
+
if (segments.includes('node_modules')) return false;
|
|
404
|
+
const { patterns, negated } = orderPatterns(globs);
|
|
405
|
+
if (negated.some((blocked) => matchDirectory(memberPath, blocked))) return false;
|
|
406
|
+
return patterns.some((pattern) => matchDirectory(memberPath, pattern));
|
|
407
|
+
} catch {
|
|
408
|
+
// Load-bearing: a pathological declaration can overflow the brace
|
|
409
|
+
// recursion (RangeError) or hit another unexpected syntax error; the
|
|
410
|
+
// per-segment regex compile is caught earlier. Degrading here keeps any
|
|
411
|
+
// such declaration a non-member instead of aborting the pre-flight.
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
@@ -20,6 +20,7 @@ import { applyUserDelta, extractUserDelta, mergeArgsStyle } from './mcp-config-m
|
|
|
20
20
|
import { saveAgentDelta, takeAgentDelta } from './mcp-config-backup.ts';
|
|
21
21
|
import { applyPacksToEntry } from './packs-policy.ts';
|
|
22
22
|
import { copyDir, deployWord, PLUGIN_ROOT, type DeployMode } from './install-payload.ts';
|
|
23
|
+
import { codexApprovalEnv, codexApprovalToolsBlock, CODEX_APPROVAL_MODE_ENV } from './agents/codex-config.ts';
|
|
23
24
|
|
|
24
25
|
// openclaw and codex-desktop both ship a .mcp.json plus the .codex-plugin
|
|
25
26
|
// manifest into their plugin dir — the codex-discoverable plugin-dir shape;
|
|
@@ -164,7 +165,32 @@ export function writeMcpServersFile(pluginDest: string, mcpPath: string, agentKe
|
|
|
164
165
|
if (delta) finalEntry = asRecord(applyUserDelta(entry, delta, 'args'));
|
|
165
166
|
}
|
|
166
167
|
const packsChanged = applyPacksToEntry(finalEntry, 'env', agentKey === 'openclaw' ? 'OpenClaw' : 'Codex Desktop');
|
|
167
|
-
|
|
168
|
+
// The codex client yield (PR-5): the per-tool approve blocks inside the
|
|
169
|
+
// devkit-owned server entry — codex reads them from the plugin-provided
|
|
170
|
+
// server definition (the config.toml route is refused by codex's own
|
|
171
|
+
// bootstrap validation when the implied server has no transport; see
|
|
172
|
+
// agents/codex-config.ts). OpenClaw shares this writer but is not codex,
|
|
173
|
+
// so its .mcp.json stays block-free. The block is ours wholesale — the
|
|
174
|
+
// file is devkit-owned and regenerated — and a drift (an older deploy's
|
|
175
|
+
// missing or hand-stripped tools map) counts as a change so the next
|
|
176
|
+
// update heals it, same as the packs write above.
|
|
177
|
+
let toolsChanged = false;
|
|
178
|
+
let envChanged = false;
|
|
179
|
+
if (agentKey !== 'openclaw') {
|
|
180
|
+
const wanted = codexApprovalToolsBlock();
|
|
181
|
+
toolsChanged = JSON.stringify(finalEntry.tools) !== JSON.stringify(wanted);
|
|
182
|
+
if (toolsChanged) finalEntry.tools = wanted;
|
|
183
|
+
// The ask-mode env half rides the same codex-only condition as the tools
|
|
184
|
+
// block (openclaw is not codex and stays both block- and env-free). The
|
|
185
|
+
// env is ours wholesale too — same doctrine, same drift healing: a stale
|
|
186
|
+
// or hand-edited copy is a change, so the next update restores it.
|
|
187
|
+
const entryEnv = asRecord(finalEntry.env);
|
|
188
|
+
if (entryEnv.DEVKIT_APPROVAL_MODE !== CODEX_APPROVAL_MODE_ENV) {
|
|
189
|
+
finalEntry.env = { ...entryEnv, ...codexApprovalEnv() };
|
|
190
|
+
envChanged = true;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (existing && !changed && !packsChanged && !toolsChanged && !envChanged) {
|
|
168
194
|
console.log(` MCP Config unchanged: ${configPath}`);
|
|
169
195
|
return;
|
|
170
196
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { McpServer, type RegisteredTool } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
3
|
-
import
|
|
3
|
+
import {
|
|
4
|
+
ErrorCode,
|
|
5
|
+
McpError,
|
|
6
|
+
type CallToolResult,
|
|
7
|
+
type ElicitRequestFormParams,
|
|
8
|
+
type JSONRPCMessage,
|
|
9
|
+
} from '@modelcontextprotocol/sdk/types.js';
|
|
4
10
|
|
|
5
11
|
import {
|
|
6
12
|
TOOL_DEFINITIONS,
|
|
@@ -18,6 +24,8 @@ import { peekCachedUpdateInfo, applyUpdateHint, readInstalledVersion } from './u
|
|
|
18
24
|
import { initTelemetry } from './telemetry/telemetry.ts';
|
|
19
25
|
import { detectAgent } from './telemetry/agent-detect.ts';
|
|
20
26
|
import { asRecord } from './lib/as-record.ts';
|
|
27
|
+
import { approvalModeFromEnv } from './lib/approval-mode.ts';
|
|
28
|
+
import type { ElicitationSeam } from './approval-types.ts';
|
|
21
29
|
|
|
22
30
|
const pkgVersion = readInstalledVersion() || '0.0.0';
|
|
23
31
|
|
|
@@ -113,6 +121,23 @@ const VENDOR_BOUNDARY_RULE =
|
|
|
113
121
|
"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. " +
|
|
114
122
|
"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. ";
|
|
115
123
|
|
|
124
|
+
// Harness tool-routing failure, shared by the stdio instruction forms (the
|
|
125
|
+
// remote face rides no harness model wire — see the remote return).
|
|
126
|
+
// Measured failure (2026-11-13, live codex 0.167.2 session + reproduced
|
|
127
|
+
// against the same provider): codex presents MCP tools as namespace-type
|
|
128
|
+
// tools and dispatches ONLY through the `namespace` field on function_call
|
|
129
|
+
// items, with no flat-name fallback; a custom OpenAI-compatible model
|
|
130
|
+
// gateway that drops that field (request history and/or generated calls)
|
|
131
|
+
// turns every regenerated call namespace-less, codex's registry
|
|
132
|
+
// (namespace, name) exact-match misses, and the harness answers
|
|
133
|
+
// `unsupported call: <tool>` — 690 of 692 huaweicloud calls in the dump,
|
|
134
|
+
// none ever reaching the devkit server, while the model retried the
|
|
135
|
+
// identical call in a spin. The devkit cannot observe or fix these
|
|
136
|
+
// calls; the only devkit-side lever is teaching the agent what the
|
|
137
|
+
// signature means so the spin stops after one reply.
|
|
138
|
+
const UNSUPPORTED_CALL_RULE =
|
|
139
|
+
'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. ';
|
|
140
|
+
|
|
116
141
|
export function instructionsFor(remote: boolean, runtimePacks = false): string {
|
|
117
142
|
if (remote) {
|
|
118
143
|
return (
|
|
@@ -154,6 +179,7 @@ export function instructionsFor(remote: boolean, runtimePacks = false): string {
|
|
|
154
179
|
// directory, and the stdio instructions render on both.
|
|
155
180
|
"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. " +
|
|
156
181
|
VENDOR_BOUNDARY_RULE +
|
|
182
|
+
UNSUPPORTED_CALL_RULE +
|
|
157
183
|
'Route Huawei Cloud tasks through the huaweicloud-core skill; browse packs with huaweicloud_list_packs.'
|
|
158
184
|
);
|
|
159
185
|
}
|
|
@@ -256,12 +282,53 @@ export function normalizeToolCallParams(message: JSONRPCMessage): JSONRPCMessage
|
|
|
256
282
|
return message;
|
|
257
283
|
}
|
|
258
284
|
|
|
285
|
+
// The server-run confirmation seam (PR-1.5). The SDK captures the client's
|
|
286
|
+
// initialize params on the per-session Server instance (that IS the session
|
|
287
|
+
// record), so `capable` reads the declared `elicitation.form` capability and
|
|
288
|
+
// never re-probes. The prompt raises a form-mode elicitation with an
|
|
289
|
+
// explicit timeout and resolves every failure as a decision: the gate
|
|
290
|
+
// refuses fail-closed instead of surfacing a transport error as the tool
|
|
291
|
+
// result. Never wired on the remote face (it forces token mode and must not
|
|
292
|
+
// elicit).
|
|
293
|
+
// The SDK's request-timeout code (-32001) as a plain number: the enum type
|
|
294
|
+
// has no shared member with the wire error's numeric code, so compare numbers.
|
|
295
|
+
const REQUEST_TIMEOUT_CODE: number = ErrorCode.RequestTimeout;
|
|
296
|
+
|
|
297
|
+
function createElicitationSeam(server: McpServer): ElicitationSeam {
|
|
298
|
+
return {
|
|
299
|
+
get capable(): boolean {
|
|
300
|
+
return server.server.getClientCapabilities()?.elicitation?.form !== undefined;
|
|
301
|
+
},
|
|
302
|
+
async prompt({ message, schema, timeoutMs }) {
|
|
303
|
+
try {
|
|
304
|
+
const result = await server.server.elicitInput(
|
|
305
|
+
{ mode: 'form', message, requestedSchema: schema as ElicitRequestFormParams['requestedSchema'] },
|
|
306
|
+
{ timeout: timeoutMs },
|
|
307
|
+
);
|
|
308
|
+
return { decision: result.action, content: result.content };
|
|
309
|
+
} catch (error) {
|
|
310
|
+
if (error instanceof McpError && error.code === REQUEST_TIMEOUT_CODE) {
|
|
311
|
+
return { decision: 'timeout', detail: error.message };
|
|
312
|
+
}
|
|
313
|
+
return { decision: 'error', detail: error instanceof Error ? error.message : String(error) };
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
259
319
|
export function createDevkitMcpServer({
|
|
260
320
|
sessionId,
|
|
261
321
|
runtimePacks = false,
|
|
262
322
|
remoteSurface = false,
|
|
263
323
|
}: DevkitServerOptions = {}): McpServer {
|
|
264
324
|
assertConstructedSchemas();
|
|
325
|
+
// The approval posture resolves once at construction: a bogus
|
|
326
|
+
// DEVKIT_APPROVAL_MODE throws here (boot fail-fast, the same doctrine
|
|
327
|
+
// DEVKIT_PACKS applies through syncDisclosure). The value itself is read
|
|
328
|
+
// per call by the gate, and it no longer changes the wire surface: the
|
|
329
|
+
// PR-1.5 flip removed the client interaction flag, because the server
|
|
330
|
+
// raises the confirmation now.
|
|
331
|
+
approvalModeFromEnv(process.env);
|
|
265
332
|
// The contradictory construction is refused, not cautioned: a remote that
|
|
266
333
|
// also carried runtime pack toggling would attach the onPacksChanged seam
|
|
267
334
|
// to every callOpts, publishing the server host's absolute install path
|
|
@@ -327,11 +394,27 @@ export function createDevkitMcpServer({
|
|
|
327
394
|
tool.name,
|
|
328
395
|
server.registerTool(
|
|
329
396
|
tool.name,
|
|
330
|
-
{
|
|
397
|
+
{
|
|
398
|
+
description: tool.description,
|
|
399
|
+
inputSchema: getToolSchema(tool.name),
|
|
400
|
+
// No client interaction flag (PR-1.5 flip). The confirmation runs
|
|
401
|
+
// on the server now: on an elicitation-capable client the gate
|
|
402
|
+
// raises its own form, and on the rest the T3 chat round-trip is
|
|
403
|
+
// the confirmation. A client dialog ahead of either would
|
|
404
|
+
// double-confirm (codex measured the two-interaction sequence:
|
|
405
|
+
// its own approval prompt, then the server form), so roster tools
|
|
406
|
+
// carry no `anthropic/requiresUserInteraction`. The machinery
|
|
407
|
+
// stays roster-driven where it lives: nothing here keys on the
|
|
408
|
+
// roster because the policy emits nothing for any tool.
|
|
409
|
+
},
|
|
331
410
|
async (args): Promise<CallToolResult> => {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
411
|
+
// The server-run confirmation seam rides every stdio call; the
|
|
412
|
+
// remote face never wires it (ask mode is force-downgraded there).
|
|
413
|
+
const elicitation = remoteSurface ? undefined : createElicitationSeam(server);
|
|
414
|
+
const callOpts: CallToolOptions = {
|
|
415
|
+
...(runtimePacks ? { sessionId, onPacksChanged: () => syncDisclosure() } : { sessionId }),
|
|
416
|
+
...(elicitation ? { elicitation } : {}),
|
|
417
|
+
};
|
|
335
418
|
const result = await callTool(tool.name, args, callOpts);
|
|
336
419
|
const decorated = _decorateResult(sessionId, tool.name, result);
|
|
337
420
|
return {
|
|
@@ -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-session posture: its confirmation is the server-run
|
|
62
|
+
// gate's elicitation form (or the T3 chat round-trip), and this stateless
|
|
63
|
+
// remote face carries no session to ask in — no client capability record
|
|
64
|
+
// and no in-band round-trip — so the env is forced back to the token gate,
|
|
65
|
+
// loudly, before any request handler resolves it. This is the only
|
|
66
|
+
// production entry to the 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 session to run the confirmation in); 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(
|
|
@@ -215,11 +215,21 @@ export class DevkitStdioTransport implements Transport {
|
|
|
215
215
|
return;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
// An id-bearing message without a method is
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
// the
|
|
218
|
+
// An id-bearing message without a method is either a RESPONSE to a
|
|
219
|
+
// server-initiated request (the elicitation form we raise during a tool
|
|
220
|
+
// call) or a malformed request. A response carries result or error and
|
|
221
|
+
// must reach the SDK, which correlates it by id; without this branch the
|
|
222
|
+
// form answer was answered with -32601 and the server waited out its
|
|
223
|
+
// request timeout (measured: every elicitation round-trip hung on the
|
|
224
|
+
// real stdio face while the in-memory transport worked). A message with
|
|
225
|
+
// neither result nor error is still the malformed shape: reply -32601
|
|
226
|
+
// echoing the id so the failure is correlatable, matching the legacy
|
|
227
|
+
// behavior.
|
|
222
228
|
if (typeof message.method !== 'string' || !message.method) {
|
|
229
|
+
if (Object.hasOwn(message, 'result') || Object.hasOwn(message, 'error')) {
|
|
230
|
+
this.onmessage?.(raw as JSONRPCMessage);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
223
233
|
this.writeJsonRpcError(-32601, 'Method not found: undefined', message.id);
|
|
224
234
|
return;
|
|
225
235
|
}
|