huaweicloud-devkit 2.0.0-next.3 → 2.0.0-next.5
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 +1 -1
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.mcp.json +55 -1
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
- 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 +141 -86
- package/plugins/huaweicloud-core/dist/agents/opencode.js +106 -39
- 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/explain-error.js +9 -1
- package/plugins/huaweicloud-core/dist/hcloud-cli.js +1 -1
- package/plugins/huaweicloud-core/dist/hcloud-plan.js +68 -62
- package/plugins/huaweicloud-core/dist/lib/approval-mode.js +7 -5
- 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 +371 -32
- package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +6 -16
- package/plugins/huaweicloud-core/dist/lib/opencode-ask-rule.js +224 -78
- 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 +68 -16
- package/plugins/huaweicloud-core/dist/mcp-server.js +6933 -1186
- 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 +85 -130
- 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 +20 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +245 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/expose-task.js +71 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +180 -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 +29 -3
- package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +93 -9
- package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +37 -10
- 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/risk-rule-engine.js +20 -4
- package/plugins/huaweicloud-core/dist/safety/classify-hcloud.js +6 -6
- 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/safety/redact.js +21 -3
- package/plugins/huaweicloud-core/dist/safety/risk-merge.js +24 -4
- 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 +36 -1
- package/plugins/huaweicloud-core/dist/tool-definitions.js +13 -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 +67 -4
- package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
- package/plugins/huaweicloud-core/safety/policy.json +18 -11
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +115 -11
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +198 -143
- 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 +2 -2
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +11 -7
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +74 -29
- 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 +176 -88
- package/plugins/huaweicloud-core/src/agents/opencode.ts +125 -54
- 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/explain-error.ts +9 -1
- package/plugins/huaweicloud-core/src/hcloud-cli.ts +3 -0
- package/plugins/huaweicloud-core/src/hcloud-plan.ts +74 -71
- package/plugins/huaweicloud-core/src/lib/approval-mode.ts +7 -5
- 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 +408 -30
- package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +8 -15
- package/plugins/huaweicloud-core/src/lib/opencode-ask-rule.ts +302 -83
- 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 +81 -17
- package/plugins/huaweicloud-core/src/mcp-server.ts +7 -7
- 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 +99 -137
- 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 +43 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +296 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/expose-task.ts +105 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +195 -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 +41 -14
- package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +120 -8
- package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +42 -9
- 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/risk-rule-engine.ts +20 -7
- package/plugins/huaweicloud-core/src/safety/classify-hcloud.ts +28 -16
- 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/safety/redact.ts +24 -6
- package/plugins/huaweicloud-core/src/safety/risk-merge.ts +26 -5
- 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 +511 -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 +39 -1
- package/plugins/huaweicloud-core/src/tool-definitions.ts +13 -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,116 @@
|
|
|
1
|
+
// The shared display-redaction leaf. Two passes live here, one canonical home
|
|
2
|
+
// each:
|
|
3
|
+
// 1. the secret-TOKEN FOLD — the argv/string fold that hides secret VALUES
|
|
4
|
+
// from every display and store surface (the run face's pin view, the
|
|
5
|
+
// sandbox exec views, the approval token store's argsRedacted, the
|
|
6
|
+
// trace). The fold's primitives were born in hcloud-plan.ts for the
|
|
7
|
+
// run face's pin view; PR-3a round 3 moved them HERE because the exec
|
|
8
|
+
// face and the token store need the same fold and cannot import the
|
|
9
|
+
// face (approval-tokens ← hcloud-cli would be a value cycle). One
|
|
10
|
+
// fold, every consumer; the classification engines see the RAW
|
|
11
|
+
// command always — this leaf is for display and persistence only.
|
|
12
|
+
// 2. the supplemental-key denylist (api_key/apiKey/value) — object-shaped
|
|
13
|
+
// secrets redactSecrets alone never covered.
|
|
14
|
+
const SUPPLEMENTAL_SECRET_KEYS = new Set(['api_key', 'apikey', 'value']);
|
|
15
|
+
// The secret key families (the run face's exact vocabulary, kept verbatim):
|
|
16
|
+
// unanchored inside a token (redactSecrets folds `password=` inside
|
|
17
|
+
// `--dbpassword=` the same way), with AK/SK boundary-anchored.
|
|
18
|
+
const SECRET_KEY_ALT = 'access[_-]?key(?:[_-]?(?:id|secret))?|secret[_-]?key|secret[_-]?string|secret[_-]?binary|security[_-]?token|x[_-]?auth[_-]?token|token|password|passwd|admin[_-]?pass|credential|input[_-]?value|user[_-]?data|metadata|private[_-]?key|authorization';
|
|
19
|
+
// A bare key token (`--password`, `--server.adminPass`, `--dbpassword`): the
|
|
20
|
+
// value rides the NEXT argv element. The optional prefix must end on a
|
|
21
|
+
// separator char, or `--task` would parse as the SK key token.
|
|
22
|
+
export const SECRET_KEY_TOKEN_RE = new RegExp('^(?:--?[A-Za-z0-9_.-]*[._-])?(?:' + SECRET_KEY_ALT + '|AK|SK)$', 'i');
|
|
23
|
+
// Shared key+separator scanner: ONE global split drives every consumer. The
|
|
24
|
+
// value segment of a key runs to the NEXT key occurrence — a multi-key body
|
|
25
|
+
// yields one segment per key.
|
|
26
|
+
const SECRET_KEY_SEP_RE = new RegExp('((?:(?:' + SECRET_KEY_ALT + ')|\\b(?:AK|SK))["\'\\\\]*\\s*(?:[=:]|\\s|(?=["\']))\\s*)', 'gi');
|
|
27
|
+
export function secretSegments(arg) {
|
|
28
|
+
const parts = String(arg).split(SECRET_KEY_SEP_RE);
|
|
29
|
+
const segments = [];
|
|
30
|
+
for (let i = 1; i < parts.length; i += 2) {
|
|
31
|
+
segments.push({ sep: parts[i] ?? '', value: parts[i + 1] ?? '' });
|
|
32
|
+
}
|
|
33
|
+
return segments;
|
|
34
|
+
}
|
|
35
|
+
// The canonical argv fold (the run face's pin view, verbatim): a string
|
|
36
|
+
// token the scanner sees a secret key in has every value segment folded to
|
|
37
|
+
// `<redacted>` while the STRUCTURE (flag names, key names, non-secret
|
|
38
|
+
// prefix) survives, and a bare key token folds the value riding the next
|
|
39
|
+
// element. A chained bare key (`--password --token x`) is left for its own
|
|
40
|
+
// iteration so no real value hides behind the skip. Mixed arrays are safe:
|
|
41
|
+
// non-string elements pass through untouched at their position, so object
|
|
42
|
+
// payloads (the tunnel faces' arrays) never coerce.
|
|
43
|
+
export function foldSecretTokens(args) {
|
|
44
|
+
const out = [];
|
|
45
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
46
|
+
const raw = args[i];
|
|
47
|
+
if (typeof raw !== 'string' && typeof raw !== 'number') {
|
|
48
|
+
out.push(raw);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const arg = String(raw);
|
|
52
|
+
const segments = secretSegments(arg);
|
|
53
|
+
if (segments.length > 0) {
|
|
54
|
+
const parts = String(arg).split(SECRET_KEY_SEP_RE);
|
|
55
|
+
let folded = parts[0] ?? '';
|
|
56
|
+
for (let j = 1; j < parts.length; j += 2) {
|
|
57
|
+
folded += parts[j] + '<redacted>';
|
|
58
|
+
}
|
|
59
|
+
out.push(folded);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const nextRaw = i + 1 < args.length ? args[i + 1] : undefined;
|
|
63
|
+
// Narrow before String(): only string- and number-shaped elements can
|
|
64
|
+
// be a bare key's value token — anything else (objects, arrays) is not
|
|
65
|
+
// a shell word and passes through untouched, and Object's default
|
|
66
|
+
// stringification never enters the fold.
|
|
67
|
+
const next = typeof nextRaw === 'string' || typeof nextRaw === 'number' ? String(nextRaw) : undefined;
|
|
68
|
+
if (SECRET_KEY_TOKEN_RE.test(arg) && next !== undefined && !SECRET_KEY_TOKEN_RE.test(next)) {
|
|
69
|
+
out.push(arg, '<redacted>');
|
|
70
|
+
i += 1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
out.push(raw);
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
// The string twin of the argv fold: whitespace-split a command string into
|
|
78
|
+
// its words, fold the same way, rejoin. The word approximation is the
|
|
79
|
+
// documented residual: a quoted value containing spaces folds only its
|
|
80
|
+
// first word (the same space-bearing-value partial-redaction class the
|
|
81
|
+
// run face records).
|
|
82
|
+
export function foldSecretTokensInString(text) {
|
|
83
|
+
return foldSecretTokens(text.split(/\s+/)).join(' ');
|
|
84
|
+
}
|
|
85
|
+
// THE COMPOSITION RULE (one statement, every consumer): a display or store
|
|
86
|
+
// surface redacts by composing `redactSecrets(value)` FIRST (the engine's
|
|
87
|
+
// glued key=value/key:value folds) and `redactWithSupplementalKeys(...)`
|
|
88
|
+
// SECOND (the supplemental key denylist plus the two-token fold). There is
|
|
89
|
+
// deliberately no helper wrapping the pair: the consumers run it on whole
|
|
90
|
+
// argv arrays and object bindings (values redactSecrets alone mishandles),
|
|
91
|
+
// so a string-only helper was a zero-call-site lie the round-4 seat caught.
|
|
92
|
+
// redactSecrets's import stays — it is the first half of the composition
|
|
93
|
+
// the callers name at their sites.
|
|
94
|
+
export function redactWithSupplementalKeys(value) {
|
|
95
|
+
if (typeof value === 'string') {
|
|
96
|
+
// The two-token secret form (`--password hunter2`) folds on the string
|
|
97
|
+
// leaf every display/store consumer routes through: the glued forms
|
|
98
|
+
// fold earlier via redactSecrets (the callers compose this leaf after
|
|
99
|
+
// it), the cross-word forms here (interrogate round 3, F1 — reproduced
|
|
100
|
+
// on every surface by both seats and the root).
|
|
101
|
+
return foldSecretTokensInString(value);
|
|
102
|
+
}
|
|
103
|
+
if (Array.isArray(value)) {
|
|
104
|
+
// The array fold is pairwise: adjacent elements carry the bare key
|
|
105
|
+
// token and its value (the run face's argv shape), so recursion alone
|
|
106
|
+
// could never catch the pair.
|
|
107
|
+
return foldSecretTokens(value.map((item) => redactWithSupplementalKeys(item)));
|
|
108
|
+
}
|
|
109
|
+
if (value && typeof value === 'object') {
|
|
110
|
+
return Object.fromEntries(Object.entries(value).map(([key, val]) => [
|
|
111
|
+
key,
|
|
112
|
+
SUPPLEMENTAL_SECRET_KEYS.has(key.toLowerCase()) ? '<redacted>' : redactWithSupplementalKeys(val),
|
|
113
|
+
]));
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
@@ -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
|
}
|