rulesync 43.8.0 → 43.8.1
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/dist/cli/index.cjs +3 -3
- package/dist/cli/index.js +3 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/{import-C5ETusOs.cjs → import-B111LEQv.cjs} +883 -63
- package/dist/{import-Cu5o6uKO.js → import-UXidZnLu.js} +884 -64
- package/dist/{import-Cu5o6uKO.js.map → import-UXidZnLu.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -79480,6 +79480,30 @@ function maxRangeCount(steps) {
|
|
|
79480
79480
|
return most;
|
|
79481
79481
|
}
|
|
79482
79482
|
/**
|
|
79483
|
+
* Whether any one value matches both globs — that is, whether the two patterns
|
|
79484
|
+
* overlap at all. The answer is exact up to `MAX_INTERSECTION_CELLS`; a pair
|
|
79485
|
+
* longer than that is reported as overlapping without being compared, so a
|
|
79486
|
+
* caller that reads a `true` as a reason to restrict stays on the safe side and
|
|
79487
|
+
* one that would read it as a reason to permit must not use this. What a pair
|
|
79488
|
+
* costs counts the ranges a `[a-z]` class carries, not only the two lengths.
|
|
79489
|
+
*
|
|
79490
|
+
* This answers the question an adapter really has when it holds a restriction
|
|
79491
|
+
* and an `allow`: is there a command both of them name? Asking instead whether
|
|
79492
|
+
* either pattern covers the other's *text* misses the ordinary crossing pair —
|
|
79493
|
+
* `* --force` and `git *` cover none of each other's spellings, yet they share
|
|
79494
|
+
* every `git … --force` command.
|
|
79495
|
+
*
|
|
79496
|
+
* The two step lists are walked as a table rather than by backtracking, so no
|
|
79497
|
+
* input makes the time blow up the way a translated regex would. Only two rows
|
|
79498
|
+
* of that table are ever held, and the shorter pattern is the one that sizes
|
|
79499
|
+
* them, so the memory is linear in the shorter pattern however long the other
|
|
79500
|
+
* one is. Where a `[...]` class meets another `[...]` class the answer is
|
|
79501
|
+
* assumed to be yes, which over-reports rather than misses.
|
|
79502
|
+
*/
|
|
79503
|
+
function globsIntersect(left, right) {
|
|
79504
|
+
return parsedGlobsIntersect(parseGlobPattern(left), parseGlobPattern(right));
|
|
79505
|
+
}
|
|
79506
|
+
/**
|
|
79483
79507
|
* `globsIntersect` for two globs already parsed, optionally spending a budget
|
|
79484
79508
|
* shared with the rest of the caller's run — see `createIntersectionBudget`.
|
|
79485
79509
|
* Once that budget is exhausted every further pair answers `true` without being
|
|
@@ -80107,6 +80131,11 @@ function collectShellCommandRules(permission) {
|
|
|
80107
80131
|
function widenToPrefixGlob$1(pattern) {
|
|
80108
80132
|
return pattern.endsWith("*") ? pattern : `${pattern}*`;
|
|
80109
80133
|
}
|
|
80134
|
+
function widenForOverlap(pattern) {
|
|
80135
|
+
if (/\{[^}]*,[^}]*\}/.test(pattern)) return "*";
|
|
80136
|
+
const widened = pattern.replaceAll("**/", "*").replaceAll("/**", "*");
|
|
80137
|
+
return widened.endsWith(" *") ? `${widened.slice(0, -2)}*` : widened;
|
|
80138
|
+
}
|
|
80110
80139
|
/**
|
|
80111
80140
|
* Build the test an adapter applies to an `allow` pattern before writing it:
|
|
80112
80141
|
* which restrictions it cannot write name some of the same commands? The
|
|
@@ -80138,11 +80167,11 @@ function widenToPrefixGlob$1(pattern) {
|
|
|
80138
80167
|
function createShadowingRestrictionsTest(restrictions, { normalizePattern = (pattern) => pattern, budget = createIntersectionBudget() } = {}) {
|
|
80139
80168
|
const normalized = restrictions.map(({ pattern, fromAllToolsCategory }) => ({
|
|
80140
80169
|
pattern,
|
|
80141
|
-
glob: parseGlobPattern(fromAllToolsCategory ? pattern : normalizePattern(pattern))
|
|
80170
|
+
glob: parseGlobPattern(widenForOverlap(fromAllToolsCategory ? pattern : normalizePattern(pattern)))
|
|
80142
80171
|
}));
|
|
80143
80172
|
return (allowPattern) => {
|
|
80144
80173
|
if (budget.remaining === 0) return normalized.map(({ pattern }) => pattern);
|
|
80145
|
-
const allowGlob = parseGlobPattern(normalizePattern(allowPattern));
|
|
80174
|
+
const allowGlob = parseGlobPattern(widenForOverlap(normalizePattern(allowPattern)));
|
|
80146
80175
|
return normalized.filter(({ pattern, glob }) => pattern === allowPattern || parsedGlobsIntersect(glob, allowGlob, budget)).map(({ pattern }) => pattern);
|
|
80147
80176
|
};
|
|
80148
80177
|
}
|
|
@@ -80305,6 +80334,336 @@ function honorAllToolsOnBash(permission) {
|
|
|
80305
80334
|
bash: bashRulesHonoringAllTools(permission)
|
|
80306
80335
|
};
|
|
80307
80336
|
}
|
|
80337
|
+
// src/features/permissions/shadowed-allows.ts
|
|
80338
|
+
/** The canonical category whose patterns are URLs or domains. */
|
|
80339
|
+
const WEBFETCH_CATEGORY$2 = "webfetch";
|
|
80340
|
+
/**
|
|
80341
|
+
* A URL or domain pattern lowercased and without its scheme, so `HTTPS://Evil.example/*`
|
|
80342
|
+
* and `evil.example/*` are compared as the same host. Hosts are case-insensitive
|
|
80343
|
+
* and a scheme-less allow covers every scheme.
|
|
80344
|
+
*/
|
|
80345
|
+
function normalizeUrlPattern(pattern) {
|
|
80346
|
+
return pattern.toLowerCase().replace(/^[a-z][a-z0-9+.-]*:\/\//, "");
|
|
80347
|
+
}
|
|
80348
|
+
/**
|
|
80349
|
+
* A URL pattern with its scheme stripped and only its host lowercased, for
|
|
80350
|
+
* writing it into a tool that matches paths case-sensitively (Copilot in VS
|
|
80351
|
+
* Code). A scheme spelled as a glob (a `*` scheme, `http*`, or a bare double
|
|
80352
|
+
* slash after a `*`) is stripped too.
|
|
80353
|
+
*/
|
|
80354
|
+
function stripUrlSchemeKeepingPathCase(pattern) {
|
|
80355
|
+
const withoutScheme = pattern.replace(/^[a-z0-9+.*-]*:?\/\//i, "");
|
|
80356
|
+
const slash = withoutScheme.indexOf("/");
|
|
80357
|
+
return slash === -1 ? withoutScheme.toLowerCase() : `${withoutScheme.slice(0, slash).toLowerCase()}${withoutScheme.slice(slash)}`;
|
|
80358
|
+
}
|
|
80359
|
+
/** Split a lowercased, scheme-less URL or domain pattern into host, port and path. */
|
|
80360
|
+
function splitUrlPattern(pattern) {
|
|
80361
|
+
const normalized = stripUrlSchemeKeepingPathCase(pattern).toLowerCase();
|
|
80362
|
+
const slash = normalized.indexOf("/");
|
|
80363
|
+
const hostPort = slash === -1 ? normalized : normalized.slice(0, slash);
|
|
80364
|
+
const path = slash === -1 ? void 0 : normalized.slice(slash);
|
|
80365
|
+
const port = /:([0-9*]+)$/.exec(hostPort);
|
|
80366
|
+
return port === null ? {
|
|
80367
|
+
host: hostPort,
|
|
80368
|
+
port: void 0,
|
|
80369
|
+
path
|
|
80370
|
+
} : {
|
|
80371
|
+
host: hostPort.slice(0, port.index),
|
|
80372
|
+
port: port[1],
|
|
80373
|
+
path
|
|
80374
|
+
};
|
|
80375
|
+
}
|
|
80376
|
+
/**
|
|
80377
|
+
* Whether two URL or domain patterns can name one URL. Both are compared
|
|
80378
|
+
* lowercased and without their scheme, part by part, so a `*` in one part
|
|
80379
|
+
* never reaches into another (`*.github.com` does not overlap
|
|
80380
|
+
* `example.org/private/*`). A pathless pattern is a host, which domain-only
|
|
80381
|
+
* tools read as every URL on it, on any port, and on its subdomains, so a
|
|
80382
|
+
* missing path or port matches every path or port, and each host also stands
|
|
80383
|
+
* for `*.<host>`. Because a glob can also match across those parts, the
|
|
80384
|
+
* whole strings are compared as well, and an overlap from either counts. A
|
|
80385
|
+
* pattern holding whitespace names no URL.
|
|
80386
|
+
*/
|
|
80387
|
+
function urlPatternsOverlap(left, right) {
|
|
80388
|
+
if (left === right) return true;
|
|
80389
|
+
if (/\s/.test(left) || /\s/.test(right)) return false;
|
|
80390
|
+
return urlPartsOverlap(left, right) || wholeStringsOverlap(left, right);
|
|
80391
|
+
}
|
|
80392
|
+
/**
|
|
80393
|
+
* The whole-string comparison a `*` restriction also gets, since a glob there
|
|
80394
|
+
* matches the whole URL (`*.pdf` names `https://example.com/doc.pdf`): the two
|
|
80395
|
+
* patterns compared as written and lowercased without a scheme, each widened
|
|
80396
|
+
* by `createShadowingRestrictionsTest`.
|
|
80397
|
+
*/
|
|
80398
|
+
function wholeStringsOverlap(left, right) {
|
|
80399
|
+
return [[left, right], [normalizeUrlPattern(left), normalizeUrlPattern(right)]].some(([restriction = "", allow = ""]) => createShadowingRestrictionsTest([{
|
|
80400
|
+
pattern: restriction,
|
|
80401
|
+
fromAllToolsCategory: false
|
|
80402
|
+
}])(allow).length > 0);
|
|
80403
|
+
}
|
|
80404
|
+
function urlPartsOverlap(left, right) {
|
|
80405
|
+
const a = splitUrlPattern(left);
|
|
80406
|
+
const b = splitUrlPattern(right);
|
|
80407
|
+
const hosts = (host) => [host, `*.${host}`];
|
|
80408
|
+
if (!hosts(a.host).some((x) => hosts(b.host).some((y) => globsIntersect(x, y)))) return false;
|
|
80409
|
+
if (a.port !== void 0 && b.port !== void 0 && !globsIntersect(a.port, b.port)) return false;
|
|
80410
|
+
return a.path === void 0 || b.path === void 0 || globsIntersect(a.path, b.path);
|
|
80411
|
+
}
|
|
80412
|
+
/**
|
|
80413
|
+
* Whether any of `restrictions` overlaps an allow pattern of `category`. For
|
|
80414
|
+
* `webfetch` the patterns are compared as URLs (see `urlPatternsOverlap`).
|
|
80415
|
+
*/
|
|
80416
|
+
function createCategoryShadowTest({ restrictions, category }) {
|
|
80417
|
+
if (category === WEBFETCH_CATEGORY$2) return (allowPattern) => restrictions.some(({ pattern }) => urlPatternsOverlap(pattern, allowPattern));
|
|
80418
|
+
const asWritten = createShadowingRestrictionsTest(restrictions);
|
|
80419
|
+
return (allowPattern) => asWritten(allowPattern).length > 0;
|
|
80420
|
+
}
|
|
80421
|
+
/** One allow rule left out of a tool's config, named as `<category>: <pattern>`. */
|
|
80422
|
+
function describeRule(category, pattern) {
|
|
80423
|
+
return `${category}: ${pattern}`;
|
|
80424
|
+
}
|
|
80425
|
+
/**
|
|
80426
|
+
* The `*` category with only its catch-all entries left, warning about the
|
|
80427
|
+
* pattern-specific ones dropped.
|
|
80428
|
+
*/
|
|
80429
|
+
function keepAllToolsCatchAll({ rules, isCatchAll, toolLabel, logger }) {
|
|
80430
|
+
const kept = {};
|
|
80431
|
+
const dropped = [];
|
|
80432
|
+
for (const [pattern, action] of Object.entries(rules)) if (isCatchAll(pattern)) kept[pattern] = action;
|
|
80433
|
+
else dropped.push(`${pattern} (${action})`);
|
|
80434
|
+
if (dropped.length > 0) warnWithFallback(logger, `${toolLabel} has no rule that scopes a pattern to every tool, so the all-tools '*' rule(s) for ${dropped.join(", ")} were not written as such; a deny or ask among them is honored by withholding the allow rules it covers in the other categories.`);
|
|
80435
|
+
return kept;
|
|
80436
|
+
}
|
|
80437
|
+
/**
|
|
80438
|
+
* Apply the all-tools `*` category's restrictions to every other category, for
|
|
80439
|
+
* a tool that cannot write a pattern-specific rule spanning every tool.
|
|
80440
|
+
*
|
|
80441
|
+
* A `deny` or `ask` written under `*` covers every tool — `{"*": {".env":
|
|
80442
|
+
* "deny"}}` denies reading `.env` as surely as `{"read": {".env": "deny"}}`
|
|
80443
|
+
* does. A tool with no such rule would otherwise keep a `read: {"*": "allow"}`
|
|
80444
|
+
* beside it and auto-approve the very file the author denied. So:
|
|
80445
|
+
*
|
|
80446
|
+
* - `bash` gets the restrictions copied in, exactly as `honorAllToolsOnBash`
|
|
80447
|
+
* does, since a command list can carry them.
|
|
80448
|
+
* - Every other category loses each `allow` that names an input a `*`
|
|
80449
|
+
* restriction also names (see `createShadowingRestrictionsTest`); the tool
|
|
80450
|
+
* then falls back to its own prompt or default for it, the safe direction.
|
|
80451
|
+
* (AugmentCode instead applies its blanket all-tools fallback to a tool left
|
|
80452
|
+
* with no entries, since its own default would auto-run the tool.) Width
|
|
80453
|
+
* does not matter: a shell-only `{"*": {"git push *": "ask"}}` withholds a
|
|
80454
|
+
* `read: {"*": "allow"}` too, because the catch-all names every input.
|
|
80455
|
+
* - With `dropAllToolsPatterns`, the pattern-specific entries of `*` itself are
|
|
80456
|
+
* removed, for a tool that would otherwise write them as an inert literal
|
|
80457
|
+
* `*(<pattern>)` rule. They are honored by the withholding above.
|
|
80458
|
+
*
|
|
80459
|
+
* `restateAs` says which pattern-specific `*` restrictions the tool can write
|
|
80460
|
+
* as a rule of the category itself (`Read(.env)`), for a tool whose default for
|
|
80461
|
+
* an input with no rule would auto-approve it: such a restriction is copied
|
|
80462
|
+
* into each stated category it applies to (see `restatesAsCategoryRule`), so
|
|
80463
|
+
* the input stays restricted after its allow is withheld.
|
|
80464
|
+
* `downgradeWithheldCatchAll` writes a withheld catch-all `*` allow as `ask`
|
|
80465
|
+
* (`deny` under a catch-all `*` deny) rather than dropping it, for a tool that keeps a stale `always` otherwise.
|
|
80466
|
+
*
|
|
80467
|
+
* `writesAllToolsCatchAll` says the tool already enforces a `*` catch-all
|
|
80468
|
+
* (`{"*": {"*": "ask"}}`) natively over its per-tool allows, so the catch-all
|
|
80469
|
+
* is left out of the withholding. `isCatchAll` says which spellings the tool
|
|
80470
|
+
* reads as that catch-all (by default only `*`).
|
|
80471
|
+
*
|
|
80472
|
+
* Every withheld allow is named in one warning.
|
|
80473
|
+
*/
|
|
80474
|
+
function honorAllToolsRestrictions({ permission, toolLabel, logger, writesAllToolsCatchAll = false, dropAllToolsPatterns = false, isCatchAll = (pattern) => pattern === "*", restateAs = () => false, downgradeWithheldCatchAll = false }) {
|
|
80475
|
+
const allToolsRules = Object.hasOwn(permission, "*") ? permission["*"] : void 0;
|
|
80476
|
+
if (allToolsRules === void 0) return permission;
|
|
80477
|
+
const restrictions = Object.entries(allToolsRules).filter(([pattern, action]) => action !== "allow" && !isPrototypePollutionKey(pattern) && !(writesAllToolsCatchAll && isCatchAll(pattern))).map(([pattern]) => ({
|
|
80478
|
+
pattern,
|
|
80479
|
+
fromAllToolsCategory: true
|
|
80480
|
+
}));
|
|
80481
|
+
const result = {};
|
|
80482
|
+
const withheld = [];
|
|
80483
|
+
for (const [category, rules] of Object.entries(permission)) {
|
|
80484
|
+
if (category === "*") {
|
|
80485
|
+
const kept = dropAllToolsPatterns ? keepAllToolsCatchAll({
|
|
80486
|
+
rules,
|
|
80487
|
+
isCatchAll,
|
|
80488
|
+
toolLabel,
|
|
80489
|
+
logger
|
|
80490
|
+
}) : rules;
|
|
80491
|
+
if (!dropAllToolsPatterns || Object.keys(kept).length > 0) result[category] = kept;
|
|
80492
|
+
continue;
|
|
80493
|
+
}
|
|
80494
|
+
if (restrictions.length === 0) {
|
|
80495
|
+
result[category] = rules;
|
|
80496
|
+
continue;
|
|
80497
|
+
}
|
|
80498
|
+
if (category === "bash") {
|
|
80499
|
+
const bash = bashRulesHonoringAllTools({
|
|
80500
|
+
...permission,
|
|
80501
|
+
["*"]: Object.fromEntries(restrictions.map(({ pattern }) => [pattern, allToolsRules[pattern] ?? "deny"]))
|
|
80502
|
+
});
|
|
80503
|
+
for (const [pattern, action] of Object.entries(rules)) if (action === "allow" && bash[pattern] !== "allow") withheld.push(describeRule(category, pattern));
|
|
80504
|
+
result[category] = bash;
|
|
80505
|
+
continue;
|
|
80506
|
+
}
|
|
80507
|
+
result[category] = honorInCategory({
|
|
80508
|
+
category,
|
|
80509
|
+
rules,
|
|
80510
|
+
restrictions: restrictions.map(({ pattern }) => ({
|
|
80511
|
+
pattern,
|
|
80512
|
+
action: allToolsRules[pattern] ?? "deny"
|
|
80513
|
+
})),
|
|
80514
|
+
restateAs,
|
|
80515
|
+
downgradeWithheldCatchAll,
|
|
80516
|
+
withheld
|
|
80517
|
+
});
|
|
80518
|
+
}
|
|
80519
|
+
if (withheld.length > 0) warnWithFallback(logger, `${toolLabel} was not given the allow rule(s) for ${withheld.join(", ")} because a deny or ask rule under the all-tools '*' category restricts the same inputs, and the stricter rule wins whatever its width.`);
|
|
80520
|
+
return result;
|
|
80521
|
+
}
|
|
80522
|
+
/** File categories whose patterns are paths. */
|
|
80523
|
+
const PATH_CATEGORIES = /* @__PURE__ */ new Set([
|
|
80524
|
+
"read",
|
|
80525
|
+
"edit",
|
|
80526
|
+
"write"
|
|
80527
|
+
]);
|
|
80528
|
+
/**
|
|
80529
|
+
* The common `restateAs`: a restriction is restated under a path category when
|
|
80530
|
+
* it reads as a path (no whitespace, so not a command such as `git push *`),
|
|
80531
|
+
* and under `webfetch` when it reads as a URL or domain. `actions` limits it to
|
|
80532
|
+
* the actions the tool can write per pattern.
|
|
80533
|
+
*/
|
|
80534
|
+
function restatesAsCategoryRule(actions = ["deny", "ask"]) {
|
|
80535
|
+
return ({ category, pattern, action }) => {
|
|
80536
|
+
if (!actions.includes(action) || pattern === "*") return false;
|
|
80537
|
+
if (PATH_CATEGORIES.has(category)) return !/\s/.test(pattern);
|
|
80538
|
+
if (category === WEBFETCH_CATEGORY$2) return /^([a-z][a-z0-9+.-]*:\/\/)?[\w*-]+(\.[\w*-]+)+(:[\w*]+)?(\/\S*)?$/i.test(pattern);
|
|
80539
|
+
return false;
|
|
80540
|
+
};
|
|
80541
|
+
}
|
|
80542
|
+
/** One non-shell category with the `*` restrictions honored; see the caller. */
|
|
80543
|
+
function honorInCategory({ category, rules, restrictions, restateAs, downgradeWithheldCatchAll, withheld }) {
|
|
80544
|
+
const shadowingRestrictions = createCategoryShadowTest({
|
|
80545
|
+
restrictions: restrictions.map(({ pattern }) => ({
|
|
80546
|
+
pattern,
|
|
80547
|
+
fromAllToolsCategory: true
|
|
80548
|
+
})),
|
|
80549
|
+
category
|
|
80550
|
+
});
|
|
80551
|
+
const downgradedAction = restrictions.some(({ pattern, action }) => pattern === "*" && action === "deny") ? "deny" : "ask";
|
|
80552
|
+
const kept = {};
|
|
80553
|
+
for (const [pattern, action] of Object.entries(rules)) {
|
|
80554
|
+
if (action === "allow" && shadowingRestrictions(pattern)) {
|
|
80555
|
+
withheld.push(describeRule(category, pattern));
|
|
80556
|
+
if (downgradeWithheldCatchAll && pattern === "*") kept[pattern] = downgradedAction;
|
|
80557
|
+
continue;
|
|
80558
|
+
}
|
|
80559
|
+
kept[pattern] = action;
|
|
80560
|
+
}
|
|
80561
|
+
return restateInCategory({
|
|
80562
|
+
category,
|
|
80563
|
+
rules: kept,
|
|
80564
|
+
restrictions,
|
|
80565
|
+
restateAs
|
|
80566
|
+
});
|
|
80567
|
+
}
|
|
80568
|
+
function restateInCategory({ category, rules, restrictions, restateAs }) {
|
|
80569
|
+
const restated = { ...rules };
|
|
80570
|
+
for (const { pattern, action } of restrictions) {
|
|
80571
|
+
if (isPrototypePollutionKey(pattern) || !restateAs({
|
|
80572
|
+
category,
|
|
80573
|
+
pattern,
|
|
80574
|
+
action
|
|
80575
|
+
})) continue;
|
|
80576
|
+
if (isStricterAction({
|
|
80577
|
+
action,
|
|
80578
|
+
existing: Object.hasOwn(restated, pattern) ? restated[pattern] : void 0
|
|
80579
|
+
})) restated[pattern] = action;
|
|
80580
|
+
}
|
|
80581
|
+
return restated;
|
|
80582
|
+
}
|
|
80583
|
+
/**
|
|
80584
|
+
* One category's rules with the pattern-specific `*` restrictions `restateAs`
|
|
80585
|
+
* accepts copied in as its own rules (the stricter action wins on a shared
|
|
80586
|
+
* spelling), for a tool that can write them there and needs no allow
|
|
80587
|
+
* withheld, because its own ordering already lets the copied rule win.
|
|
80588
|
+
*/
|
|
80589
|
+
function restateAllToolsRestrictionsInCategory({ permission, category, restateAs }) {
|
|
80590
|
+
const rules = lookupOwn({
|
|
80591
|
+
record: permission,
|
|
80592
|
+
key: category
|
|
80593
|
+
}) ?? {};
|
|
80594
|
+
const allToolsRules = lookupOwn({
|
|
80595
|
+
record: permission,
|
|
80596
|
+
key: "*"
|
|
80597
|
+
}) ?? {};
|
|
80598
|
+
return restateInCategory({
|
|
80599
|
+
category,
|
|
80600
|
+
rules,
|
|
80601
|
+
restrictions: Object.entries(allToolsRules).filter(([, action]) => action !== "allow").map(([pattern, action]) => ({
|
|
80602
|
+
pattern,
|
|
80603
|
+
action
|
|
80604
|
+
})),
|
|
80605
|
+
restateAs
|
|
80606
|
+
});
|
|
80607
|
+
}
|
|
80608
|
+
/**
|
|
80609
|
+
* Withhold every `allow` that an `ask` the tool cannot write also covers, for a
|
|
80610
|
+
* tool with no ask tier on some surface.
|
|
80611
|
+
*
|
|
80612
|
+
* Such a tool prompts for whatever it does not auto-approve, so skipping the
|
|
80613
|
+
* `ask` alone is right — but only if no `allow` beside it auto-approves the
|
|
80614
|
+
* same input. The canonical order is `deny > ask > allow`, so `{"git *":
|
|
80615
|
+
* "allow", "git push *": "ask"}` must not leave `git *` auto-approved.
|
|
80616
|
+
*
|
|
80617
|
+
* Within each group (categories the tool folds into one surface share a group;
|
|
80618
|
+
* by default each category is its own), a pattern-specific `allow` an `ask`
|
|
80619
|
+
* overlaps is removed. A catch-all `*` `allow` is downgraded to `ask` instead,
|
|
80620
|
+
* so a tool that has a coarse prompting default for the whole surface (Vibe's
|
|
80621
|
+
* `permission = "ask"`) uses it; a tool that skips `ask` drops it either way.
|
|
80622
|
+
*
|
|
80623
|
+
* `isSkippedAsk` picks the `ask` rules the tool cannot write (by default every
|
|
80624
|
+
* one). Every withheld allow is named in one warning.
|
|
80625
|
+
*/
|
|
80626
|
+
function withholdAllowsShadowedByAsks({ permission, toolLabel, logger, isSkippedAsk = () => true, groupOf = (category) => category }) {
|
|
80627
|
+
const asksByGroup = /* @__PURE__ */ new Map();
|
|
80628
|
+
for (const [category, rules] of Object.entries(permission)) for (const [pattern, action] of Object.entries(rules)) {
|
|
80629
|
+
if (action !== "ask" || isPrototypePollutionKey(pattern)) continue;
|
|
80630
|
+
if (!isSkippedAsk({
|
|
80631
|
+
category,
|
|
80632
|
+
pattern
|
|
80633
|
+
})) continue;
|
|
80634
|
+
const group = groupOf(category);
|
|
80635
|
+
asksByGroup.set(group, [...asksByGroup.get(group) ?? [], pattern]);
|
|
80636
|
+
}
|
|
80637
|
+
if (asksByGroup.size === 0) return permission;
|
|
80638
|
+
const result = {};
|
|
80639
|
+
const withheld = [];
|
|
80640
|
+
for (const [category, rules] of Object.entries(permission)) {
|
|
80641
|
+
const asks = asksByGroup.get(groupOf(category));
|
|
80642
|
+
if (asks === void 0) {
|
|
80643
|
+
result[category] = rules;
|
|
80644
|
+
continue;
|
|
80645
|
+
}
|
|
80646
|
+
const shadowingAsks = createCategoryShadowTest({
|
|
80647
|
+
restrictions: asks.map((pattern) => ({
|
|
80648
|
+
pattern,
|
|
80649
|
+
fromAllToolsCategory: false
|
|
80650
|
+
})),
|
|
80651
|
+
category
|
|
80652
|
+
});
|
|
80653
|
+
const kept = {};
|
|
80654
|
+
for (const [pattern, action] of Object.entries(rules)) {
|
|
80655
|
+
if (action !== "allow" || !shadowingAsks(pattern)) {
|
|
80656
|
+
kept[pattern] = action;
|
|
80657
|
+
continue;
|
|
80658
|
+
}
|
|
80659
|
+
withheld.push(describeRule(category, pattern));
|
|
80660
|
+
if (pattern === "*") kept[pattern] = "ask";
|
|
80661
|
+
}
|
|
80662
|
+
result[category] = kept;
|
|
80663
|
+
}
|
|
80664
|
+
if (withheld.length > 0) warnWithFallback(logger, `${toolLabel} has no "ask" tier there, so the allow rule(s) for ${withheld.join(", ")} were withheld (a catch-all '*' allow falls back to the tool's prompt): an ask rule covers the same inputs, and an allow kept beside it would auto-approve what the ask should prompt for.`);
|
|
80665
|
+
return result;
|
|
80666
|
+
}
|
|
80308
80667
|
// src/features/permissions/tool-pattern-entry.ts
|
|
80309
80668
|
/**
|
|
80310
80669
|
* Parse a `Tool(pattern)` permission entry (e.g. `Bash(npm run *)`) into its
|
|
@@ -80390,7 +80749,7 @@ const MATCH_ALL_PATH_GLOBS = /* @__PURE__ */ new Set([
|
|
|
80390
80749
|
"**/*"
|
|
80391
80750
|
]);
|
|
80392
80751
|
const DIRECTORY_CONTENTS_SUFFIX = /\/\*\*(?:\/\*)?$/;
|
|
80393
|
-
const HOME_OR_VARIABLE_PATH = /^~(
|
|
80752
|
+
const HOME_OR_VARIABLE_PATH = /^~(?:[A-Za-z_][\w.-]*)?(?:[/\\]|$)|^\$[A-Za-z_]|^%[A-Za-z_]\w*%|\$\{[A-Za-z_]/;
|
|
80394
80753
|
const LEADING_HOME = /^~(?:\/|$)/;
|
|
80395
80754
|
/**
|
|
80396
80755
|
* The home directory as an Antigravity path: forward slashes, no trailing
|
|
@@ -80405,7 +80764,7 @@ function toAntigravityHomePath(homeDirectory) {
|
|
|
80405
80764
|
* apply (rulesync#3324). Only a file the user's own home holds, such as the
|
|
80406
80765
|
* global Antigravity CLI settings, may carry a machine-specific path, so the
|
|
80407
80766
|
* caller passes `homeDirectory` only then. `$HOME`, `${HOME}`, `%VAR%` and
|
|
80408
|
-
* `~user/` are left as written
|
|
80767
|
+
* `~user/` are left as written and still warned about.
|
|
80409
80768
|
*/
|
|
80410
80769
|
function expandLeadingHome(target, homeDirectory) {
|
|
80411
80770
|
if (homeDirectory === void 0 || !LEADING_HOME.test(target)) return target;
|
|
@@ -80647,30 +81006,84 @@ function convertRulesyncToAntigravityPermissions({ config, toAction, toolLabel,
|
|
|
80647
81006
|
const allow = [];
|
|
80648
81007
|
const ask = [];
|
|
80649
81008
|
const deny = [];
|
|
80650
|
-
|
|
81009
|
+
const permission = honorAllToolsRestrictions({
|
|
81010
|
+
permission: config.permission,
|
|
81011
|
+
toolLabel,
|
|
81012
|
+
logger
|
|
81013
|
+
});
|
|
81014
|
+
const translated = [];
|
|
81015
|
+
for (const [category, rules] of Object.entries(permission)) {
|
|
80651
81016
|
const action = toAction(category);
|
|
80652
|
-
for (const [pattern,
|
|
81017
|
+
for (const [pattern, decision] of Object.entries(rules)) {
|
|
80653
81018
|
const entry = buildAntigravityPermissionEntry({
|
|
80654
81019
|
action,
|
|
80655
81020
|
category,
|
|
80656
81021
|
pattern,
|
|
80657
|
-
decision
|
|
81022
|
+
decision,
|
|
80658
81023
|
logger,
|
|
80659
81024
|
toolLabel,
|
|
80660
81025
|
homeDirectory
|
|
80661
81026
|
});
|
|
80662
|
-
|
|
80663
|
-
|
|
80664
|
-
|
|
80665
|
-
|
|
80666
|
-
|
|
80667
|
-
|
|
80668
|
-
|
|
81027
|
+
translated.push({
|
|
81028
|
+
action,
|
|
81029
|
+
category,
|
|
81030
|
+
pattern,
|
|
81031
|
+
decision,
|
|
81032
|
+
entry
|
|
81033
|
+
});
|
|
81034
|
+
}
|
|
81035
|
+
}
|
|
81036
|
+
const skippedRestrictionsByAction = /* @__PURE__ */ new Map();
|
|
81037
|
+
const groupOf = ({ action, category }) => category.startsWith("mcp__") ? category : action;
|
|
81038
|
+
for (const { action, category, pattern, decision, entry } of translated) if (entry === void 0 && decision !== "allow") {
|
|
81039
|
+
const group = groupOf({
|
|
81040
|
+
action,
|
|
81041
|
+
category
|
|
81042
|
+
});
|
|
81043
|
+
skippedRestrictionsByAction.set(group, [...skippedRestrictionsByAction.get(group) ?? [], pattern]);
|
|
81044
|
+
}
|
|
81045
|
+
const allToolsRestrictions = Object.entries(lookupOwn({
|
|
81046
|
+
record: config.permission,
|
|
81047
|
+
key: "*"
|
|
81048
|
+
}) ?? {}).filter(([pattern, decision]) => decision !== "allow" && pattern !== "*" && !isPrototypePollutionKey(pattern)).map(([pattern]) => pattern);
|
|
81049
|
+
const shadowingTests = /* @__PURE__ */ new Map();
|
|
81050
|
+
const shadowingTestOf = (group) => {
|
|
81051
|
+
const cached = shadowingTests.get(group);
|
|
81052
|
+
if (cached !== void 0) return cached;
|
|
81053
|
+
const patterns = [...skippedRestrictionsByAction.get(group) ?? [], ...allToolsRestrictions];
|
|
81054
|
+
let test;
|
|
81055
|
+
if (URL_ACTIONS.has(group)) test = (allowPattern) => patterns.some((pattern) => urlPatternsOverlap(pattern, allowPattern));
|
|
81056
|
+
else {
|
|
81057
|
+
const asGlobs = createShadowingRestrictionsTest([.../* @__PURE__ */ new Set([...patterns, ...patterns.map(normalizeUrlPattern)])].map((pattern) => ({
|
|
81058
|
+
pattern,
|
|
81059
|
+
fromAllToolsCategory: false
|
|
81060
|
+
})));
|
|
81061
|
+
test = (allowPattern) => asGlobs(allowPattern).length > 0 || asGlobs(normalizeUrlPattern(allowPattern)).length > 0;
|
|
81062
|
+
}
|
|
81063
|
+
shadowingTests.set(group, test);
|
|
81064
|
+
return test;
|
|
81065
|
+
};
|
|
81066
|
+
const withheld = [];
|
|
81067
|
+
for (const { action, category, pattern, decision, entry } of translated) {
|
|
81068
|
+
if (entry === void 0) continue;
|
|
81069
|
+
switch (decision) {
|
|
81070
|
+
case "allow":
|
|
81071
|
+
if ([pattern, effectiveTargetScope(entry)].some((candidate) => shadowingTestOf(groupOf({
|
|
81072
|
+
action,
|
|
81073
|
+
category
|
|
81074
|
+
}))(candidate))) {
|
|
81075
|
+
withheld.push(`${category}: ${pattern}`);
|
|
80669
81076
|
break;
|
|
80670
|
-
|
|
80671
|
-
|
|
81077
|
+
}
|
|
81078
|
+
allow.push(entry);
|
|
81079
|
+
break;
|
|
81080
|
+
case "ask":
|
|
81081
|
+
ask.push(entry);
|
|
81082
|
+
break;
|
|
81083
|
+
case "deny": deny.push(entry);
|
|
80672
81084
|
}
|
|
80673
81085
|
}
|
|
81086
|
+
if (withheld.length > 0) logger.warn(`${toolLabel} permissions: the allow rule(s) for ${withheld.join(", ")} were not written because a deny or ask rule ${toolLabel} cannot express (skipped above) covers the same inputs, and the stricter rule wins.`);
|
|
80674
81087
|
return {
|
|
80675
81088
|
allow: [...new Set(allow)],
|
|
80676
81089
|
ask: [...new Set(ask)],
|
|
@@ -80678,6 +81091,24 @@ function convertRulesyncToAntigravityPermissions({ config, toAction, toolLabel,
|
|
|
80678
81091
|
};
|
|
80679
81092
|
}
|
|
80680
81093
|
/**
|
|
81094
|
+
* The widest glob an emitted entry grants, for comparing an allow against the
|
|
81095
|
+
* restrictions Antigravity cannot express. The emitted target can grant more
|
|
81096
|
+
* than the canonical pattern it came from: a path target also covers
|
|
81097
|
+
* everything inside it (and `.` the whole workspace), a command target is a
|
|
81098
|
+
* word prefix (`git push` approves `git push --force`), and a domain target
|
|
81099
|
+
* covers its subdomains and every URL on it. Widening only ever withholds more.
|
|
81100
|
+
*/
|
|
81101
|
+
function effectiveTargetScope(entry) {
|
|
81102
|
+
const { toolName, pattern: target } = parseToolPatternEntry(entry);
|
|
81103
|
+
if (target === "*") return "*";
|
|
81104
|
+
if (PATH_ACTIONS.has(toolName)) {
|
|
81105
|
+
const path = target.replace(/\/+$/, "");
|
|
81106
|
+
return path === "." || path === "" ? "*" : `${path}/**`;
|
|
81107
|
+
}
|
|
81108
|
+
if (ANTIGRAVITY_COMMAND_ACTIONS.has(toolName)) return target.endsWith("*") ? target : `${target}*`;
|
|
81109
|
+
return target;
|
|
81110
|
+
}
|
|
81111
|
+
/**
|
|
80681
81112
|
* Convert Antigravity allow/ask/deny arrays to rulesync permissions config,
|
|
80682
81113
|
* shared by the CLI and IDE adapters; `toCategory` maps the target's tool or
|
|
80683
81114
|
* action name back to a canonical category.
|
|
@@ -81578,15 +82009,21 @@ async function withBaseEnabledPlugins({ mergedContent, baseFilePath }) {
|
|
|
81578
82009
|
function convertRulesyncToAugmentEntries({ config, logger }) {
|
|
81579
82010
|
const entries = [];
|
|
81580
82011
|
const resolvedBashRules = bashRulesHonoringAllTools(config.permission);
|
|
82012
|
+
const honoredPermission = honorAllToolsRestrictions({
|
|
82013
|
+
permission: config.permission,
|
|
82014
|
+
toolLabel: "AugmentCode",
|
|
82015
|
+
logger,
|
|
82016
|
+
writesAllToolsCatchAll: true
|
|
82017
|
+
});
|
|
81581
82018
|
const permission = config.permission.bash !== void 0 || Object.keys(resolvedBashRules).length > 0 ? {
|
|
81582
|
-
...
|
|
82019
|
+
...honoredPermission,
|
|
81583
82020
|
bash: resolvedBashRules
|
|
81584
|
-
} :
|
|
82021
|
+
} : honoredPermission;
|
|
81585
82022
|
const allToolsFailClosedType = computeAllToolsFailClosedType(config.permission["*"]);
|
|
81586
82023
|
const categoriesWithOwnEntries = /* @__PURE__ */ new Set();
|
|
81587
82024
|
for (const [category, rules] of Object.entries(permission)) {
|
|
81588
82025
|
if (category === "*") {
|
|
81589
|
-
logger?.warn("AugmentCode permissions: the all-tools '*' category cannot be emitted as a single entry because AugmentCode has no wildcard toolName. Deny/ask rules are folded into 'launch-process' and, for any other managed tool that has no explicit rules of its own, applied as a blanket deny/ask; all-tools allow rules and tools that
|
|
82026
|
+
logger?.warn("AugmentCode permissions: the all-tools '*' category cannot be emitted as a single entry because AugmentCode has no wildcard toolName. Deny/ask rules are folded into 'launch-process' and, for any other managed tool that has no explicit rules of its own (or whose allow rules were all withheld because a '*' deny/ask covers them), applied as a blanket deny/ask; all-tools allow rules and tools that still define rules of their own are left untouched.");
|
|
81590
82027
|
continue;
|
|
81591
82028
|
}
|
|
81592
82029
|
const augmentToolName = toAugmentToolName(category);
|
|
@@ -81645,9 +82082,10 @@ function computeAllToolsFailClosedType(allToolsRules) {
|
|
|
81645
82082
|
* other managed tools: one that produced no entries of its own above must not fall back to
|
|
81646
82083
|
* AugmentCode's own default just because it has no per-input matcher to narrow the all-tools
|
|
81647
82084
|
* restriction onto. A category can be stated yet still emit nothing (e.g. only non-`*` allow/ask
|
|
81648
|
-
* patterns, dropped with a warning
|
|
81649
|
-
*
|
|
81650
|
-
*
|
|
82085
|
+
* patterns, dropped with a warning, or only allows withheld by `honorAllToolsRestrictions`), so
|
|
82086
|
+
* this checks emitted entries rather than whether the category was merely present in the source
|
|
82087
|
+
* config. Falling back to AugmentCode's own default instead would let a read-only tool run on the
|
|
82088
|
+
* input the restriction names. A tool whose own rules did emit entries is left untouched here.
|
|
81651
82089
|
*/
|
|
81652
82090
|
function synthesizeManagedToolFallbackEntries(categoriesWithOwnEntries, allToolsFailClosedType) {
|
|
81653
82091
|
if (allToolsFailClosedType === void 0) return [];
|
|
@@ -84111,8 +84549,10 @@ function categoryOfRule$2(rule) {
|
|
|
84111
84549
|
* - MCP rules take no specifier, so a scoped `mcp__<...>` category is written
|
|
84112
84550
|
* for its catch-all pattern only.
|
|
84113
84551
|
* - The all-tools `*` category is CodeBuddy's documented standalone `*` rule
|
|
84114
|
-
* for its catch-all pattern.
|
|
84115
|
-
*
|
|
84552
|
+
* for its catch-all pattern. A narrower `*` pattern reaches the `Bash`
|
|
84553
|
+
* rules through `honorAllToolsRestrictions`, which also withholds every
|
|
84554
|
+
* allow it overlaps in the other categories — a `{"*": "allow"}` included,
|
|
84555
|
+
* even for a shell-only pattern such as `git push *`.
|
|
84116
84556
|
*/
|
|
84117
84557
|
function buildCodebuddyRule({ category, pattern, action, logger }) {
|
|
84118
84558
|
const catchAll = pattern === "*";
|
|
@@ -84160,7 +84600,13 @@ function parseCodebuddyRule(rule) {
|
|
|
84160
84600
|
* manage (and every entry rulesync cannot parse).
|
|
84161
84601
|
*/
|
|
84162
84602
|
function buildCodebuddyRuleLists({ config, existingPermissions, logger }) {
|
|
84163
|
-
const permission =
|
|
84603
|
+
const permission = honorAllToolsRestrictions({
|
|
84604
|
+
permission: config.permission,
|
|
84605
|
+
toolLabel: "CodeBuddy",
|
|
84606
|
+
logger,
|
|
84607
|
+
restateAs: restatesAsCategoryRule(),
|
|
84608
|
+
writesAllToolsCatchAll: true
|
|
84609
|
+
});
|
|
84164
84610
|
const ranked = /* @__PURE__ */ new Map();
|
|
84165
84611
|
const managedCategories = /* @__PURE__ */ new Set();
|
|
84166
84612
|
for (const [category, rules] of Object.entries(permission)) {
|
|
@@ -85755,6 +86201,44 @@ function addCodexWebfetchRules({ rules, domains, logger }) {
|
|
|
85755
86201
|
domains[pattern] = action;
|
|
85756
86202
|
}
|
|
85757
86203
|
}
|
|
86204
|
+
/**
|
|
86205
|
+
* Copy the all-tools `*` path restrictions into the `read` rules, when the
|
|
86206
|
+
* config states a filesystem category at all: Codex has no all-tools rule, so
|
|
86207
|
+
* `{"*": {".env": "deny"}, "edit": {"*": "allow"}}` would otherwise grant
|
|
86208
|
+
* write access to `.env`. Both a `deny` and an `ask` land under `read`, where
|
|
86209
|
+
* they are handled exactly like a directly written read rule (an ask becomes
|
|
86210
|
+
* `"deny"`, since Codex cannot prompt for a path), so a narrower write allow
|
|
86211
|
+
* they cover is denied as well. A catch-all `*` deny is copied too and
|
|
86212
|
+
* withholds every filesystem allow, so `{"*": {"*": "deny"}, "edit": {"src":
|
|
86213
|
+
* "allow"}}` grants nothing; a catch-all
|
|
86214
|
+
* ask is the documented default idiom and is left alone. Other patterns are
|
|
86215
|
+
* copied only when they read as a path — `git push *` is a command, not a
|
|
86216
|
+
* path — so the sandbox gains nothing but these restrictions.
|
|
86217
|
+
*/
|
|
86218
|
+
function restateAllToolsPathRestrictions({ config, filesystemCategoryRules }) {
|
|
86219
|
+
if (Object.keys(filesystemCategoryRules).length === 0) return;
|
|
86220
|
+
if (lookupOwn({
|
|
86221
|
+
record: config.permission,
|
|
86222
|
+
key: "*"
|
|
86223
|
+
})?.["*"] === "deny") for (const category of [
|
|
86224
|
+
"read",
|
|
86225
|
+
"edit",
|
|
86226
|
+
"write"
|
|
86227
|
+
]) {
|
|
86228
|
+
const rules = filesystemCategoryRules[category];
|
|
86229
|
+
if (rules === void 0) continue;
|
|
86230
|
+
filesystemCategoryRules[category] = Object.fromEntries(Object.entries(rules).filter(([, action]) => action !== "allow"));
|
|
86231
|
+
}
|
|
86232
|
+
const isPath = restatesAsCategoryRule(["deny", "ask"]);
|
|
86233
|
+
filesystemCategoryRules.read = restateAllToolsRestrictionsInCategory({
|
|
86234
|
+
permission: {
|
|
86235
|
+
...config.permission,
|
|
86236
|
+
read: filesystemCategoryRules.read ?? {}
|
|
86237
|
+
},
|
|
86238
|
+
category: "read",
|
|
86239
|
+
restateAs: (params) => params.pattern === "*" ? params.action === "deny" : isPath(params)
|
|
86240
|
+
});
|
|
86241
|
+
}
|
|
85758
86242
|
function convertRulesyncToCodexProfile({ config, logger }) {
|
|
85759
86243
|
const filesystem = { [CODEX_MINIMAL_KEY]: "read" };
|
|
85760
86244
|
const workspaceRootFilesystem = {};
|
|
@@ -85766,8 +86250,24 @@ function convertRulesyncToCodexProfile({ config, logger }) {
|
|
|
85766
86250
|
continue;
|
|
85767
86251
|
}
|
|
85768
86252
|
if (toolName === "webfetch") {
|
|
86253
|
+
const allToolsRules = lookupOwn({
|
|
86254
|
+
record: config.permission,
|
|
86255
|
+
key: "*"
|
|
86256
|
+
});
|
|
86257
|
+
const { webfetch: webfetchRules = {} } = withholdAllowsShadowedByAsks({
|
|
86258
|
+
permission: { webfetch: honorAllToolsRestrictions({
|
|
86259
|
+
permission: allToolsRules === void 0 ? { webfetch: rules } : {
|
|
86260
|
+
["*"]: allToolsRules,
|
|
86261
|
+
webfetch: rules
|
|
86262
|
+
},
|
|
86263
|
+
toolLabel: "Codex CLI network domains",
|
|
86264
|
+
logger
|
|
86265
|
+
}).webfetch ?? {} },
|
|
86266
|
+
toolLabel: "Codex CLI network domains",
|
|
86267
|
+
logger
|
|
86268
|
+
});
|
|
85769
86269
|
addCodexWebfetchRules({
|
|
85770
|
-
rules,
|
|
86270
|
+
rules: webfetchRules,
|
|
85771
86271
|
domains,
|
|
85772
86272
|
logger
|
|
85773
86273
|
});
|
|
@@ -85776,6 +86276,10 @@ function convertRulesyncToCodexProfile({ config, logger }) {
|
|
|
85776
86276
|
if (toolName === "bash") continue;
|
|
85777
86277
|
logger?.warn(`Codex CLI permission profiles support only read/edit/write/webfetch categories (bash goes to .codex/rules/rulesync.rules). Skipping: ${toolName}`);
|
|
85778
86278
|
}
|
|
86279
|
+
restateAllToolsPathRestrictions({
|
|
86280
|
+
config,
|
|
86281
|
+
filesystemCategoryRules
|
|
86282
|
+
});
|
|
85779
86283
|
addCodexFilesystemRules({
|
|
85780
86284
|
categoryRules: filesystemCategoryRules,
|
|
85781
86285
|
filesystem,
|
|
@@ -86519,8 +87023,10 @@ const PADDED_SHELL_WILDCARD_REASON = "a pattern narrower than the bare 'Shell' (
|
|
|
86519
87023
|
* server or tool). A pattern on an MCP category is still written as the
|
|
86520
87024
|
* `(specifier)` here; `writableCommandcodeRule` decides what to do with it,
|
|
86521
87025
|
* because Command Code ignores it. The all-tools `*` category is only
|
|
86522
|
-
* written for its catch-all pattern; narrower `*`
|
|
86523
|
-
*
|
|
87026
|
+
* written for its catch-all pattern; a narrower `*` pattern reaches the `Shell`
|
|
87027
|
+
* entries through `honorAllToolsRestrictions`, which also withholds every allow
|
|
87028
|
+
* it overlaps in the other categories — a `{"*": "allow"}` included, even for a
|
|
87029
|
+
* shell-only pattern such as `git push *`.
|
|
86524
87030
|
*/
|
|
86525
87031
|
function buildCommandcodeRule(category, pattern) {
|
|
86526
87032
|
const catchAll = pattern === "*" || pattern === "";
|
|
@@ -86814,7 +87320,13 @@ function rankCommandcodeRule({ ranked, rule, action, logger }) {
|
|
|
86814
87320
|
* rewritten by `writableCommandcodeRule`.
|
|
86815
87321
|
*/
|
|
86816
87322
|
function buildCommandcodeRuleLists({ config, existingPermissions, logger }) {
|
|
86817
|
-
const permission =
|
|
87323
|
+
const permission = honorAllToolsRestrictions({
|
|
87324
|
+
permission: config.permission,
|
|
87325
|
+
toolLabel: "Command Code",
|
|
87326
|
+
logger,
|
|
87327
|
+
restateAs: restatesAsCategoryRule(),
|
|
87328
|
+
writesAllToolsCatchAll: true
|
|
87329
|
+
});
|
|
86818
87330
|
const ranked = /* @__PURE__ */ new Map();
|
|
86819
87331
|
const managedCategories = /* @__PURE__ */ new Set();
|
|
86820
87332
|
for (const [category, rules] of Object.entries(permission)) {
|
|
@@ -87274,7 +87786,13 @@ function convertRulesyncToContinuePermissions({ config, logger }) {
|
|
|
87274
87786
|
allow: []
|
|
87275
87787
|
};
|
|
87276
87788
|
const actionByEntry = /* @__PURE__ */ new Map();
|
|
87277
|
-
for (const [category, rules] of Object.entries(
|
|
87789
|
+
for (const [category, rules] of Object.entries(honorAllToolsRestrictions({
|
|
87790
|
+
permission: config.permission,
|
|
87791
|
+
toolLabel: "Continue",
|
|
87792
|
+
logger,
|
|
87793
|
+
writesAllToolsCatchAll: true,
|
|
87794
|
+
isCatchAll: (pattern) => normalizeCatchAllPattern$1(pattern) === "*"
|
|
87795
|
+
}))) {
|
|
87278
87796
|
if (isPrototypePollutionKey(category)) continue;
|
|
87279
87797
|
const toolName = category === "*" ? "*" : toContinueToolName(category);
|
|
87280
87798
|
for (const [rawPattern, action] of Object.entries(rules)) {
|
|
@@ -87646,6 +88164,58 @@ function asAutoApproveMap(value) {
|
|
|
87646
88164
|
return result;
|
|
87647
88165
|
}
|
|
87648
88166
|
/**
|
|
88167
|
+
* The edits or urls map's rules with the all-tools `*` restrictions honored.
|
|
88168
|
+
* A restriction that reads as a path (edits) or URL (urls), and the catch-all
|
|
88169
|
+
* `*`, is written as a `false` entry of its own, which `buildAutoApproveValue`
|
|
88170
|
+
* places where it wins; a URL is written without its scheme and with only its host lowercased,
|
|
88171
|
+
* since VS Code matches paths case-sensitively.
|
|
88172
|
+
* Every other restriction (a command, an odd URL pattern) cannot be written
|
|
88173
|
+
* there, so each `true` entry it overlaps is withheld instead.
|
|
88174
|
+
*/
|
|
88175
|
+
function honorCopilotAllToolsRestrictions({ permission, category, logger }) {
|
|
88176
|
+
const allToolsRules = lookupOwn({
|
|
88177
|
+
record: permission,
|
|
88178
|
+
key: "*"
|
|
88179
|
+
}) ?? {};
|
|
88180
|
+
const isWritable = restatesAsCategoryRule();
|
|
88181
|
+
const restateAs = (params) => params.pattern === "*" || isWritable(params);
|
|
88182
|
+
const writable = {};
|
|
88183
|
+
const notWritable = {};
|
|
88184
|
+
for (const [pattern, action] of Object.entries(allToolsRules)) {
|
|
88185
|
+
if (action === "allow") continue;
|
|
88186
|
+
if (restateAs({
|
|
88187
|
+
category,
|
|
88188
|
+
pattern,
|
|
88189
|
+
action
|
|
88190
|
+
})) {
|
|
88191
|
+
const key = category === "webfetch" && pattern !== "*" ? stripUrlSchemeKeepingPathCase(pattern) : pattern;
|
|
88192
|
+
writable[key] = action;
|
|
88193
|
+
} else notWritable[pattern] = action;
|
|
88194
|
+
}
|
|
88195
|
+
const restated = restateAllToolsRestrictionsInCategory({
|
|
88196
|
+
permission: {
|
|
88197
|
+
["*"]: writable,
|
|
88198
|
+
[category]: lookupOwn({
|
|
88199
|
+
record: permission,
|
|
88200
|
+
key: category
|
|
88201
|
+
}) ?? {}
|
|
88202
|
+
},
|
|
88203
|
+
category,
|
|
88204
|
+
restateAs: () => true
|
|
88205
|
+
});
|
|
88206
|
+
return lookupOwn({
|
|
88207
|
+
record: honorAllToolsRestrictions({
|
|
88208
|
+
permission: {
|
|
88209
|
+
["*"]: notWritable,
|
|
88210
|
+
[category]: restated
|
|
88211
|
+
},
|
|
88212
|
+
toolLabel: COPILOT_TOOL_LABEL,
|
|
88213
|
+
logger
|
|
88214
|
+
}),
|
|
88215
|
+
key: category
|
|
88216
|
+
}) ?? {};
|
|
88217
|
+
}
|
|
88218
|
+
/**
|
|
87649
88219
|
* Render one canonical category's rules as a VS Code auto-approve map. Returns
|
|
87650
88220
|
* `undefined` when the category contributes nothing, so the key is retracted
|
|
87651
88221
|
* rather than written as an empty object.
|
|
@@ -87723,11 +88293,14 @@ var CopilotPermissions = class CopilotPermissions extends ToolPermissions {
|
|
|
87723
88293
|
const config = rulesyncPermissions.getJson();
|
|
87724
88294
|
const patch = {};
|
|
87725
88295
|
for (const [category, settingKey] of Object.entries(AUTO_APPROVE_KEYS)) {
|
|
87726
|
-
|
|
87727
|
-
if (rules === void 0) continue;
|
|
88296
|
+
if (!Object.hasOwn(config.permission, category)) continue;
|
|
87728
88297
|
patch[settingKey] = buildAutoApproveValue({
|
|
87729
88298
|
category,
|
|
87730
|
-
rules
|
|
88299
|
+
rules: category === "bash" ? bashRulesHonoringAllTools(config.permission) : honorCopilotAllToolsRestrictions({
|
|
88300
|
+
permission: config.permission,
|
|
88301
|
+
category,
|
|
88302
|
+
logger
|
|
88303
|
+
})
|
|
87731
88304
|
});
|
|
87732
88305
|
}
|
|
87733
88306
|
const existingSettings = () => parseSharedConfig({
|
|
@@ -87828,6 +88401,15 @@ const DEFAULT_PERMISSION_MODE_KEY = "defaultPermissionMode";
|
|
|
87828
88401
|
function isCopilotcliDefaultPermissionMode(value) {
|
|
87829
88402
|
return COPILOTCLI_DEFAULT_PERMISSION_MODES.some((mode) => mode === value);
|
|
87830
88403
|
}
|
|
88404
|
+
/** The given categories of a permission block, those it states. */
|
|
88405
|
+
function pickOwnCategories(permission, categories) {
|
|
88406
|
+
const picked = {};
|
|
88407
|
+
for (const category of categories) {
|
|
88408
|
+
const rules = Object.hasOwn(permission, category) ? permission[category] : void 0;
|
|
88409
|
+
if (rules !== void 0) picked[category] = rules;
|
|
88410
|
+
}
|
|
88411
|
+
return picked;
|
|
88412
|
+
}
|
|
87831
88413
|
function toUrlList(value) {
|
|
87832
88414
|
if (!Array.isArray(value)) return [];
|
|
87833
88415
|
return value.filter((entry) => typeof entry === "string");
|
|
@@ -87912,7 +88494,15 @@ var CopilotcliPermissions = class CopilotcliPermissions extends ToolPermissions
|
|
|
87912
88494
|
const filePath = (0, node_path.join)(outputRoot, paths.relativeDirPath, paths.relativeFilePath);
|
|
87913
88495
|
const existingContent = await readFileContentOrNull(filePath) ?? "{}";
|
|
87914
88496
|
const config = rulesyncPermissions.getJson();
|
|
87915
|
-
const rules =
|
|
88497
|
+
const rules = withholdAllowsShadowedByAsks({
|
|
88498
|
+
permission: honorAllToolsRestrictions({
|
|
88499
|
+
permission: pickOwnCategories(config.permission, ["*", WEBFETCH_CATEGORY$1]),
|
|
88500
|
+
toolLabel: "Copilot CLI",
|
|
88501
|
+
logger
|
|
88502
|
+
}),
|
|
88503
|
+
toolLabel: "Copilot CLI",
|
|
88504
|
+
logger
|
|
88505
|
+
})[WEBFETCH_CATEGORY$1];
|
|
87916
88506
|
const patch = {};
|
|
87917
88507
|
if (rules !== void 0) {
|
|
87918
88508
|
const { allowedUrls, deniedUrls } = splitUrlRules(rules);
|
|
@@ -88391,6 +88981,26 @@ function resolveCategoryAction({ category, toolName, rules, logger }) {
|
|
|
88391
88981
|
return catchAllAction;
|
|
88392
88982
|
}
|
|
88393
88983
|
/**
|
|
88984
|
+
* The canonical rules with the all-tools `*` restrictions applied the way
|
|
88985
|
+
* Crush can carry them. Crush has no all-tools list, so a `*` deny or ask
|
|
88986
|
+
* withholds every `allow` it covers in the other categories (`{"*": {".env":
|
|
88987
|
+
* "deny"}, "read": {"*": "allow"}}` keeps `view` out of `allowed_tools`, and
|
|
88988
|
+
* Crush prompts for it), named in one warning. `bash` keeps the
|
|
88989
|
+
* `honorAllToolsOnBash` treatment: its allow lines become `safe_commands`, and
|
|
88990
|
+
* the safe-command and blocked-command logic reports what it withholds itself.
|
|
88991
|
+
*/
|
|
88992
|
+
function honorCrushAllToolsRestrictions({ config, logger }) {
|
|
88993
|
+
const withShell = honorAllToolsOnBash(config.permission);
|
|
88994
|
+
const honored = honorAllToolsRestrictions({
|
|
88995
|
+
permission: Object.fromEntries(Object.entries(config.permission).filter(([category]) => category !== SHELL_PERMISSION_CATEGORY)),
|
|
88996
|
+
toolLabel: "Crush",
|
|
88997
|
+
logger
|
|
88998
|
+
});
|
|
88999
|
+
const permission = {};
|
|
89000
|
+
for (const [category, rules] of Object.entries(withShell)) permission[category] = category !== "bash" && Object.hasOwn(honored, category) ? honored[category] ?? rules : rules;
|
|
89001
|
+
return permission;
|
|
89002
|
+
}
|
|
89003
|
+
/**
|
|
88394
89004
|
* Convert a rulesync permissions config into Crush's two tool lists.
|
|
88395
89005
|
*/
|
|
88396
89006
|
function convertRulesyncToCrushLists({ config, logger }) {
|
|
@@ -88399,7 +89009,10 @@ function convertRulesyncToCrushLists({ config, logger }) {
|
|
|
88399
89009
|
disabled: []
|
|
88400
89010
|
};
|
|
88401
89011
|
const actionByTool = /* @__PURE__ */ new Map();
|
|
88402
|
-
for (const [category, rules] of Object.entries(
|
|
89012
|
+
for (const [category, rules] of Object.entries(honorCrushAllToolsRestrictions({
|
|
89013
|
+
config,
|
|
89014
|
+
logger
|
|
89015
|
+
}))) {
|
|
88403
89016
|
if (isPrototypePollutionKey(category)) continue;
|
|
88404
89017
|
if (category === "*") {
|
|
88405
89018
|
for (const [rawPattern, action] of Object.entries(rules)) {
|
|
@@ -88844,7 +89457,17 @@ var CursorPermissions = class CursorPermissions extends ToolPermissions {
|
|
|
88844
89457
|
function convertRulesyncToCursorPermissions(config, logger) {
|
|
88845
89458
|
const allow = [];
|
|
88846
89459
|
const deny = [];
|
|
88847
|
-
|
|
89460
|
+
const permission = withholdAllowsShadowedByAsks({
|
|
89461
|
+
permission: honorAllToolsRestrictions({
|
|
89462
|
+
permission: config.permission,
|
|
89463
|
+
toolLabel: "Cursor CLI",
|
|
89464
|
+
logger
|
|
89465
|
+
}),
|
|
89466
|
+
toolLabel: "Cursor CLI",
|
|
89467
|
+
logger,
|
|
89468
|
+
groupOf: (category) => isMcpScopedCategory(category) ? category : toCursorType(category)
|
|
89469
|
+
});
|
|
89470
|
+
for (const [category, rules] of Object.entries(permission)) {
|
|
88848
89471
|
const cursorType = toCursorType(category);
|
|
88849
89472
|
for (const [pattern, action] of Object.entries(rules)) {
|
|
88850
89473
|
const entry = buildToolPatternEntry({
|
|
@@ -90189,7 +90812,11 @@ function convertRulesyncToDevinPermissions({ config, logger }) {
|
|
|
90189
90812
|
case "deny": deny.push(entry);
|
|
90190
90813
|
}
|
|
90191
90814
|
};
|
|
90192
|
-
for (const [category, rules] of Object.entries(
|
|
90815
|
+
for (const [category, rules] of Object.entries(honorAllToolsRestrictions({
|
|
90816
|
+
permission: config.permission,
|
|
90817
|
+
toolLabel: "Devin",
|
|
90818
|
+
logger
|
|
90819
|
+
}))) {
|
|
90193
90820
|
const scope = toDevinScope(category);
|
|
90194
90821
|
if (DEVIN_BARE_ONLY_SCOPES.has(scope)) {
|
|
90195
90822
|
const action = collapseBareOnlyScopeRules({
|
|
@@ -90933,7 +91560,12 @@ function unmanagedEntries(existingPermission, key) {
|
|
|
90933
91560
|
*/
|
|
90934
91561
|
function buildGrokPermissionArrays(config, existingPermission, logger) {
|
|
90935
91562
|
const ranked = /* @__PURE__ */ new Map();
|
|
90936
|
-
for (const [category, rules] of Object.entries(
|
|
91563
|
+
for (const [category, rules] of Object.entries(honorAllToolsRestrictions({
|
|
91564
|
+
permission: config.permission,
|
|
91565
|
+
toolLabel: "Grok CLI",
|
|
91566
|
+
logger,
|
|
91567
|
+
writesAllToolsCatchAll: true
|
|
91568
|
+
}))) for (const [pattern, action] of Object.entries(rules)) {
|
|
90937
91569
|
const entry = buildGrokEntry(category, pattern);
|
|
90938
91570
|
if (entry === null) {
|
|
90939
91571
|
if (category === "*") {
|
|
@@ -90992,7 +91624,7 @@ function warnRemovedAllToolsRestrictions({ existingPermission, ranked, logger })
|
|
|
90992
91624
|
* Warn about entries that a bare `*` `deny`/`ask` makes ineffective: Grok
|
|
90993
91625
|
* evaluates by severity (`deny > ask > allow`), so a specific `allow` (and,
|
|
90994
91626
|
* under a `*` deny, a specific `ask`) never takes effect next to it. Shell
|
|
90995
|
-
* rules are already folded by `
|
|
91627
|
+
* rules are already folded by `honorAllToolsRestrictions`, so this covers the other
|
|
90996
91628
|
* tools.
|
|
90997
91629
|
*/
|
|
90998
91630
|
function warnEntriesShadowedByAllTools({ ranked, logger }) {
|
|
@@ -91749,7 +92381,12 @@ var JuniePermissions = class JuniePermissions extends ToolPermissions {
|
|
|
91749
92381
|
*/
|
|
91750
92382
|
function convertRulesyncToJunieRules({ config, logger, existingRules, overrideSecretFile, overrideRuleDefaults }) {
|
|
91751
92383
|
const ruleLists = {};
|
|
91752
|
-
|
|
92384
|
+
const permission = honorAllToolsRestrictions({
|
|
92385
|
+
permission: config.permission,
|
|
92386
|
+
toolLabel: "Junie allowlist",
|
|
92387
|
+
logger
|
|
92388
|
+
});
|
|
92389
|
+
for (const [category, patterns] of Object.entries(permission)) {
|
|
91753
92390
|
const group = lookupOwn({
|
|
91754
92391
|
record: CANONICAL_TO_JUNIE_GROUP,
|
|
91755
92392
|
key: category
|
|
@@ -91777,13 +92414,16 @@ function convertRulesyncToJunieRules({ config, logger, existingRules, overrideSe
|
|
|
91777
92414
|
if (list === void 0 && groupDefault === void 0) continue;
|
|
91778
92415
|
rules[group] = {
|
|
91779
92416
|
...groupDefault !== void 0 && { default: groupDefault },
|
|
91780
|
-
rules: list
|
|
92417
|
+
rules: list === void 0 ? [] : sortRestrictionsFirst(list)
|
|
91781
92418
|
};
|
|
91782
92419
|
}
|
|
91783
92420
|
const secretFile = overrideSecretFile ?? toRuleSet(existingRules[JUNIE_SECRET_FILE_GROUP]);
|
|
91784
92421
|
if (secretFile !== void 0) rules[JUNIE_SECRET_FILE_GROUP] = sanitizeRuleSet(secretFile);
|
|
91785
92422
|
return rules;
|
|
91786
92423
|
}
|
|
92424
|
+
function sortRestrictionsFirst(list) {
|
|
92425
|
+
return [...list.filter((rule) => rule.action !== "allow"), ...list.filter((rule) => rule.action === "allow")];
|
|
92426
|
+
}
|
|
91787
92427
|
/**
|
|
91788
92428
|
* Map a canonical action onto a valid Junie allowlist action. Junie supports
|
|
91789
92429
|
* only `allow` and `ask`; a canonical `deny` is downgraded to `ask` (the
|
|
@@ -91829,6 +92469,69 @@ function convertJunieToRulesyncPermissions({ allowlist }) {
|
|
|
91829
92469
|
readSecretFile
|
|
91830
92470
|
};
|
|
91831
92471
|
}
|
|
92472
|
+
// src/features/permissions/last-match-restate.ts
|
|
92473
|
+
/**
|
|
92474
|
+
* OpenCode (and its forks: Kilo, MiMo Code) applies the last matching rule,
|
|
92475
|
+
* and the `*` key comes first in the usual file, so a later key's allow overrides a pattern-specific `*` deny or
|
|
92476
|
+
* ask: `{"*": {".env": "deny"}, "read": {"*": "allow"}}` would read `.env`
|
|
92477
|
+
* freely. Canonically the stricter rule wins whatever its width, so each such
|
|
92478
|
+
* restriction is restated at the end of every other key that holds a looser
|
|
92479
|
+
* rule it overlaps, where it is matched after that rule. A `*` catch-all
|
|
92480
|
+
* (`{"*": {"*": "ask"}}` followed by per-tool allows) is the documented way to
|
|
92481
|
+
* set an OpenCode default, so it is left where it is.
|
|
92482
|
+
*
|
|
92483
|
+
* A restated rule must never land after an overlapping stricter one, or it
|
|
92484
|
+
* would loosen what that rule says. The tail of a key is therefore written
|
|
92485
|
+
* asks first, then denies: every restated ask, then each of the key's own
|
|
92486
|
+
* denies and each `*` deny that overlaps one of those asks (moved after them),
|
|
92487
|
+
* then the restated `*` denies. A key whose own catch-all is a deny covers
|
|
92488
|
+
* every input of a restated ask already, so such an ask is restated as a deny.
|
|
92489
|
+
*/
|
|
92490
|
+
function restateAllToolsRestrictionsLast(sharedPermission) {
|
|
92491
|
+
const allToolsRules = Object.hasOwn(sharedPermission, "*") ? sharedPermission["*"] : void 0;
|
|
92492
|
+
const restrictions = Object.entries(allToolsRules ?? {}).filter(([pattern, action]) => action !== "allow" && pattern !== "*" && !isPrototypePollutionKey(pattern));
|
|
92493
|
+
if (restrictions.length === 0) return sharedPermission;
|
|
92494
|
+
const result = {};
|
|
92495
|
+
for (const [key, rules] of Object.entries(sharedPermission)) result[key] = key === "*" ? rules : restateInKey({
|
|
92496
|
+
rules,
|
|
92497
|
+
restrictions
|
|
92498
|
+
});
|
|
92499
|
+
return result;
|
|
92500
|
+
}
|
|
92501
|
+
function globsOverlap(left, right) {
|
|
92502
|
+
return createShadowingRestrictionsTest([{
|
|
92503
|
+
pattern: left,
|
|
92504
|
+
fromAllToolsCategory: true
|
|
92505
|
+
}])(right).length > 0;
|
|
92506
|
+
}
|
|
92507
|
+
/** One key's rules with the `*` restrictions restated at its end; see the caller. */
|
|
92508
|
+
function restateInKey({ rules, restrictions }) {
|
|
92509
|
+
const own = Object.entries(rules);
|
|
92510
|
+
const ownAction = (pattern) => Object.hasOwn(rules, pattern) ? rules[pattern] : void 0;
|
|
92511
|
+
const overlapsLooserOwnRule = (pattern, action) => own.some(([ownPattern, existing]) => isStricterAction({
|
|
92512
|
+
action,
|
|
92513
|
+
existing
|
|
92514
|
+
}) && globsOverlap(pattern, ownPattern));
|
|
92515
|
+
const allToolsDenies = restrictions.filter(([, action]) => action === "deny").map(([pattern]) => pattern);
|
|
92516
|
+
let asks = restrictions.filter(([pattern, action]) => action === "ask" && overlapsLooserOwnRule(pattern, action)).map(([pattern]) => pattern);
|
|
92517
|
+
const denies = new Set(allToolsDenies.filter((pattern) => overlapsLooserOwnRule(pattern, "deny")));
|
|
92518
|
+
if (ownAction("*") === "deny") {
|
|
92519
|
+
for (const pattern of asks) denies.add(pattern);
|
|
92520
|
+
asks = [];
|
|
92521
|
+
}
|
|
92522
|
+
for (const pattern of asks) if (ownAction(pattern) === "deny") denies.add(pattern);
|
|
92523
|
+
asks = asks.filter((pattern) => ownAction(pattern) !== "deny");
|
|
92524
|
+
const overlapsAnAsk = (pattern) => asks.some((ask) => globsOverlap(ask, pattern));
|
|
92525
|
+
const ownDenies = own.filter(([pattern, action]) => action === "deny" && pattern !== "*").map(([pattern]) => pattern);
|
|
92526
|
+
for (const pattern of [...ownDenies, ...allToolsDenies]) if (overlapsAnAsk(pattern)) denies.add(pattern);
|
|
92527
|
+
if (asks.length === 0 && denies.size === 0) return rules;
|
|
92528
|
+
const tail = /* @__PURE__ */ new Set([...asks, ...denies]);
|
|
92529
|
+
const restated = {};
|
|
92530
|
+
for (const [pattern, action] of own) if (!tail.has(pattern)) restated[pattern] = action;
|
|
92531
|
+
for (const pattern of asks) restated[pattern] = "ask";
|
|
92532
|
+
for (const pattern of denies) restated[pattern] = "deny";
|
|
92533
|
+
return restated;
|
|
92534
|
+
}
|
|
91832
92535
|
// src/features/permissions/kilo-permissions.ts
|
|
91833
92536
|
const KiloPermissionSchema = zod_mini.z.union([zod_mini.z.enum([
|
|
91834
92537
|
"allow",
|
|
@@ -92044,7 +92747,7 @@ var KiloPermissions = class KiloPermissions extends ToolPermissions {
|
|
|
92044
92747
|
const rulesyncJson = rulesyncPermissions.getJson();
|
|
92045
92748
|
const kiloOverride = rulesyncJson.kilo;
|
|
92046
92749
|
const incomingPermission = {
|
|
92047
|
-
...honorAllToolsOnBash(rulesyncJson.permission),
|
|
92750
|
+
...restateAllToolsRestrictionsLast(honorAllToolsOnBash(rulesyncJson.permission)),
|
|
92048
92751
|
...kiloOverride?.permission
|
|
92049
92752
|
};
|
|
92050
92753
|
if (!global && Object.hasOwn(incomingPermission, KILO_MARKDOWN_SOURCE_KEY)) {
|
|
@@ -92249,7 +92952,12 @@ function warnAboutMistypedToolLists(section) {
|
|
|
92249
92952
|
function canonicalToKimiCodeRules({ config, logger }) {
|
|
92250
92953
|
const canonicalRules = [];
|
|
92251
92954
|
const overrideRules = config["kimi-code"]?.rules ?? [];
|
|
92252
|
-
|
|
92955
|
+
const permission = honorAllToolsRestrictions({
|
|
92956
|
+
permission: config.permission,
|
|
92957
|
+
toolLabel: "Kimi Code",
|
|
92958
|
+
logger
|
|
92959
|
+
});
|
|
92960
|
+
for (const [category, rules] of Object.entries(permission)) {
|
|
92253
92961
|
if (!(category === "mcp" || category.startsWith("mcp__") || lookupOwn({
|
|
92254
92962
|
record: CATEGORY_TO_KIMI_CODE_TOOL,
|
|
92255
92963
|
key: category
|
|
@@ -93096,7 +93804,11 @@ var KiroCapabilityPermissions = class KiroCapabilityPermissions extends ToolPerm
|
|
|
93096
93804
|
*/
|
|
93097
93805
|
function buildKiroCapabilityRules({ config, logger }) {
|
|
93098
93806
|
const buckets = /* @__PURE__ */ new Map();
|
|
93099
|
-
for (const [category, rules] of Object.entries(
|
|
93807
|
+
for (const [category, rules] of Object.entries(honorAllToolsRestrictions({
|
|
93808
|
+
permission: config.permission,
|
|
93809
|
+
toolLabel: "Kiro",
|
|
93810
|
+
logger
|
|
93811
|
+
}))) {
|
|
93100
93812
|
const capability = lookupOwn({
|
|
93101
93813
|
record: CANONICAL_TO_KIRO_CAPABILITY,
|
|
93102
93814
|
key: category
|
|
@@ -93304,7 +94016,12 @@ function fromLettacodeRule(rule) {
|
|
|
93304
94016
|
* absent from the config).
|
|
93305
94017
|
*/
|
|
93306
94018
|
function buildLettacodeRuleLists({ config, existingPermissions, logger }) {
|
|
93307
|
-
const permission =
|
|
94019
|
+
const permission = honorAllToolsRestrictions({
|
|
94020
|
+
permission: config.permission,
|
|
94021
|
+
toolLabel: "Letta Code",
|
|
94022
|
+
logger,
|
|
94023
|
+
restateAs: restatesAsCategoryRule()
|
|
94024
|
+
});
|
|
93308
94025
|
const ranked = /* @__PURE__ */ new Map();
|
|
93309
94026
|
const managedCategories = /* @__PURE__ */ new Set();
|
|
93310
94027
|
for (const [category, rules] of Object.entries(permission)) {
|
|
@@ -93724,7 +94441,7 @@ function toOpencodeSharedPermission({ permission, toolTarget, logger }) {
|
|
|
93724
94441
|
sharedPermission[key] = merged;
|
|
93725
94442
|
} else sharedPermission[key] = value;
|
|
93726
94443
|
}
|
|
93727
|
-
return sharedPermission;
|
|
94444
|
+
return restateAllToolsRestrictionsLast(sharedPermission);
|
|
93728
94445
|
}
|
|
93729
94446
|
const OpencodePermissionsConfigSchema = zod_mini.z.looseObject({
|
|
93730
94447
|
permission: zod_mini.z.optional(zod_mini.z.union([zod_mini.z.enum([
|
|
@@ -94549,7 +95266,7 @@ function listPatterns(patterns) {
|
|
|
94549
95266
|
* - `mcp__<server>__<tool>` is skipped: Pool approves MCP tools per server
|
|
94550
95267
|
* under `mcp_servers.<server>.allow`, authored as `poolAllow` in
|
|
94551
95268
|
* `.rulesync/mcp.json`. The all-tools `*` category is mirrored onto
|
|
94552
|
-
* `bash` by `
|
|
95269
|
+
* `bash` by `honorAllToolsRestrictions` and otherwise skipped.
|
|
94553
95270
|
*
|
|
94554
95271
|
* Project settings take project-relative paths and the user settings absolute
|
|
94555
95272
|
* or `~` paths, so a path of the other kind is skipped with a warning at each
|
|
@@ -94642,7 +95359,11 @@ var PoolPermissions = class PoolPermissions extends ToolPermissions {
|
|
|
94642
95359
|
* `tools: {}` / `paths: {}`.
|
|
94643
95360
|
*/
|
|
94644
95361
|
function buildPoolPermissionsPatch({ config, existing, global, logger }) {
|
|
94645
|
-
const permission =
|
|
95362
|
+
const permission = honorAllToolsRestrictions({
|
|
95363
|
+
permission: config.permission,
|
|
95364
|
+
toolLabel: "Pool",
|
|
95365
|
+
logger
|
|
95366
|
+
});
|
|
94646
95367
|
const existingTools = isRecord(existing["tools"]) ? existing[POOL_TOOLS_KEY] : void 0;
|
|
94647
95368
|
const existingPaths = isRecord(existing["paths"]) ? existing[POOL_PATHS_KEY] : void 0;
|
|
94648
95369
|
const patch = {};
|
|
@@ -95082,8 +95803,10 @@ function categoryOfRule(rule) {
|
|
|
95082
95803
|
* when Qoder has no spelling for it.
|
|
95083
95804
|
*
|
|
95084
95805
|
* - The all-tools `*` category is Qoder's bare `*` rule; a narrower pattern
|
|
95085
|
-
* under it names no single tool and is skipped
|
|
95086
|
-
* already
|
|
95806
|
+
* under it names no single tool and is skipped. `honorAllToolsRestrictions`
|
|
95807
|
+
* already carried it onto `bash` and withheld every allow it overlaps in the
|
|
95808
|
+
* other categories — a `{"*": "allow"}` included, even for a shell-only
|
|
95809
|
+
* pattern such as `git push *`.
|
|
95087
95810
|
* - An `mcp__...` category is a fully qualified MCP tool name (or a Qoder MCP
|
|
95088
95811
|
* wildcard like `mcp__github__*`) and only takes the catch-all pattern.
|
|
95089
95812
|
* - Every other category maps to its Qoder tool name; `*` is the bare tool
|
|
@@ -95135,7 +95858,13 @@ function fromQoderRule(rule) {
|
|
|
95135
95858
|
* ...). An existing entry this run writes is moved to its new list.
|
|
95136
95859
|
*/
|
|
95137
95860
|
function buildQoderRuleLists({ config, existingPermissions, logger }) {
|
|
95138
|
-
const permission =
|
|
95861
|
+
const permission = honorAllToolsRestrictions({
|
|
95862
|
+
permission: config.permission,
|
|
95863
|
+
toolLabel: "Qoder",
|
|
95864
|
+
logger,
|
|
95865
|
+
restateAs: restatesAsCategoryRule(),
|
|
95866
|
+
writesAllToolsCatchAll: true
|
|
95867
|
+
});
|
|
95139
95868
|
const ranked = /* @__PURE__ */ new Map();
|
|
95140
95869
|
const managedCategories = /* @__PURE__ */ new Set();
|
|
95141
95870
|
for (const [category, rules] of Object.entries(permission)) {
|
|
@@ -95948,7 +96677,10 @@ var QwencodePermissions = class QwencodePermissions extends ToolPermissions {
|
|
|
95948
96677
|
}
|
|
95949
96678
|
const displayPath = toPosixPath((0, node_path.join)(global ? "~" : ".", paths.relativeDirPath, paths.relativeFilePath));
|
|
95950
96679
|
const config = rulesyncPermissions.getJson();
|
|
95951
|
-
const { allow, ask, deny } = convertRulesyncToQwenPermissions(
|
|
96680
|
+
const { allow, ask, deny } = convertRulesyncToQwenPermissions({
|
|
96681
|
+
config,
|
|
96682
|
+
logger
|
|
96683
|
+
});
|
|
95952
96684
|
const managedToolNames = new Set(Object.keys(config.permission).map((category) => toQwenToolName(category)));
|
|
95953
96685
|
const existingPermissions = settings.permissions ?? {};
|
|
95954
96686
|
const preservedAllow = (existingPermissions.allow ?? []).filter((entry) => !managedToolNames.has(parseQwenPermissionEntry(entry, { logger }).toolName));
|
|
@@ -96053,11 +96785,17 @@ var QwencodePermissions = class QwencodePermissions extends ToolPermissions {
|
|
|
96053
96785
|
}
|
|
96054
96786
|
}
|
|
96055
96787
|
};
|
|
96056
|
-
function convertRulesyncToQwenPermissions(config) {
|
|
96788
|
+
function convertRulesyncToQwenPermissions({ config, logger }) {
|
|
96057
96789
|
const allow = [];
|
|
96058
96790
|
const ask = [];
|
|
96059
96791
|
const deny = [];
|
|
96060
|
-
|
|
96792
|
+
const permission = honorAllToolsRestrictions({
|
|
96793
|
+
permission: config.permission,
|
|
96794
|
+
toolLabel: "Qwen Code",
|
|
96795
|
+
logger,
|
|
96796
|
+
restateAs: restatesAsCategoryRule()
|
|
96797
|
+
});
|
|
96798
|
+
for (const [category, rules] of Object.entries(permission)) {
|
|
96061
96799
|
const qwenToolName = toQwenToolName(category);
|
|
96062
96800
|
for (const [pattern, action] of Object.entries(rules)) {
|
|
96063
96801
|
const entry = buildToolPatternEntry({
|
|
@@ -96586,7 +97324,10 @@ var ReasonixPermissions = class ReasonixPermissions extends ToolPermissions {
|
|
|
96586
97324
|
const existingContent = await readFileContentOrNull(filePath) ?? "";
|
|
96587
97325
|
const parsed = parseReasonixConfig(existingContent);
|
|
96588
97326
|
const config = rulesyncPermissions.getJson();
|
|
96589
|
-
const { allow, ask, deny } = convertRulesyncToReasonixPermissions(
|
|
97327
|
+
const { allow, ask, deny } = convertRulesyncToReasonixPermissions({
|
|
97328
|
+
config,
|
|
97329
|
+
logger
|
|
97330
|
+
});
|
|
96590
97331
|
const managedToolNames = new Set(Object.keys(config.permission).flatMap((category) => reasonixToolNamesOf(category)));
|
|
96591
97332
|
const override = config.reasonix;
|
|
96592
97333
|
const rawAllow = toStringArray$1(override?.rawAllow);
|
|
@@ -96856,11 +97597,16 @@ function setOrDeleteEntries(table, key, entries) {
|
|
|
96856
97597
|
/**
|
|
96857
97598
|
* Convert rulesync permissions config to Reasonix allow/ask/deny arrays.
|
|
96858
97599
|
*/
|
|
96859
|
-
function convertRulesyncToReasonixPermissions(config) {
|
|
97600
|
+
function convertRulesyncToReasonixPermissions({ config, logger }) {
|
|
96860
97601
|
const allow = [];
|
|
96861
97602
|
const ask = [];
|
|
96862
97603
|
const deny = [];
|
|
96863
|
-
|
|
97604
|
+
const permission = honorAllToolsRestrictions({
|
|
97605
|
+
permission: config.permission,
|
|
97606
|
+
toolLabel: "Reasonix",
|
|
97607
|
+
logger
|
|
97608
|
+
});
|
|
97609
|
+
for (const [category, rules] of Object.entries(permission)) for (const reasonixToolName of toReasonixToolNames(category)) for (const [pattern, action] of Object.entries(rules)) {
|
|
96864
97610
|
const entry = buildToolPatternEntry({
|
|
96865
97611
|
toolName: reasonixToolName,
|
|
96866
97612
|
pattern
|
|
@@ -98880,14 +99626,19 @@ async function readTaktRuntimeConfig({ outputRoot, logger }) {
|
|
|
98880
99626
|
/**
|
|
98881
99627
|
* Collapse a rulesync permissions config into Takt's single coarse mode.
|
|
98882
99628
|
*
|
|
98883
|
-
* Precedence: any `deny` ⇒ `readonly`; else an `edit`/`write` `allow`
|
|
98884
|
-
* else a `bash` `allow` ⇒ `full`; else the safe default `readonly`.
|
|
99629
|
+
* Precedence: any `deny` or `ask` ⇒ `readonly`; else an `edit`/`write` `allow`
|
|
99630
|
+
* ⇒ `edit`; else a `bash` `allow` ⇒ `full`; else the safe default `readonly`.
|
|
99631
|
+
*
|
|
99632
|
+
* An `ask` restricts like a `deny` here: Takt's coarse modes have no prompting
|
|
99633
|
+
* tier, so a mode derived from the allows beside it (`full` for `{"git *":
|
|
99634
|
+
* "allow", "git push *": "ask"}`) would auto-approve what the ask should prompt
|
|
99635
|
+
* for — the canonical order is `deny > ask > allow`.
|
|
98885
99636
|
*/
|
|
98886
99637
|
function deriveTaktPermissionMode(config) {
|
|
98887
99638
|
let hasEditAllow = false;
|
|
98888
99639
|
let hasBashAllow = false;
|
|
98889
99640
|
for (const [category, rules] of Object.entries(config.permission)) for (const action of Object.values(rules)) {
|
|
98890
|
-
if (action === "deny") return "readonly";
|
|
99641
|
+
if (action === "deny" || action === "ask") return "readonly";
|
|
98891
99642
|
if (action === "allow") {
|
|
98892
99643
|
if (category === "edit" || category === "write") hasEditAllow = true;
|
|
98893
99644
|
else if (category === "bash") hasBashAllow = true;
|
|
@@ -99170,7 +99921,12 @@ function buildMcpRules({ permission, existing, logger }) {
|
|
|
99170
99921
|
/** Split the canonical `webfetch` rules into TRAE's network allow/deny lists. */
|
|
99171
99922
|
function buildNetworkLists({ webfetchRules, logger }) {
|
|
99172
99923
|
const ranked = /* @__PURE__ */ new Map();
|
|
99173
|
-
|
|
99924
|
+
const { webfetch: rules = {} } = withholdAllowsShadowedByAsks({
|
|
99925
|
+
permission: { webfetch: webfetchRules },
|
|
99926
|
+
toolLabel: "TRAE resourceAuthorization.network",
|
|
99927
|
+
logger
|
|
99928
|
+
});
|
|
99929
|
+
for (const [pattern, action] of Object.entries(rules)) {
|
|
99174
99930
|
if (isPrototypePollutionKey(pattern)) continue;
|
|
99175
99931
|
if (pattern === "*") {
|
|
99176
99932
|
logger?.warn(`TRAE permissions: skipping the 'webfetch' rule '*' — TRAE sets the default network policy in the custom permission mode ('customProfiles.defaultCustomProfile.network.default'), not in resourceAuthorization.`);
|
|
@@ -99298,7 +100054,11 @@ var TraePermissions = class TraePermissions extends ToolPermissions {
|
|
|
99298
100054
|
fileContent: existingContent,
|
|
99299
100055
|
relativePath
|
|
99300
100056
|
});
|
|
99301
|
-
const permission =
|
|
100057
|
+
const permission = honorAllToolsRestrictions({
|
|
100058
|
+
permission: rulesyncPermissions.getJson().permission,
|
|
100059
|
+
toolLabel: "TRAE",
|
|
100060
|
+
logger
|
|
100061
|
+
});
|
|
99302
100062
|
warnUnmappedCategories({
|
|
99303
100063
|
permission,
|
|
99304
100064
|
logger
|
|
@@ -99547,7 +100307,18 @@ var VibePermissions = class VibePermissions extends ToolPermissions {
|
|
|
99547
100307
|
const filePath = (0, node_path.join)(outputRoot, paths.relativeDirPath, paths.relativeFilePath);
|
|
99548
100308
|
const existingContent = await readFileContentOrNull(filePath) ?? "";
|
|
99549
100309
|
const config = parseVibeConfig(existingContent);
|
|
99550
|
-
const permission =
|
|
100310
|
+
const permission = withholdAllowsShadowedByAsks({
|
|
100311
|
+
permission: honorAllToolsRestrictions({
|
|
100312
|
+
permission: rulesyncPermissions.getJson().permission,
|
|
100313
|
+
toolLabel: "Vibe",
|
|
100314
|
+
logger,
|
|
100315
|
+
restateAs: restatesAsCategoryRule(["deny"]),
|
|
100316
|
+
downgradeWithheldCatchAll: true
|
|
100317
|
+
}),
|
|
100318
|
+
toolLabel: "Vibe",
|
|
100319
|
+
logger,
|
|
100320
|
+
isSkippedAsk: ({ pattern }) => pattern !== "*"
|
|
100321
|
+
});
|
|
99551
100322
|
const vibeOverride = rulesyncPermissions.getJson().vibe;
|
|
99552
100323
|
const tools = toVibeToolsRecord(config.tools);
|
|
99553
100324
|
const diskShellPatterns = new Map([VIBE_SHELL_CATEGORY, ...VIBE_SHELL_ALIAS_TOOL_NAMES].map((vibeToolName) => [vibeToolName, toStringArray$1(readVibeToolConfig({
|
|
@@ -99596,6 +100367,12 @@ var VibePermissions = class VibePermissions extends ToolPermissions {
|
|
|
99596
100367
|
logger
|
|
99597
100368
|
});
|
|
99598
100369
|
const tableCategories = Object.entries(permission).filter(([category]) => category !== VIBE_SUBAGENT_CATEGORY && category !== VIBE_OUTSIDE_WORKDIR_CATEGORY);
|
|
100370
|
+
retireWithheldAllows({
|
|
100371
|
+
source: rulesyncPermissions.getJson().permission,
|
|
100372
|
+
permission,
|
|
100373
|
+
tools,
|
|
100374
|
+
resolveNames
|
|
100375
|
+
});
|
|
99599
100376
|
for (const [category, rules] of tableCategories) {
|
|
99600
100377
|
const vibeToolNames = resolveNames(category);
|
|
99601
100378
|
if (vibeToolNames === void 0) {
|
|
@@ -99980,6 +100757,49 @@ function applyCategoryRulesToTool({ vibeToolName, category, rules, tools, enable
|
|
|
99980
100757
|
tools[vibeToolName] = nextTool;
|
|
99981
100758
|
}
|
|
99982
100759
|
/**
|
|
100760
|
+
* Remove from the existing tables what the current restrictions forbid. The
|
|
100761
|
+
* per-tool pass merges into the `allowlist` already on disk and only sets
|
|
100762
|
+
* `permission` when the category states a `*` rule, so a regenerate would
|
|
100763
|
+
* otherwise keep an `allowlist` entry (an earlier generate's, or a
|
|
100764
|
+
* hand-written one) that auto-approves what a canonical ask or deny now
|
|
100765
|
+
* covers, or the `permission = "always"` an earlier config wrote for an allow
|
|
100766
|
+
* that is now withheld. Only the tables of categories the config manages are
|
|
100767
|
+
* touched, and only entries that overlap a restriction are removed. A
|
|
100768
|
+
* category's own catch-all ask is the documented default its allowlist carves
|
|
100769
|
+
* out of, so it removes nothing.
|
|
100770
|
+
*/
|
|
100771
|
+
function retireWithheldAllows({ source, permission, tools, resolveNames }) {
|
|
100772
|
+
const allToolsRestrictions = Object.entries(lookupOwn({
|
|
100773
|
+
record: source,
|
|
100774
|
+
key: "*"
|
|
100775
|
+
}) ?? {}).filter(([pattern, action]) => action === "deny" || action === "ask" && pattern !== "*");
|
|
100776
|
+
for (const [category, rules] of Object.entries(source)) {
|
|
100777
|
+
if (category === "*") continue;
|
|
100778
|
+
const honored = lookupOwn({
|
|
100779
|
+
record: permission,
|
|
100780
|
+
key: category
|
|
100781
|
+
}) ?? {};
|
|
100782
|
+
const withheld = new Set(Object.entries(rules).filter(([pattern, action]) => action === "allow" && honored[pattern] !== "allow").map(([pattern]) => pattern));
|
|
100783
|
+
const restrictions = [...Object.entries(honored).filter(([pattern, action]) => action !== "allow" && pattern !== "*"), ...allToolsRestrictions].map(([pattern]) => ({
|
|
100784
|
+
pattern,
|
|
100785
|
+
fromAllToolsCategory: false
|
|
100786
|
+
}));
|
|
100787
|
+
const globShadowed = createShadowingRestrictionsTest(restrictions);
|
|
100788
|
+
const shadowed = (pattern) => category === "webfetch" ? restrictions.some((restriction) => urlPatternsOverlap(restriction.pattern, pattern)) : globShadowed(pattern).length > 0;
|
|
100789
|
+
const retires = (pattern) => withheld.has(pattern) || restrictions.length > 0 && honored[pattern] !== "allow" && shadowed(pattern);
|
|
100790
|
+
for (const vibeToolName of resolveNames(category) ?? []) {
|
|
100791
|
+
if (!Object.hasOwn(tools, vibeToolName)) continue;
|
|
100792
|
+
const tool = readVibeToolConfig({
|
|
100793
|
+
tools,
|
|
100794
|
+
vibeToolName
|
|
100795
|
+
});
|
|
100796
|
+
for (const key of ["allow", "allowlist"]) if (tool[key] !== void 0) tool[key] = toStringArray$1(tool[key]).filter((pattern) => !retires(pattern));
|
|
100797
|
+
if (withheld.size > 0 && tool.permission === "always" && !Object.hasOwn(honored, "*")) tool.permission = "ask";
|
|
100798
|
+
tools[vibeToolName] = tool;
|
|
100799
|
+
}
|
|
100800
|
+
}
|
|
100801
|
+
}
|
|
100802
|
+
/**
|
|
99983
100803
|
* `enabled_tools` is an exclusive allowlist and therefore only ever
|
|
99984
100804
|
* rulesync-authored explicitly, through `vibe.enabled_tools`. When the
|
|
99985
100805
|
* override declares it (even empty), rulesync owns the whole list; when it
|