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.
@@ -79458,6 +79458,30 @@ function maxRangeCount(steps) {
79458
79458
  return most;
79459
79459
  }
79460
79460
  /**
79461
+ * Whether any one value matches both globs — that is, whether the two patterns
79462
+ * overlap at all. The answer is exact up to `MAX_INTERSECTION_CELLS`; a pair
79463
+ * longer than that is reported as overlapping without being compared, so a
79464
+ * caller that reads a `true` as a reason to restrict stays on the safe side and
79465
+ * one that would read it as a reason to permit must not use this. What a pair
79466
+ * costs counts the ranges a `[a-z]` class carries, not only the two lengths.
79467
+ *
79468
+ * This answers the question an adapter really has when it holds a restriction
79469
+ * and an `allow`: is there a command both of them name? Asking instead whether
79470
+ * either pattern covers the other's *text* misses the ordinary crossing pair —
79471
+ * `* --force` and `git *` cover none of each other's spellings, yet they share
79472
+ * every `git … --force` command.
79473
+ *
79474
+ * The two step lists are walked as a table rather than by backtracking, so no
79475
+ * input makes the time blow up the way a translated regex would. Only two rows
79476
+ * of that table are ever held, and the shorter pattern is the one that sizes
79477
+ * them, so the memory is linear in the shorter pattern however long the other
79478
+ * one is. Where a `[...]` class meets another `[...]` class the answer is
79479
+ * assumed to be yes, which over-reports rather than misses.
79480
+ */
79481
+ function globsIntersect(left, right) {
79482
+ return parsedGlobsIntersect(parseGlobPattern(left), parseGlobPattern(right));
79483
+ }
79484
+ /**
79461
79485
  * `globsIntersect` for two globs already parsed, optionally spending a budget
79462
79486
  * shared with the rest of the caller's run — see `createIntersectionBudget`.
79463
79487
  * Once that budget is exhausted every further pair answers `true` without being
@@ -80085,6 +80109,11 @@ function collectShellCommandRules(permission) {
80085
80109
  function widenToPrefixGlob$1(pattern) {
80086
80110
  return pattern.endsWith("*") ? pattern : `${pattern}*`;
80087
80111
  }
80112
+ function widenForOverlap(pattern) {
80113
+ if (/\{[^}]*,[^}]*\}/.test(pattern)) return "*";
80114
+ const widened = pattern.replaceAll("**/", "*").replaceAll("/**", "*");
80115
+ return widened.endsWith(" *") ? `${widened.slice(0, -2)}*` : widened;
80116
+ }
80088
80117
  /**
80089
80118
  * Build the test an adapter applies to an `allow` pattern before writing it:
80090
80119
  * which restrictions it cannot write name some of the same commands? The
@@ -80116,11 +80145,11 @@ function widenToPrefixGlob$1(pattern) {
80116
80145
  function createShadowingRestrictionsTest(restrictions, { normalizePattern = (pattern) => pattern, budget = createIntersectionBudget() } = {}) {
80117
80146
  const normalized = restrictions.map(({ pattern, fromAllToolsCategory }) => ({
80118
80147
  pattern,
80119
- glob: parseGlobPattern(fromAllToolsCategory ? pattern : normalizePattern(pattern))
80148
+ glob: parseGlobPattern(widenForOverlap(fromAllToolsCategory ? pattern : normalizePattern(pattern)))
80120
80149
  }));
80121
80150
  return (allowPattern) => {
80122
80151
  if (budget.remaining === 0) return normalized.map(({ pattern }) => pattern);
80123
- const allowGlob = parseGlobPattern(normalizePattern(allowPattern));
80152
+ const allowGlob = parseGlobPattern(widenForOverlap(normalizePattern(allowPattern)));
80124
80153
  return normalized.filter(({ pattern, glob }) => pattern === allowPattern || parsedGlobsIntersect(glob, allowGlob, budget)).map(({ pattern }) => pattern);
80125
80154
  };
80126
80155
  }
@@ -80283,6 +80312,336 @@ function honorAllToolsOnBash(permission) {
80283
80312
  bash: bashRulesHonoringAllTools(permission)
80284
80313
  };
80285
80314
  }
80315
+ // src/features/permissions/shadowed-allows.ts
80316
+ /** The canonical category whose patterns are URLs or domains. */
80317
+ const WEBFETCH_CATEGORY$2 = "webfetch";
80318
+ /**
80319
+ * A URL or domain pattern lowercased and without its scheme, so `HTTPS://Evil.example/*`
80320
+ * and `evil.example/*` are compared as the same host. Hosts are case-insensitive
80321
+ * and a scheme-less allow covers every scheme.
80322
+ */
80323
+ function normalizeUrlPattern(pattern) {
80324
+ return pattern.toLowerCase().replace(/^[a-z][a-z0-9+.-]*:\/\//, "");
80325
+ }
80326
+ /**
80327
+ * A URL pattern with its scheme stripped and only its host lowercased, for
80328
+ * writing it into a tool that matches paths case-sensitively (Copilot in VS
80329
+ * Code). A scheme spelled as a glob (a `*` scheme, `http*`, or a bare double
80330
+ * slash after a `*`) is stripped too.
80331
+ */
80332
+ function stripUrlSchemeKeepingPathCase(pattern) {
80333
+ const withoutScheme = pattern.replace(/^[a-z0-9+.*-]*:?\/\//i, "");
80334
+ const slash = withoutScheme.indexOf("/");
80335
+ return slash === -1 ? withoutScheme.toLowerCase() : `${withoutScheme.slice(0, slash).toLowerCase()}${withoutScheme.slice(slash)}`;
80336
+ }
80337
+ /** Split a lowercased, scheme-less URL or domain pattern into host, port and path. */
80338
+ function splitUrlPattern(pattern) {
80339
+ const normalized = stripUrlSchemeKeepingPathCase(pattern).toLowerCase();
80340
+ const slash = normalized.indexOf("/");
80341
+ const hostPort = slash === -1 ? normalized : normalized.slice(0, slash);
80342
+ const path = slash === -1 ? void 0 : normalized.slice(slash);
80343
+ const port = /:([0-9*]+)$/.exec(hostPort);
80344
+ return port === null ? {
80345
+ host: hostPort,
80346
+ port: void 0,
80347
+ path
80348
+ } : {
80349
+ host: hostPort.slice(0, port.index),
80350
+ port: port[1],
80351
+ path
80352
+ };
80353
+ }
80354
+ /**
80355
+ * Whether two URL or domain patterns can name one URL. Both are compared
80356
+ * lowercased and without their scheme, part by part, so a `*` in one part
80357
+ * never reaches into another (`*.github.com` does not overlap
80358
+ * `example.org/private/*`). A pathless pattern is a host, which domain-only
80359
+ * tools read as every URL on it, on any port, and on its subdomains, so a
80360
+ * missing path or port matches every path or port, and each host also stands
80361
+ * for `*.<host>`. Because a glob can also match across those parts, the
80362
+ * whole strings are compared as well, and an overlap from either counts. A
80363
+ * pattern holding whitespace names no URL.
80364
+ */
80365
+ function urlPatternsOverlap(left, right) {
80366
+ if (left === right) return true;
80367
+ if (/\s/.test(left) || /\s/.test(right)) return false;
80368
+ return urlPartsOverlap(left, right) || wholeStringsOverlap(left, right);
80369
+ }
80370
+ /**
80371
+ * The whole-string comparison a `*` restriction also gets, since a glob there
80372
+ * matches the whole URL (`*.pdf` names `https://example.com/doc.pdf`): the two
80373
+ * patterns compared as written and lowercased without a scheme, each widened
80374
+ * by `createShadowingRestrictionsTest`.
80375
+ */
80376
+ function wholeStringsOverlap(left, right) {
80377
+ return [[left, right], [normalizeUrlPattern(left), normalizeUrlPattern(right)]].some(([restriction = "", allow = ""]) => createShadowingRestrictionsTest([{
80378
+ pattern: restriction,
80379
+ fromAllToolsCategory: false
80380
+ }])(allow).length > 0);
80381
+ }
80382
+ function urlPartsOverlap(left, right) {
80383
+ const a = splitUrlPattern(left);
80384
+ const b = splitUrlPattern(right);
80385
+ const hosts = (host) => [host, `*.${host}`];
80386
+ if (!hosts(a.host).some((x) => hosts(b.host).some((y) => globsIntersect(x, y)))) return false;
80387
+ if (a.port !== void 0 && b.port !== void 0 && !globsIntersect(a.port, b.port)) return false;
80388
+ return a.path === void 0 || b.path === void 0 || globsIntersect(a.path, b.path);
80389
+ }
80390
+ /**
80391
+ * Whether any of `restrictions` overlaps an allow pattern of `category`. For
80392
+ * `webfetch` the patterns are compared as URLs (see `urlPatternsOverlap`).
80393
+ */
80394
+ function createCategoryShadowTest({ restrictions, category }) {
80395
+ if (category === WEBFETCH_CATEGORY$2) return (allowPattern) => restrictions.some(({ pattern }) => urlPatternsOverlap(pattern, allowPattern));
80396
+ const asWritten = createShadowingRestrictionsTest(restrictions);
80397
+ return (allowPattern) => asWritten(allowPattern).length > 0;
80398
+ }
80399
+ /** One allow rule left out of a tool's config, named as `<category>: <pattern>`. */
80400
+ function describeRule(category, pattern) {
80401
+ return `${category}: ${pattern}`;
80402
+ }
80403
+ /**
80404
+ * The `*` category with only its catch-all entries left, warning about the
80405
+ * pattern-specific ones dropped.
80406
+ */
80407
+ function keepAllToolsCatchAll({ rules, isCatchAll, toolLabel, logger }) {
80408
+ const kept = {};
80409
+ const dropped = [];
80410
+ for (const [pattern, action] of Object.entries(rules)) if (isCatchAll(pattern)) kept[pattern] = action;
80411
+ else dropped.push(`${pattern} (${action})`);
80412
+ 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.`);
80413
+ return kept;
80414
+ }
80415
+ /**
80416
+ * Apply the all-tools `*` category's restrictions to every other category, for
80417
+ * a tool that cannot write a pattern-specific rule spanning every tool.
80418
+ *
80419
+ * A `deny` or `ask` written under `*` covers every tool — `{"*": {".env":
80420
+ * "deny"}}` denies reading `.env` as surely as `{"read": {".env": "deny"}}`
80421
+ * does. A tool with no such rule would otherwise keep a `read: {"*": "allow"}`
80422
+ * beside it and auto-approve the very file the author denied. So:
80423
+ *
80424
+ * - `bash` gets the restrictions copied in, exactly as `honorAllToolsOnBash`
80425
+ * does, since a command list can carry them.
80426
+ * - Every other category loses each `allow` that names an input a `*`
80427
+ * restriction also names (see `createShadowingRestrictionsTest`); the tool
80428
+ * then falls back to its own prompt or default for it, the safe direction.
80429
+ * (AugmentCode instead applies its blanket all-tools fallback to a tool left
80430
+ * with no entries, since its own default would auto-run the tool.) Width
80431
+ * does not matter: a shell-only `{"*": {"git push *": "ask"}}` withholds a
80432
+ * `read: {"*": "allow"}` too, because the catch-all names every input.
80433
+ * - With `dropAllToolsPatterns`, the pattern-specific entries of `*` itself are
80434
+ * removed, for a tool that would otherwise write them as an inert literal
80435
+ * `*(<pattern>)` rule. They are honored by the withholding above.
80436
+ *
80437
+ * `restateAs` says which pattern-specific `*` restrictions the tool can write
80438
+ * as a rule of the category itself (`Read(.env)`), for a tool whose default for
80439
+ * an input with no rule would auto-approve it: such a restriction is copied
80440
+ * into each stated category it applies to (see `restatesAsCategoryRule`), so
80441
+ * the input stays restricted after its allow is withheld.
80442
+ * `downgradeWithheldCatchAll` writes a withheld catch-all `*` allow as `ask`
80443
+ * (`deny` under a catch-all `*` deny) rather than dropping it, for a tool that keeps a stale `always` otherwise.
80444
+ *
80445
+ * `writesAllToolsCatchAll` says the tool already enforces a `*` catch-all
80446
+ * (`{"*": {"*": "ask"}}`) natively over its per-tool allows, so the catch-all
80447
+ * is left out of the withholding. `isCatchAll` says which spellings the tool
80448
+ * reads as that catch-all (by default only `*`).
80449
+ *
80450
+ * Every withheld allow is named in one warning.
80451
+ */
80452
+ function honorAllToolsRestrictions({ permission, toolLabel, logger, writesAllToolsCatchAll = false, dropAllToolsPatterns = false, isCatchAll = (pattern) => pattern === "*", restateAs = () => false, downgradeWithheldCatchAll = false }) {
80453
+ const allToolsRules = Object.hasOwn(permission, "*") ? permission["*"] : void 0;
80454
+ if (allToolsRules === void 0) return permission;
80455
+ const restrictions = Object.entries(allToolsRules).filter(([pattern, action]) => action !== "allow" && !isPrototypePollutionKey(pattern) && !(writesAllToolsCatchAll && isCatchAll(pattern))).map(([pattern]) => ({
80456
+ pattern,
80457
+ fromAllToolsCategory: true
80458
+ }));
80459
+ const result = {};
80460
+ const withheld = [];
80461
+ for (const [category, rules] of Object.entries(permission)) {
80462
+ if (category === "*") {
80463
+ const kept = dropAllToolsPatterns ? keepAllToolsCatchAll({
80464
+ rules,
80465
+ isCatchAll,
80466
+ toolLabel,
80467
+ logger
80468
+ }) : rules;
80469
+ if (!dropAllToolsPatterns || Object.keys(kept).length > 0) result[category] = kept;
80470
+ continue;
80471
+ }
80472
+ if (restrictions.length === 0) {
80473
+ result[category] = rules;
80474
+ continue;
80475
+ }
80476
+ if (category === "bash") {
80477
+ const bash = bashRulesHonoringAllTools({
80478
+ ...permission,
80479
+ ["*"]: Object.fromEntries(restrictions.map(({ pattern }) => [pattern, allToolsRules[pattern] ?? "deny"]))
80480
+ });
80481
+ for (const [pattern, action] of Object.entries(rules)) if (action === "allow" && bash[pattern] !== "allow") withheld.push(describeRule(category, pattern));
80482
+ result[category] = bash;
80483
+ continue;
80484
+ }
80485
+ result[category] = honorInCategory({
80486
+ category,
80487
+ rules,
80488
+ restrictions: restrictions.map(({ pattern }) => ({
80489
+ pattern,
80490
+ action: allToolsRules[pattern] ?? "deny"
80491
+ })),
80492
+ restateAs,
80493
+ downgradeWithheldCatchAll,
80494
+ withheld
80495
+ });
80496
+ }
80497
+ 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.`);
80498
+ return result;
80499
+ }
80500
+ /** File categories whose patterns are paths. */
80501
+ const PATH_CATEGORIES = /* @__PURE__ */ new Set([
80502
+ "read",
80503
+ "edit",
80504
+ "write"
80505
+ ]);
80506
+ /**
80507
+ * The common `restateAs`: a restriction is restated under a path category when
80508
+ * it reads as a path (no whitespace, so not a command such as `git push *`),
80509
+ * and under `webfetch` when it reads as a URL or domain. `actions` limits it to
80510
+ * the actions the tool can write per pattern.
80511
+ */
80512
+ function restatesAsCategoryRule(actions = ["deny", "ask"]) {
80513
+ return ({ category, pattern, action }) => {
80514
+ if (!actions.includes(action) || pattern === "*") return false;
80515
+ if (PATH_CATEGORIES.has(category)) return !/\s/.test(pattern);
80516
+ if (category === WEBFETCH_CATEGORY$2) return /^([a-z][a-z0-9+.-]*:\/\/)?[\w*-]+(\.[\w*-]+)+(:[\w*]+)?(\/\S*)?$/i.test(pattern);
80517
+ return false;
80518
+ };
80519
+ }
80520
+ /** One non-shell category with the `*` restrictions honored; see the caller. */
80521
+ function honorInCategory({ category, rules, restrictions, restateAs, downgradeWithheldCatchAll, withheld }) {
80522
+ const shadowingRestrictions = createCategoryShadowTest({
80523
+ restrictions: restrictions.map(({ pattern }) => ({
80524
+ pattern,
80525
+ fromAllToolsCategory: true
80526
+ })),
80527
+ category
80528
+ });
80529
+ const downgradedAction = restrictions.some(({ pattern, action }) => pattern === "*" && action === "deny") ? "deny" : "ask";
80530
+ const kept = {};
80531
+ for (const [pattern, action] of Object.entries(rules)) {
80532
+ if (action === "allow" && shadowingRestrictions(pattern)) {
80533
+ withheld.push(describeRule(category, pattern));
80534
+ if (downgradeWithheldCatchAll && pattern === "*") kept[pattern] = downgradedAction;
80535
+ continue;
80536
+ }
80537
+ kept[pattern] = action;
80538
+ }
80539
+ return restateInCategory({
80540
+ category,
80541
+ rules: kept,
80542
+ restrictions,
80543
+ restateAs
80544
+ });
80545
+ }
80546
+ function restateInCategory({ category, rules, restrictions, restateAs }) {
80547
+ const restated = { ...rules };
80548
+ for (const { pattern, action } of restrictions) {
80549
+ if (isPrototypePollutionKey(pattern) || !restateAs({
80550
+ category,
80551
+ pattern,
80552
+ action
80553
+ })) continue;
80554
+ if (isStricterAction({
80555
+ action,
80556
+ existing: Object.hasOwn(restated, pattern) ? restated[pattern] : void 0
80557
+ })) restated[pattern] = action;
80558
+ }
80559
+ return restated;
80560
+ }
80561
+ /**
80562
+ * One category's rules with the pattern-specific `*` restrictions `restateAs`
80563
+ * accepts copied in as its own rules (the stricter action wins on a shared
80564
+ * spelling), for a tool that can write them there and needs no allow
80565
+ * withheld, because its own ordering already lets the copied rule win.
80566
+ */
80567
+ function restateAllToolsRestrictionsInCategory({ permission, category, restateAs }) {
80568
+ const rules = lookupOwn({
80569
+ record: permission,
80570
+ key: category
80571
+ }) ?? {};
80572
+ const allToolsRules = lookupOwn({
80573
+ record: permission,
80574
+ key: "*"
80575
+ }) ?? {};
80576
+ return restateInCategory({
80577
+ category,
80578
+ rules,
80579
+ restrictions: Object.entries(allToolsRules).filter(([, action]) => action !== "allow").map(([pattern, action]) => ({
80580
+ pattern,
80581
+ action
80582
+ })),
80583
+ restateAs
80584
+ });
80585
+ }
80586
+ /**
80587
+ * Withhold every `allow` that an `ask` the tool cannot write also covers, for a
80588
+ * tool with no ask tier on some surface.
80589
+ *
80590
+ * Such a tool prompts for whatever it does not auto-approve, so skipping the
80591
+ * `ask` alone is right — but only if no `allow` beside it auto-approves the
80592
+ * same input. The canonical order is `deny > ask > allow`, so `{"git *":
80593
+ * "allow", "git push *": "ask"}` must not leave `git *` auto-approved.
80594
+ *
80595
+ * Within each group (categories the tool folds into one surface share a group;
80596
+ * by default each category is its own), a pattern-specific `allow` an `ask`
80597
+ * overlaps is removed. A catch-all `*` `allow` is downgraded to `ask` instead,
80598
+ * so a tool that has a coarse prompting default for the whole surface (Vibe's
80599
+ * `permission = "ask"`) uses it; a tool that skips `ask` drops it either way.
80600
+ *
80601
+ * `isSkippedAsk` picks the `ask` rules the tool cannot write (by default every
80602
+ * one). Every withheld allow is named in one warning.
80603
+ */
80604
+ function withholdAllowsShadowedByAsks({ permission, toolLabel, logger, isSkippedAsk = () => true, groupOf = (category) => category }) {
80605
+ const asksByGroup = /* @__PURE__ */ new Map();
80606
+ for (const [category, rules] of Object.entries(permission)) for (const [pattern, action] of Object.entries(rules)) {
80607
+ if (action !== "ask" || isPrototypePollutionKey(pattern)) continue;
80608
+ if (!isSkippedAsk({
80609
+ category,
80610
+ pattern
80611
+ })) continue;
80612
+ const group = groupOf(category);
80613
+ asksByGroup.set(group, [...asksByGroup.get(group) ?? [], pattern]);
80614
+ }
80615
+ if (asksByGroup.size === 0) return permission;
80616
+ const result = {};
80617
+ const withheld = [];
80618
+ for (const [category, rules] of Object.entries(permission)) {
80619
+ const asks = asksByGroup.get(groupOf(category));
80620
+ if (asks === void 0) {
80621
+ result[category] = rules;
80622
+ continue;
80623
+ }
80624
+ const shadowingAsks = createCategoryShadowTest({
80625
+ restrictions: asks.map((pattern) => ({
80626
+ pattern,
80627
+ fromAllToolsCategory: false
80628
+ })),
80629
+ category
80630
+ });
80631
+ const kept = {};
80632
+ for (const [pattern, action] of Object.entries(rules)) {
80633
+ if (action !== "allow" || !shadowingAsks(pattern)) {
80634
+ kept[pattern] = action;
80635
+ continue;
80636
+ }
80637
+ withheld.push(describeRule(category, pattern));
80638
+ if (pattern === "*") kept[pattern] = "ask";
80639
+ }
80640
+ result[category] = kept;
80641
+ }
80642
+ 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.`);
80643
+ return result;
80644
+ }
80286
80645
  // src/features/permissions/tool-pattern-entry.ts
80287
80646
  /**
80288
80647
  * Parse a `Tool(pattern)` permission entry (e.g. `Bash(npm run *)`) into its
@@ -80368,7 +80727,7 @@ const MATCH_ALL_PATH_GLOBS = /* @__PURE__ */ new Set([
80368
80727
  "**/*"
80369
80728
  ]);
80370
80729
  const DIRECTORY_CONTENTS_SUFFIX = /\/\*\*(?:\/\*)?$/;
80371
- const HOME_OR_VARIABLE_PATH = /^~(?:\/|$)|^\$[A-Za-z_]|\$\{[A-Za-z_]/;
80730
+ const HOME_OR_VARIABLE_PATH = /^~(?:[A-Za-z_][\w.-]*)?(?:[/\\]|$)|^\$[A-Za-z_]|^%[A-Za-z_]\w*%|\$\{[A-Za-z_]/;
80372
80731
  const LEADING_HOME = /^~(?:\/|$)/;
80373
80732
  /**
80374
80733
  * The home directory as an Antigravity path: forward slashes, no trailing
@@ -80383,7 +80742,7 @@ function toAntigravityHomePath(homeDirectory) {
80383
80742
  * apply (rulesync#3324). Only a file the user's own home holds, such as the
80384
80743
  * global Antigravity CLI settings, may carry a machine-specific path, so the
80385
80744
  * caller passes `homeDirectory` only then. `$HOME`, `${HOME}`, `%VAR%` and
80386
- * `~user/` are left as written (the variable forms are still warned about).
80745
+ * `~user/` are left as written and still warned about.
80387
80746
  */
80388
80747
  function expandLeadingHome(target, homeDirectory) {
80389
80748
  if (homeDirectory === void 0 || !LEADING_HOME.test(target)) return target;
@@ -80625,30 +80984,84 @@ function convertRulesyncToAntigravityPermissions({ config, toAction, toolLabel,
80625
80984
  const allow = [];
80626
80985
  const ask = [];
80627
80986
  const deny = [];
80628
- for (const [category, rules] of Object.entries(honorAllToolsOnBash(config.permission))) {
80987
+ const permission = honorAllToolsRestrictions({
80988
+ permission: config.permission,
80989
+ toolLabel,
80990
+ logger
80991
+ });
80992
+ const translated = [];
80993
+ for (const [category, rules] of Object.entries(permission)) {
80629
80994
  const action = toAction(category);
80630
- for (const [pattern, permissionAction] of Object.entries(rules)) {
80995
+ for (const [pattern, decision] of Object.entries(rules)) {
80631
80996
  const entry = buildAntigravityPermissionEntry({
80632
80997
  action,
80633
80998
  category,
80634
80999
  pattern,
80635
- decision: permissionAction,
81000
+ decision,
80636
81001
  logger,
80637
81002
  toolLabel,
80638
81003
  homeDirectory
80639
81004
  });
80640
- if (entry === void 0) continue;
80641
- switch (permissionAction) {
80642
- case "allow":
80643
- allow.push(entry);
80644
- break;
80645
- case "ask":
80646
- ask.push(entry);
81005
+ translated.push({
81006
+ action,
81007
+ category,
81008
+ pattern,
81009
+ decision,
81010
+ entry
81011
+ });
81012
+ }
81013
+ }
81014
+ const skippedRestrictionsByAction = /* @__PURE__ */ new Map();
81015
+ const groupOf = ({ action, category }) => category.startsWith("mcp__") ? category : action;
81016
+ for (const { action, category, pattern, decision, entry } of translated) if (entry === void 0 && decision !== "allow") {
81017
+ const group = groupOf({
81018
+ action,
81019
+ category
81020
+ });
81021
+ skippedRestrictionsByAction.set(group, [...skippedRestrictionsByAction.get(group) ?? [], pattern]);
81022
+ }
81023
+ const allToolsRestrictions = Object.entries(lookupOwn({
81024
+ record: config.permission,
81025
+ key: "*"
81026
+ }) ?? {}).filter(([pattern, decision]) => decision !== "allow" && pattern !== "*" && !isPrototypePollutionKey(pattern)).map(([pattern]) => pattern);
81027
+ const shadowingTests = /* @__PURE__ */ new Map();
81028
+ const shadowingTestOf = (group) => {
81029
+ const cached = shadowingTests.get(group);
81030
+ if (cached !== void 0) return cached;
81031
+ const patterns = [...skippedRestrictionsByAction.get(group) ?? [], ...allToolsRestrictions];
81032
+ let test;
81033
+ if (URL_ACTIONS.has(group)) test = (allowPattern) => patterns.some((pattern) => urlPatternsOverlap(pattern, allowPattern));
81034
+ else {
81035
+ const asGlobs = createShadowingRestrictionsTest([.../* @__PURE__ */ new Set([...patterns, ...patterns.map(normalizeUrlPattern)])].map((pattern) => ({
81036
+ pattern,
81037
+ fromAllToolsCategory: false
81038
+ })));
81039
+ test = (allowPattern) => asGlobs(allowPattern).length > 0 || asGlobs(normalizeUrlPattern(allowPattern)).length > 0;
81040
+ }
81041
+ shadowingTests.set(group, test);
81042
+ return test;
81043
+ };
81044
+ const withheld = [];
81045
+ for (const { action, category, pattern, decision, entry } of translated) {
81046
+ if (entry === void 0) continue;
81047
+ switch (decision) {
81048
+ case "allow":
81049
+ if ([pattern, effectiveTargetScope(entry)].some((candidate) => shadowingTestOf(groupOf({
81050
+ action,
81051
+ category
81052
+ }))(candidate))) {
81053
+ withheld.push(`${category}: ${pattern}`);
80647
81054
  break;
80648
- case "deny": deny.push(entry);
80649
- }
81055
+ }
81056
+ allow.push(entry);
81057
+ break;
81058
+ case "ask":
81059
+ ask.push(entry);
81060
+ break;
81061
+ case "deny": deny.push(entry);
80650
81062
  }
80651
81063
  }
81064
+ 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.`);
80652
81065
  return {
80653
81066
  allow: [...new Set(allow)],
80654
81067
  ask: [...new Set(ask)],
@@ -80656,6 +81069,24 @@ function convertRulesyncToAntigravityPermissions({ config, toAction, toolLabel,
80656
81069
  };
80657
81070
  }
80658
81071
  /**
81072
+ * The widest glob an emitted entry grants, for comparing an allow against the
81073
+ * restrictions Antigravity cannot express. The emitted target can grant more
81074
+ * than the canonical pattern it came from: a path target also covers
81075
+ * everything inside it (and `.` the whole workspace), a command target is a
81076
+ * word prefix (`git push` approves `git push --force`), and a domain target
81077
+ * covers its subdomains and every URL on it. Widening only ever withholds more.
81078
+ */
81079
+ function effectiveTargetScope(entry) {
81080
+ const { toolName, pattern: target } = parseToolPatternEntry(entry);
81081
+ if (target === "*") return "*";
81082
+ if (PATH_ACTIONS.has(toolName)) {
81083
+ const path = target.replace(/\/+$/, "");
81084
+ return path === "." || path === "" ? "*" : `${path}/**`;
81085
+ }
81086
+ if (ANTIGRAVITY_COMMAND_ACTIONS.has(toolName)) return target.endsWith("*") ? target : `${target}*`;
81087
+ return target;
81088
+ }
81089
+ /**
80659
81090
  * Convert Antigravity allow/ask/deny arrays to rulesync permissions config,
80660
81091
  * shared by the CLI and IDE adapters; `toCategory` maps the target's tool or
80661
81092
  * action name back to a canonical category.
@@ -81556,15 +81987,21 @@ async function withBaseEnabledPlugins({ mergedContent, baseFilePath }) {
81556
81987
  function convertRulesyncToAugmentEntries({ config, logger }) {
81557
81988
  const entries = [];
81558
81989
  const resolvedBashRules = bashRulesHonoringAllTools(config.permission);
81990
+ const honoredPermission = honorAllToolsRestrictions({
81991
+ permission: config.permission,
81992
+ toolLabel: "AugmentCode",
81993
+ logger,
81994
+ writesAllToolsCatchAll: true
81995
+ });
81559
81996
  const permission = config.permission.bash !== void 0 || Object.keys(resolvedBashRules).length > 0 ? {
81560
- ...config.permission,
81997
+ ...honoredPermission,
81561
81998
  bash: resolvedBashRules
81562
- } : config.permission;
81999
+ } : honoredPermission;
81563
82000
  const allToolsFailClosedType = computeAllToolsFailClosedType(config.permission["*"]);
81564
82001
  const categoriesWithOwnEntries = /* @__PURE__ */ new Set();
81565
82002
  for (const [category, rules] of Object.entries(permission)) {
81566
82003
  if (category === "*") {
81567
- 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 already define their own rules are left untouched.");
82004
+ 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.");
81568
82005
  continue;
81569
82006
  }
81570
82007
  const augmentToolName = toAugmentToolName(category);
@@ -81623,9 +82060,10 @@ function computeAllToolsFailClosedType(allToolsRules) {
81623
82060
  * other managed tools: one that produced no entries of its own above must not fall back to
81624
82061
  * AugmentCode's own default just because it has no per-input matcher to narrow the all-tools
81625
82062
  * restriction onto. A category can be stated yet still emit nothing (e.g. only non-`*` allow/ask
81626
- * patterns, dropped with a warning), so this checks emitted entries rather than whether the
81627
- * category was merely present in the source config. A tool whose own rules did emit entries is
81628
- * left untouched here.
82063
+ * patterns, dropped with a warning, or only allows withheld by `honorAllToolsRestrictions`), so
82064
+ * this checks emitted entries rather than whether the category was merely present in the source
82065
+ * config. Falling back to AugmentCode's own default instead would let a read-only tool run on the
82066
+ * input the restriction names. A tool whose own rules did emit entries is left untouched here.
81629
82067
  */
81630
82068
  function synthesizeManagedToolFallbackEntries(categoriesWithOwnEntries, allToolsFailClosedType) {
81631
82069
  if (allToolsFailClosedType === void 0) return [];
@@ -84089,8 +84527,10 @@ function categoryOfRule$2(rule) {
84089
84527
  * - MCP rules take no specifier, so a scoped `mcp__<...>` category is written
84090
84528
  * for its catch-all pattern only.
84091
84529
  * - The all-tools `*` category is CodeBuddy's documented standalone `*` rule
84092
- * for its catch-all pattern. Narrower `*` patterns are shell restrictions
84093
- * and reach the `Bash` rules through `honorAllToolsOnBash`.
84530
+ * for its catch-all pattern. A narrower `*` pattern reaches the `Bash`
84531
+ * rules through `honorAllToolsRestrictions`, which also withholds every
84532
+ * allow it overlaps in the other categories — a `{"*": "allow"}` included,
84533
+ * even for a shell-only pattern such as `git push *`.
84094
84534
  */
84095
84535
  function buildCodebuddyRule({ category, pattern, action, logger }) {
84096
84536
  const catchAll = pattern === "*";
@@ -84138,7 +84578,13 @@ function parseCodebuddyRule(rule) {
84138
84578
  * manage (and every entry rulesync cannot parse).
84139
84579
  */
84140
84580
  function buildCodebuddyRuleLists({ config, existingPermissions, logger }) {
84141
- const permission = honorAllToolsOnBash(config.permission);
84581
+ const permission = honorAllToolsRestrictions({
84582
+ permission: config.permission,
84583
+ toolLabel: "CodeBuddy",
84584
+ logger,
84585
+ restateAs: restatesAsCategoryRule(),
84586
+ writesAllToolsCatchAll: true
84587
+ });
84142
84588
  const ranked = /* @__PURE__ */ new Map();
84143
84589
  const managedCategories = /* @__PURE__ */ new Set();
84144
84590
  for (const [category, rules] of Object.entries(permission)) {
@@ -85733,6 +86179,44 @@ function addCodexWebfetchRules({ rules, domains, logger }) {
85733
86179
  domains[pattern] = action;
85734
86180
  }
85735
86181
  }
86182
+ /**
86183
+ * Copy the all-tools `*` path restrictions into the `read` rules, when the
86184
+ * config states a filesystem category at all: Codex has no all-tools rule, so
86185
+ * `{"*": {".env": "deny"}, "edit": {"*": "allow"}}` would otherwise grant
86186
+ * write access to `.env`. Both a `deny` and an `ask` land under `read`, where
86187
+ * they are handled exactly like a directly written read rule (an ask becomes
86188
+ * `"deny"`, since Codex cannot prompt for a path), so a narrower write allow
86189
+ * they cover is denied as well. A catch-all `*` deny is copied too and
86190
+ * withholds every filesystem allow, so `{"*": {"*": "deny"}, "edit": {"src":
86191
+ * "allow"}}` grants nothing; a catch-all
86192
+ * ask is the documented default idiom and is left alone. Other patterns are
86193
+ * copied only when they read as a path — `git push *` is a command, not a
86194
+ * path — so the sandbox gains nothing but these restrictions.
86195
+ */
86196
+ function restateAllToolsPathRestrictions({ config, filesystemCategoryRules }) {
86197
+ if (Object.keys(filesystemCategoryRules).length === 0) return;
86198
+ if (lookupOwn({
86199
+ record: config.permission,
86200
+ key: "*"
86201
+ })?.["*"] === "deny") for (const category of [
86202
+ "read",
86203
+ "edit",
86204
+ "write"
86205
+ ]) {
86206
+ const rules = filesystemCategoryRules[category];
86207
+ if (rules === void 0) continue;
86208
+ filesystemCategoryRules[category] = Object.fromEntries(Object.entries(rules).filter(([, action]) => action !== "allow"));
86209
+ }
86210
+ const isPath = restatesAsCategoryRule(["deny", "ask"]);
86211
+ filesystemCategoryRules.read = restateAllToolsRestrictionsInCategory({
86212
+ permission: {
86213
+ ...config.permission,
86214
+ read: filesystemCategoryRules.read ?? {}
86215
+ },
86216
+ category: "read",
86217
+ restateAs: (params) => params.pattern === "*" ? params.action === "deny" : isPath(params)
86218
+ });
86219
+ }
85736
86220
  function convertRulesyncToCodexProfile({ config, logger }) {
85737
86221
  const filesystem = { [CODEX_MINIMAL_KEY]: "read" };
85738
86222
  const workspaceRootFilesystem = {};
@@ -85744,8 +86228,24 @@ function convertRulesyncToCodexProfile({ config, logger }) {
85744
86228
  continue;
85745
86229
  }
85746
86230
  if (toolName === "webfetch") {
86231
+ const allToolsRules = lookupOwn({
86232
+ record: config.permission,
86233
+ key: "*"
86234
+ });
86235
+ const { webfetch: webfetchRules = {} } = withholdAllowsShadowedByAsks({
86236
+ permission: { webfetch: honorAllToolsRestrictions({
86237
+ permission: allToolsRules === void 0 ? { webfetch: rules } : {
86238
+ ["*"]: allToolsRules,
86239
+ webfetch: rules
86240
+ },
86241
+ toolLabel: "Codex CLI network domains",
86242
+ logger
86243
+ }).webfetch ?? {} },
86244
+ toolLabel: "Codex CLI network domains",
86245
+ logger
86246
+ });
85747
86247
  addCodexWebfetchRules({
85748
- rules,
86248
+ rules: webfetchRules,
85749
86249
  domains,
85750
86250
  logger
85751
86251
  });
@@ -85754,6 +86254,10 @@ function convertRulesyncToCodexProfile({ config, logger }) {
85754
86254
  if (toolName === "bash") continue;
85755
86255
  logger?.warn(`Codex CLI permission profiles support only read/edit/write/webfetch categories (bash goes to .codex/rules/rulesync.rules). Skipping: ${toolName}`);
85756
86256
  }
86257
+ restateAllToolsPathRestrictions({
86258
+ config,
86259
+ filesystemCategoryRules
86260
+ });
85757
86261
  addCodexFilesystemRules({
85758
86262
  categoryRules: filesystemCategoryRules,
85759
86263
  filesystem,
@@ -86497,8 +87001,10 @@ const PADDED_SHELL_WILDCARD_REASON = "a pattern narrower than the bare 'Shell' (
86497
87001
  * server or tool). A pattern on an MCP category is still written as the
86498
87002
  * `(specifier)` here; `writableCommandcodeRule` decides what to do with it,
86499
87003
  * because Command Code ignores it. The all-tools `*` category is only
86500
- * written for its catch-all pattern; narrower `*` patterns are shell
86501
- * restrictions and reach the `Shell` entries through `honorAllToolsOnBash`.
87004
+ * written for its catch-all pattern; a narrower `*` pattern reaches the `Shell`
87005
+ * entries through `honorAllToolsRestrictions`, which also withholds every allow
87006
+ * it overlaps in the other categories — a `{"*": "allow"}` included, even for a
87007
+ * shell-only pattern such as `git push *`.
86502
87008
  */
86503
87009
  function buildCommandcodeRule(category, pattern) {
86504
87010
  const catchAll = pattern === "*" || pattern === "";
@@ -86792,7 +87298,13 @@ function rankCommandcodeRule({ ranked, rule, action, logger }) {
86792
87298
  * rewritten by `writableCommandcodeRule`.
86793
87299
  */
86794
87300
  function buildCommandcodeRuleLists({ config, existingPermissions, logger }) {
86795
- const permission = honorAllToolsOnBash(config.permission);
87301
+ const permission = honorAllToolsRestrictions({
87302
+ permission: config.permission,
87303
+ toolLabel: "Command Code",
87304
+ logger,
87305
+ restateAs: restatesAsCategoryRule(),
87306
+ writesAllToolsCatchAll: true
87307
+ });
86796
87308
  const ranked = /* @__PURE__ */ new Map();
86797
87309
  const managedCategories = /* @__PURE__ */ new Set();
86798
87310
  for (const [category, rules] of Object.entries(permission)) {
@@ -87252,7 +87764,13 @@ function convertRulesyncToContinuePermissions({ config, logger }) {
87252
87764
  allow: []
87253
87765
  };
87254
87766
  const actionByEntry = /* @__PURE__ */ new Map();
87255
- for (const [category, rules] of Object.entries(honorAllToolsOnBash(config.permission))) {
87767
+ for (const [category, rules] of Object.entries(honorAllToolsRestrictions({
87768
+ permission: config.permission,
87769
+ toolLabel: "Continue",
87770
+ logger,
87771
+ writesAllToolsCatchAll: true,
87772
+ isCatchAll: (pattern) => normalizeCatchAllPattern$1(pattern) === "*"
87773
+ }))) {
87256
87774
  if (isPrototypePollutionKey(category)) continue;
87257
87775
  const toolName = category === "*" ? "*" : toContinueToolName(category);
87258
87776
  for (const [rawPattern, action] of Object.entries(rules)) {
@@ -87624,6 +88142,58 @@ function asAutoApproveMap(value) {
87624
88142
  return result;
87625
88143
  }
87626
88144
  /**
88145
+ * The edits or urls map's rules with the all-tools `*` restrictions honored.
88146
+ * A restriction that reads as a path (edits) or URL (urls), and the catch-all
88147
+ * `*`, is written as a `false` entry of its own, which `buildAutoApproveValue`
88148
+ * places where it wins; a URL is written without its scheme and with only its host lowercased,
88149
+ * since VS Code matches paths case-sensitively.
88150
+ * Every other restriction (a command, an odd URL pattern) cannot be written
88151
+ * there, so each `true` entry it overlaps is withheld instead.
88152
+ */
88153
+ function honorCopilotAllToolsRestrictions({ permission, category, logger }) {
88154
+ const allToolsRules = lookupOwn({
88155
+ record: permission,
88156
+ key: "*"
88157
+ }) ?? {};
88158
+ const isWritable = restatesAsCategoryRule();
88159
+ const restateAs = (params) => params.pattern === "*" || isWritable(params);
88160
+ const writable = {};
88161
+ const notWritable = {};
88162
+ for (const [pattern, action] of Object.entries(allToolsRules)) {
88163
+ if (action === "allow") continue;
88164
+ if (restateAs({
88165
+ category,
88166
+ pattern,
88167
+ action
88168
+ })) {
88169
+ const key = category === "webfetch" && pattern !== "*" ? stripUrlSchemeKeepingPathCase(pattern) : pattern;
88170
+ writable[key] = action;
88171
+ } else notWritable[pattern] = action;
88172
+ }
88173
+ const restated = restateAllToolsRestrictionsInCategory({
88174
+ permission: {
88175
+ ["*"]: writable,
88176
+ [category]: lookupOwn({
88177
+ record: permission,
88178
+ key: category
88179
+ }) ?? {}
88180
+ },
88181
+ category,
88182
+ restateAs: () => true
88183
+ });
88184
+ return lookupOwn({
88185
+ record: honorAllToolsRestrictions({
88186
+ permission: {
88187
+ ["*"]: notWritable,
88188
+ [category]: restated
88189
+ },
88190
+ toolLabel: COPILOT_TOOL_LABEL,
88191
+ logger
88192
+ }),
88193
+ key: category
88194
+ }) ?? {};
88195
+ }
88196
+ /**
87627
88197
  * Render one canonical category's rules as a VS Code auto-approve map. Returns
87628
88198
  * `undefined` when the category contributes nothing, so the key is retracted
87629
88199
  * rather than written as an empty object.
@@ -87701,11 +88271,14 @@ var CopilotPermissions = class CopilotPermissions extends ToolPermissions {
87701
88271
  const config = rulesyncPermissions.getJson();
87702
88272
  const patch = {};
87703
88273
  for (const [category, settingKey] of Object.entries(AUTO_APPROVE_KEYS)) {
87704
- const rules = config.permission[category];
87705
- if (rules === void 0) continue;
88274
+ if (!Object.hasOwn(config.permission, category)) continue;
87706
88275
  patch[settingKey] = buildAutoApproveValue({
87707
88276
  category,
87708
- rules
88277
+ rules: category === "bash" ? bashRulesHonoringAllTools(config.permission) : honorCopilotAllToolsRestrictions({
88278
+ permission: config.permission,
88279
+ category,
88280
+ logger
88281
+ })
87709
88282
  });
87710
88283
  }
87711
88284
  const existingSettings = () => parseSharedConfig({
@@ -87806,6 +88379,15 @@ const DEFAULT_PERMISSION_MODE_KEY = "defaultPermissionMode";
87806
88379
  function isCopilotcliDefaultPermissionMode(value) {
87807
88380
  return COPILOTCLI_DEFAULT_PERMISSION_MODES.some((mode) => mode === value);
87808
88381
  }
88382
+ /** The given categories of a permission block, those it states. */
88383
+ function pickOwnCategories(permission, categories) {
88384
+ const picked = {};
88385
+ for (const category of categories) {
88386
+ const rules = Object.hasOwn(permission, category) ? permission[category] : void 0;
88387
+ if (rules !== void 0) picked[category] = rules;
88388
+ }
88389
+ return picked;
88390
+ }
87809
88391
  function toUrlList(value) {
87810
88392
  if (!Array.isArray(value)) return [];
87811
88393
  return value.filter((entry) => typeof entry === "string");
@@ -87890,7 +88472,15 @@ var CopilotcliPermissions = class CopilotcliPermissions extends ToolPermissions
87890
88472
  const filePath = join(outputRoot, paths.relativeDirPath, paths.relativeFilePath);
87891
88473
  const existingContent = await readFileContentOrNull(filePath) ?? "{}";
87892
88474
  const config = rulesyncPermissions.getJson();
87893
- const rules = config.permission[WEBFETCH_CATEGORY$1];
88475
+ const rules = withholdAllowsShadowedByAsks({
88476
+ permission: honorAllToolsRestrictions({
88477
+ permission: pickOwnCategories(config.permission, ["*", WEBFETCH_CATEGORY$1]),
88478
+ toolLabel: "Copilot CLI",
88479
+ logger
88480
+ }),
88481
+ toolLabel: "Copilot CLI",
88482
+ logger
88483
+ })[WEBFETCH_CATEGORY$1];
87894
88484
  const patch = {};
87895
88485
  if (rules !== void 0) {
87896
88486
  const { allowedUrls, deniedUrls } = splitUrlRules(rules);
@@ -88369,6 +88959,26 @@ function resolveCategoryAction({ category, toolName, rules, logger }) {
88369
88959
  return catchAllAction;
88370
88960
  }
88371
88961
  /**
88962
+ * The canonical rules with the all-tools `*` restrictions applied the way
88963
+ * Crush can carry them. Crush has no all-tools list, so a `*` deny or ask
88964
+ * withholds every `allow` it covers in the other categories (`{"*": {".env":
88965
+ * "deny"}, "read": {"*": "allow"}}` keeps `view` out of `allowed_tools`, and
88966
+ * Crush prompts for it), named in one warning. `bash` keeps the
88967
+ * `honorAllToolsOnBash` treatment: its allow lines become `safe_commands`, and
88968
+ * the safe-command and blocked-command logic reports what it withholds itself.
88969
+ */
88970
+ function honorCrushAllToolsRestrictions({ config, logger }) {
88971
+ const withShell = honorAllToolsOnBash(config.permission);
88972
+ const honored = honorAllToolsRestrictions({
88973
+ permission: Object.fromEntries(Object.entries(config.permission).filter(([category]) => category !== SHELL_PERMISSION_CATEGORY)),
88974
+ toolLabel: "Crush",
88975
+ logger
88976
+ });
88977
+ const permission = {};
88978
+ for (const [category, rules] of Object.entries(withShell)) permission[category] = category !== "bash" && Object.hasOwn(honored, category) ? honored[category] ?? rules : rules;
88979
+ return permission;
88980
+ }
88981
+ /**
88372
88982
  * Convert a rulesync permissions config into Crush's two tool lists.
88373
88983
  */
88374
88984
  function convertRulesyncToCrushLists({ config, logger }) {
@@ -88377,7 +88987,10 @@ function convertRulesyncToCrushLists({ config, logger }) {
88377
88987
  disabled: []
88378
88988
  };
88379
88989
  const actionByTool = /* @__PURE__ */ new Map();
88380
- for (const [category, rules] of Object.entries(honorAllToolsOnBash(config.permission))) {
88990
+ for (const [category, rules] of Object.entries(honorCrushAllToolsRestrictions({
88991
+ config,
88992
+ logger
88993
+ }))) {
88381
88994
  if (isPrototypePollutionKey(category)) continue;
88382
88995
  if (category === "*") {
88383
88996
  for (const [rawPattern, action] of Object.entries(rules)) {
@@ -88822,7 +89435,17 @@ var CursorPermissions = class CursorPermissions extends ToolPermissions {
88822
89435
  function convertRulesyncToCursorPermissions(config, logger) {
88823
89436
  const allow = [];
88824
89437
  const deny = [];
88825
- for (const [category, rules] of Object.entries(honorAllToolsOnBash(config.permission))) {
89438
+ const permission = withholdAllowsShadowedByAsks({
89439
+ permission: honorAllToolsRestrictions({
89440
+ permission: config.permission,
89441
+ toolLabel: "Cursor CLI",
89442
+ logger
89443
+ }),
89444
+ toolLabel: "Cursor CLI",
89445
+ logger,
89446
+ groupOf: (category) => isMcpScopedCategory(category) ? category : toCursorType(category)
89447
+ });
89448
+ for (const [category, rules] of Object.entries(permission)) {
88826
89449
  const cursorType = toCursorType(category);
88827
89450
  for (const [pattern, action] of Object.entries(rules)) {
88828
89451
  const entry = buildToolPatternEntry({
@@ -90167,7 +90790,11 @@ function convertRulesyncToDevinPermissions({ config, logger }) {
90167
90790
  case "deny": deny.push(entry);
90168
90791
  }
90169
90792
  };
90170
- for (const [category, rules] of Object.entries(honorAllToolsOnBash(config.permission))) {
90793
+ for (const [category, rules] of Object.entries(honorAllToolsRestrictions({
90794
+ permission: config.permission,
90795
+ toolLabel: "Devin",
90796
+ logger
90797
+ }))) {
90171
90798
  const scope = toDevinScope(category);
90172
90799
  if (DEVIN_BARE_ONLY_SCOPES.has(scope)) {
90173
90800
  const action = collapseBareOnlyScopeRules({
@@ -90911,7 +91538,12 @@ function unmanagedEntries(existingPermission, key) {
90911
91538
  */
90912
91539
  function buildGrokPermissionArrays(config, existingPermission, logger) {
90913
91540
  const ranked = /* @__PURE__ */ new Map();
90914
- for (const [category, rules] of Object.entries(honorAllToolsOnBash(config.permission))) for (const [pattern, action] of Object.entries(rules)) {
91541
+ for (const [category, rules] of Object.entries(honorAllToolsRestrictions({
91542
+ permission: config.permission,
91543
+ toolLabel: "Grok CLI",
91544
+ logger,
91545
+ writesAllToolsCatchAll: true
91546
+ }))) for (const [pattern, action] of Object.entries(rules)) {
90915
91547
  const entry = buildGrokEntry(category, pattern);
90916
91548
  if (entry === null) {
90917
91549
  if (category === "*") {
@@ -90970,7 +91602,7 @@ function warnRemovedAllToolsRestrictions({ existingPermission, ranked, logger })
90970
91602
  * Warn about entries that a bare `*` `deny`/`ask` makes ineffective: Grok
90971
91603
  * evaluates by severity (`deny > ask > allow`), so a specific `allow` (and,
90972
91604
  * under a `*` deny, a specific `ask`) never takes effect next to it. Shell
90973
- * rules are already folded by `honorAllToolsOnBash`, so this covers the other
91605
+ * rules are already folded by `honorAllToolsRestrictions`, so this covers the other
90974
91606
  * tools.
90975
91607
  */
90976
91608
  function warnEntriesShadowedByAllTools({ ranked, logger }) {
@@ -91727,7 +92359,12 @@ var JuniePermissions = class JuniePermissions extends ToolPermissions {
91727
92359
  */
91728
92360
  function convertRulesyncToJunieRules({ config, logger, existingRules, overrideSecretFile, overrideRuleDefaults }) {
91729
92361
  const ruleLists = {};
91730
- for (const [category, patterns] of Object.entries(honorAllToolsOnBash(config.permission))) {
92362
+ const permission = honorAllToolsRestrictions({
92363
+ permission: config.permission,
92364
+ toolLabel: "Junie allowlist",
92365
+ logger
92366
+ });
92367
+ for (const [category, patterns] of Object.entries(permission)) {
91731
92368
  const group = lookupOwn({
91732
92369
  record: CANONICAL_TO_JUNIE_GROUP,
91733
92370
  key: category
@@ -91755,13 +92392,16 @@ function convertRulesyncToJunieRules({ config, logger, existingRules, overrideSe
91755
92392
  if (list === void 0 && groupDefault === void 0) continue;
91756
92393
  rules[group] = {
91757
92394
  ...groupDefault !== void 0 && { default: groupDefault },
91758
- rules: list ?? []
92395
+ rules: list === void 0 ? [] : sortRestrictionsFirst(list)
91759
92396
  };
91760
92397
  }
91761
92398
  const secretFile = overrideSecretFile ?? toRuleSet(existingRules[JUNIE_SECRET_FILE_GROUP]);
91762
92399
  if (secretFile !== void 0) rules[JUNIE_SECRET_FILE_GROUP] = sanitizeRuleSet(secretFile);
91763
92400
  return rules;
91764
92401
  }
92402
+ function sortRestrictionsFirst(list) {
92403
+ return [...list.filter((rule) => rule.action !== "allow"), ...list.filter((rule) => rule.action === "allow")];
92404
+ }
91765
92405
  /**
91766
92406
  * Map a canonical action onto a valid Junie allowlist action. Junie supports
91767
92407
  * only `allow` and `ask`; a canonical `deny` is downgraded to `ask` (the
@@ -91807,6 +92447,69 @@ function convertJunieToRulesyncPermissions({ allowlist }) {
91807
92447
  readSecretFile
91808
92448
  };
91809
92449
  }
92450
+ // src/features/permissions/last-match-restate.ts
92451
+ /**
92452
+ * OpenCode (and its forks: Kilo, MiMo Code) applies the last matching rule,
92453
+ * and the `*` key comes first in the usual file, so a later key's allow overrides a pattern-specific `*` deny or
92454
+ * ask: `{"*": {".env": "deny"}, "read": {"*": "allow"}}` would read `.env`
92455
+ * freely. Canonically the stricter rule wins whatever its width, so each such
92456
+ * restriction is restated at the end of every other key that holds a looser
92457
+ * rule it overlaps, where it is matched after that rule. A `*` catch-all
92458
+ * (`{"*": {"*": "ask"}}` followed by per-tool allows) is the documented way to
92459
+ * set an OpenCode default, so it is left where it is.
92460
+ *
92461
+ * A restated rule must never land after an overlapping stricter one, or it
92462
+ * would loosen what that rule says. The tail of a key is therefore written
92463
+ * asks first, then denies: every restated ask, then each of the key's own
92464
+ * denies and each `*` deny that overlaps one of those asks (moved after them),
92465
+ * then the restated `*` denies. A key whose own catch-all is a deny covers
92466
+ * every input of a restated ask already, so such an ask is restated as a deny.
92467
+ */
92468
+ function restateAllToolsRestrictionsLast(sharedPermission) {
92469
+ const allToolsRules = Object.hasOwn(sharedPermission, "*") ? sharedPermission["*"] : void 0;
92470
+ const restrictions = Object.entries(allToolsRules ?? {}).filter(([pattern, action]) => action !== "allow" && pattern !== "*" && !isPrototypePollutionKey(pattern));
92471
+ if (restrictions.length === 0) return sharedPermission;
92472
+ const result = {};
92473
+ for (const [key, rules] of Object.entries(sharedPermission)) result[key] = key === "*" ? rules : restateInKey({
92474
+ rules,
92475
+ restrictions
92476
+ });
92477
+ return result;
92478
+ }
92479
+ function globsOverlap(left, right) {
92480
+ return createShadowingRestrictionsTest([{
92481
+ pattern: left,
92482
+ fromAllToolsCategory: true
92483
+ }])(right).length > 0;
92484
+ }
92485
+ /** One key's rules with the `*` restrictions restated at its end; see the caller. */
92486
+ function restateInKey({ rules, restrictions }) {
92487
+ const own = Object.entries(rules);
92488
+ const ownAction = (pattern) => Object.hasOwn(rules, pattern) ? rules[pattern] : void 0;
92489
+ const overlapsLooserOwnRule = (pattern, action) => own.some(([ownPattern, existing]) => isStricterAction({
92490
+ action,
92491
+ existing
92492
+ }) && globsOverlap(pattern, ownPattern));
92493
+ const allToolsDenies = restrictions.filter(([, action]) => action === "deny").map(([pattern]) => pattern);
92494
+ let asks = restrictions.filter(([pattern, action]) => action === "ask" && overlapsLooserOwnRule(pattern, action)).map(([pattern]) => pattern);
92495
+ const denies = new Set(allToolsDenies.filter((pattern) => overlapsLooserOwnRule(pattern, "deny")));
92496
+ if (ownAction("*") === "deny") {
92497
+ for (const pattern of asks) denies.add(pattern);
92498
+ asks = [];
92499
+ }
92500
+ for (const pattern of asks) if (ownAction(pattern) === "deny") denies.add(pattern);
92501
+ asks = asks.filter((pattern) => ownAction(pattern) !== "deny");
92502
+ const overlapsAnAsk = (pattern) => asks.some((ask) => globsOverlap(ask, pattern));
92503
+ const ownDenies = own.filter(([pattern, action]) => action === "deny" && pattern !== "*").map(([pattern]) => pattern);
92504
+ for (const pattern of [...ownDenies, ...allToolsDenies]) if (overlapsAnAsk(pattern)) denies.add(pattern);
92505
+ if (asks.length === 0 && denies.size === 0) return rules;
92506
+ const tail = /* @__PURE__ */ new Set([...asks, ...denies]);
92507
+ const restated = {};
92508
+ for (const [pattern, action] of own) if (!tail.has(pattern)) restated[pattern] = action;
92509
+ for (const pattern of asks) restated[pattern] = "ask";
92510
+ for (const pattern of denies) restated[pattern] = "deny";
92511
+ return restated;
92512
+ }
91810
92513
  // src/features/permissions/kilo-permissions.ts
91811
92514
  const KiloPermissionSchema = z.union([z.enum([
91812
92515
  "allow",
@@ -92022,7 +92725,7 @@ var KiloPermissions = class KiloPermissions extends ToolPermissions {
92022
92725
  const rulesyncJson = rulesyncPermissions.getJson();
92023
92726
  const kiloOverride = rulesyncJson.kilo;
92024
92727
  const incomingPermission = {
92025
- ...honorAllToolsOnBash(rulesyncJson.permission),
92728
+ ...restateAllToolsRestrictionsLast(honorAllToolsOnBash(rulesyncJson.permission)),
92026
92729
  ...kiloOverride?.permission
92027
92730
  };
92028
92731
  if (!global && Object.hasOwn(incomingPermission, KILO_MARKDOWN_SOURCE_KEY)) {
@@ -92227,7 +92930,12 @@ function warnAboutMistypedToolLists(section) {
92227
92930
  function canonicalToKimiCodeRules({ config, logger }) {
92228
92931
  const canonicalRules = [];
92229
92932
  const overrideRules = config["kimi-code"]?.rules ?? [];
92230
- for (const [category, rules] of Object.entries(config.permission)) {
92933
+ const permission = honorAllToolsRestrictions({
92934
+ permission: config.permission,
92935
+ toolLabel: "Kimi Code",
92936
+ logger
92937
+ });
92938
+ for (const [category, rules] of Object.entries(permission)) {
92231
92939
  if (!(category === "mcp" || category.startsWith("mcp__") || lookupOwn({
92232
92940
  record: CATEGORY_TO_KIMI_CODE_TOOL,
92233
92941
  key: category
@@ -93074,7 +93782,11 @@ var KiroCapabilityPermissions = class KiroCapabilityPermissions extends ToolPerm
93074
93782
  */
93075
93783
  function buildKiroCapabilityRules({ config, logger }) {
93076
93784
  const buckets = /* @__PURE__ */ new Map();
93077
- for (const [category, rules] of Object.entries(honorAllToolsOnBash(config.permission))) {
93785
+ for (const [category, rules] of Object.entries(honorAllToolsRestrictions({
93786
+ permission: config.permission,
93787
+ toolLabel: "Kiro",
93788
+ logger
93789
+ }))) {
93078
93790
  const capability = lookupOwn({
93079
93791
  record: CANONICAL_TO_KIRO_CAPABILITY,
93080
93792
  key: category
@@ -93282,7 +93994,12 @@ function fromLettacodeRule(rule) {
93282
93994
  * absent from the config).
93283
93995
  */
93284
93996
  function buildLettacodeRuleLists({ config, existingPermissions, logger }) {
93285
- const permission = honorAllToolsOnBash(config.permission);
93997
+ const permission = honorAllToolsRestrictions({
93998
+ permission: config.permission,
93999
+ toolLabel: "Letta Code",
94000
+ logger,
94001
+ restateAs: restatesAsCategoryRule()
94002
+ });
93286
94003
  const ranked = /* @__PURE__ */ new Map();
93287
94004
  const managedCategories = /* @__PURE__ */ new Set();
93288
94005
  for (const [category, rules] of Object.entries(permission)) {
@@ -93702,7 +94419,7 @@ function toOpencodeSharedPermission({ permission, toolTarget, logger }) {
93702
94419
  sharedPermission[key] = merged;
93703
94420
  } else sharedPermission[key] = value;
93704
94421
  }
93705
- return sharedPermission;
94422
+ return restateAllToolsRestrictionsLast(sharedPermission);
93706
94423
  }
93707
94424
  const OpencodePermissionsConfigSchema = z.looseObject({
93708
94425
  permission: z.optional(z.union([z.enum([
@@ -94527,7 +95244,7 @@ function listPatterns(patterns) {
94527
95244
  * - `mcp__<server>__<tool>` is skipped: Pool approves MCP tools per server
94528
95245
  * under `mcp_servers.<server>.allow`, authored as `poolAllow` in
94529
95246
  * `.rulesync/mcp.json`. The all-tools `*` category is mirrored onto
94530
- * `bash` by `honorAllToolsOnBash` and otherwise skipped.
95247
+ * `bash` by `honorAllToolsRestrictions` and otherwise skipped.
94531
95248
  *
94532
95249
  * Project settings take project-relative paths and the user settings absolute
94533
95250
  * or `~` paths, so a path of the other kind is skipped with a warning at each
@@ -94620,7 +95337,11 @@ var PoolPermissions = class PoolPermissions extends ToolPermissions {
94620
95337
  * `tools: {}` / `paths: {}`.
94621
95338
  */
94622
95339
  function buildPoolPermissionsPatch({ config, existing, global, logger }) {
94623
- const permission = honorAllToolsOnBash(config.permission);
95340
+ const permission = honorAllToolsRestrictions({
95341
+ permission: config.permission,
95342
+ toolLabel: "Pool",
95343
+ logger
95344
+ });
94624
95345
  const existingTools = isRecord(existing["tools"]) ? existing[POOL_TOOLS_KEY] : void 0;
94625
95346
  const existingPaths = isRecord(existing["paths"]) ? existing[POOL_PATHS_KEY] : void 0;
94626
95347
  const patch = {};
@@ -95060,8 +95781,10 @@ function categoryOfRule(rule) {
95060
95781
  * when Qoder has no spelling for it.
95061
95782
  *
95062
95783
  * - The all-tools `*` category is Qoder's bare `*` rule; a narrower pattern
95063
- * under it names no single tool and is skipped (its shell restrictions
95064
- * already reached `bash` through `honorAllToolsOnBash`).
95784
+ * under it names no single tool and is skipped. `honorAllToolsRestrictions`
95785
+ * already carried it onto `bash` and withheld every allow it overlaps in the
95786
+ * other categories — a `{"*": "allow"}` included, even for a shell-only
95787
+ * pattern such as `git push *`.
95065
95788
  * - An `mcp__...` category is a fully qualified MCP tool name (or a Qoder MCP
95066
95789
  * wildcard like `mcp__github__*`) and only takes the catch-all pattern.
95067
95790
  * - Every other category maps to its Qoder tool name; `*` is the bare tool
@@ -95113,7 +95836,13 @@ function fromQoderRule(rule) {
95113
95836
  * ...). An existing entry this run writes is moved to its new list.
95114
95837
  */
95115
95838
  function buildQoderRuleLists({ config, existingPermissions, logger }) {
95116
- const permission = honorAllToolsOnBash(config.permission);
95839
+ const permission = honorAllToolsRestrictions({
95840
+ permission: config.permission,
95841
+ toolLabel: "Qoder",
95842
+ logger,
95843
+ restateAs: restatesAsCategoryRule(),
95844
+ writesAllToolsCatchAll: true
95845
+ });
95117
95846
  const ranked = /* @__PURE__ */ new Map();
95118
95847
  const managedCategories = /* @__PURE__ */ new Set();
95119
95848
  for (const [category, rules] of Object.entries(permission)) {
@@ -95926,7 +96655,10 @@ var QwencodePermissions = class QwencodePermissions extends ToolPermissions {
95926
96655
  }
95927
96656
  const displayPath = toPosixPath(join(global ? "~" : ".", paths.relativeDirPath, paths.relativeFilePath));
95928
96657
  const config = rulesyncPermissions.getJson();
95929
- const { allow, ask, deny } = convertRulesyncToQwenPermissions(config);
96658
+ const { allow, ask, deny } = convertRulesyncToQwenPermissions({
96659
+ config,
96660
+ logger
96661
+ });
95930
96662
  const managedToolNames = new Set(Object.keys(config.permission).map((category) => toQwenToolName(category)));
95931
96663
  const existingPermissions = settings.permissions ?? {};
95932
96664
  const preservedAllow = (existingPermissions.allow ?? []).filter((entry) => !managedToolNames.has(parseQwenPermissionEntry(entry, { logger }).toolName));
@@ -96031,11 +96763,17 @@ var QwencodePermissions = class QwencodePermissions extends ToolPermissions {
96031
96763
  }
96032
96764
  }
96033
96765
  };
96034
- function convertRulesyncToQwenPermissions(config) {
96766
+ function convertRulesyncToQwenPermissions({ config, logger }) {
96035
96767
  const allow = [];
96036
96768
  const ask = [];
96037
96769
  const deny = [];
96038
- for (const [category, rules] of Object.entries(config.permission)) {
96770
+ const permission = honorAllToolsRestrictions({
96771
+ permission: config.permission,
96772
+ toolLabel: "Qwen Code",
96773
+ logger,
96774
+ restateAs: restatesAsCategoryRule()
96775
+ });
96776
+ for (const [category, rules] of Object.entries(permission)) {
96039
96777
  const qwenToolName = toQwenToolName(category);
96040
96778
  for (const [pattern, action] of Object.entries(rules)) {
96041
96779
  const entry = buildToolPatternEntry({
@@ -96564,7 +97302,10 @@ var ReasonixPermissions = class ReasonixPermissions extends ToolPermissions {
96564
97302
  const existingContent = await readFileContentOrNull(filePath) ?? "";
96565
97303
  const parsed = parseReasonixConfig(existingContent);
96566
97304
  const config = rulesyncPermissions.getJson();
96567
- const { allow, ask, deny } = convertRulesyncToReasonixPermissions(config);
97305
+ const { allow, ask, deny } = convertRulesyncToReasonixPermissions({
97306
+ config,
97307
+ logger
97308
+ });
96568
97309
  const managedToolNames = new Set(Object.keys(config.permission).flatMap((category) => reasonixToolNamesOf(category)));
96569
97310
  const override = config.reasonix;
96570
97311
  const rawAllow = toStringArray$1(override?.rawAllow);
@@ -96834,11 +97575,16 @@ function setOrDeleteEntries(table, key, entries) {
96834
97575
  /**
96835
97576
  * Convert rulesync permissions config to Reasonix allow/ask/deny arrays.
96836
97577
  */
96837
- function convertRulesyncToReasonixPermissions(config) {
97578
+ function convertRulesyncToReasonixPermissions({ config, logger }) {
96838
97579
  const allow = [];
96839
97580
  const ask = [];
96840
97581
  const deny = [];
96841
- for (const [category, rules] of Object.entries(config.permission)) for (const reasonixToolName of toReasonixToolNames(category)) for (const [pattern, action] of Object.entries(rules)) {
97582
+ const permission = honorAllToolsRestrictions({
97583
+ permission: config.permission,
97584
+ toolLabel: "Reasonix",
97585
+ logger
97586
+ });
97587
+ for (const [category, rules] of Object.entries(permission)) for (const reasonixToolName of toReasonixToolNames(category)) for (const [pattern, action] of Object.entries(rules)) {
96842
97588
  const entry = buildToolPatternEntry({
96843
97589
  toolName: reasonixToolName,
96844
97590
  pattern
@@ -98858,14 +99604,19 @@ async function readTaktRuntimeConfig({ outputRoot, logger }) {
98858
99604
  /**
98859
99605
  * Collapse a rulesync permissions config into Takt's single coarse mode.
98860
99606
  *
98861
- * Precedence: any `deny` ⇒ `readonly`; else an `edit`/`write` `allow` ⇒ `edit`;
98862
- * else a `bash` `allow` ⇒ `full`; else the safe default `readonly`.
99607
+ * Precedence: any `deny` or `ask` ⇒ `readonly`; else an `edit`/`write` `allow`
99608
+ * ⇒ `edit`; else a `bash` `allow` ⇒ `full`; else the safe default `readonly`.
99609
+ *
99610
+ * An `ask` restricts like a `deny` here: Takt's coarse modes have no prompting
99611
+ * tier, so a mode derived from the allows beside it (`full` for `{"git *":
99612
+ * "allow", "git push *": "ask"}`) would auto-approve what the ask should prompt
99613
+ * for — the canonical order is `deny > ask > allow`.
98863
99614
  */
98864
99615
  function deriveTaktPermissionMode(config) {
98865
99616
  let hasEditAllow = false;
98866
99617
  let hasBashAllow = false;
98867
99618
  for (const [category, rules] of Object.entries(config.permission)) for (const action of Object.values(rules)) {
98868
- if (action === "deny") return "readonly";
99619
+ if (action === "deny" || action === "ask") return "readonly";
98869
99620
  if (action === "allow") {
98870
99621
  if (category === "edit" || category === "write") hasEditAllow = true;
98871
99622
  else if (category === "bash") hasBashAllow = true;
@@ -99148,7 +99899,12 @@ function buildMcpRules({ permission, existing, logger }) {
99148
99899
  /** Split the canonical `webfetch` rules into TRAE's network allow/deny lists. */
99149
99900
  function buildNetworkLists({ webfetchRules, logger }) {
99150
99901
  const ranked = /* @__PURE__ */ new Map();
99151
- for (const [pattern, action] of Object.entries(webfetchRules)) {
99902
+ const { webfetch: rules = {} } = withholdAllowsShadowedByAsks({
99903
+ permission: { webfetch: webfetchRules },
99904
+ toolLabel: "TRAE resourceAuthorization.network",
99905
+ logger
99906
+ });
99907
+ for (const [pattern, action] of Object.entries(rules)) {
99152
99908
  if (isPrototypePollutionKey(pattern)) continue;
99153
99909
  if (pattern === "*") {
99154
99910
  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.`);
@@ -99276,7 +100032,11 @@ var TraePermissions = class TraePermissions extends ToolPermissions {
99276
100032
  fileContent: existingContent,
99277
100033
  relativePath
99278
100034
  });
99279
- const permission = honorAllToolsOnBash(rulesyncPermissions.getJson().permission);
100035
+ const permission = honorAllToolsRestrictions({
100036
+ permission: rulesyncPermissions.getJson().permission,
100037
+ toolLabel: "TRAE",
100038
+ logger
100039
+ });
99280
100040
  warnUnmappedCategories({
99281
100041
  permission,
99282
100042
  logger
@@ -99525,7 +100285,18 @@ var VibePermissions = class VibePermissions extends ToolPermissions {
99525
100285
  const filePath = join(outputRoot, paths.relativeDirPath, paths.relativeFilePath);
99526
100286
  const existingContent = await readFileContentOrNull(filePath) ?? "";
99527
100287
  const config = parseVibeConfig(existingContent);
99528
- const permission = honorAllToolsOnBash(rulesyncPermissions.getJson().permission);
100288
+ const permission = withholdAllowsShadowedByAsks({
100289
+ permission: honorAllToolsRestrictions({
100290
+ permission: rulesyncPermissions.getJson().permission,
100291
+ toolLabel: "Vibe",
100292
+ logger,
100293
+ restateAs: restatesAsCategoryRule(["deny"]),
100294
+ downgradeWithheldCatchAll: true
100295
+ }),
100296
+ toolLabel: "Vibe",
100297
+ logger,
100298
+ isSkippedAsk: ({ pattern }) => pattern !== "*"
100299
+ });
99529
100300
  const vibeOverride = rulesyncPermissions.getJson().vibe;
99530
100301
  const tools = toVibeToolsRecord(config.tools);
99531
100302
  const diskShellPatterns = new Map([VIBE_SHELL_CATEGORY, ...VIBE_SHELL_ALIAS_TOOL_NAMES].map((vibeToolName) => [vibeToolName, toStringArray$1(readVibeToolConfig({
@@ -99574,6 +100345,12 @@ var VibePermissions = class VibePermissions extends ToolPermissions {
99574
100345
  logger
99575
100346
  });
99576
100347
  const tableCategories = Object.entries(permission).filter(([category]) => category !== VIBE_SUBAGENT_CATEGORY && category !== VIBE_OUTSIDE_WORKDIR_CATEGORY);
100348
+ retireWithheldAllows({
100349
+ source: rulesyncPermissions.getJson().permission,
100350
+ permission,
100351
+ tools,
100352
+ resolveNames
100353
+ });
99577
100354
  for (const [category, rules] of tableCategories) {
99578
100355
  const vibeToolNames = resolveNames(category);
99579
100356
  if (vibeToolNames === void 0) {
@@ -99958,6 +100735,49 @@ function applyCategoryRulesToTool({ vibeToolName, category, rules, tools, enable
99958
100735
  tools[vibeToolName] = nextTool;
99959
100736
  }
99960
100737
  /**
100738
+ * Remove from the existing tables what the current restrictions forbid. The
100739
+ * per-tool pass merges into the `allowlist` already on disk and only sets
100740
+ * `permission` when the category states a `*` rule, so a regenerate would
100741
+ * otherwise keep an `allowlist` entry (an earlier generate's, or a
100742
+ * hand-written one) that auto-approves what a canonical ask or deny now
100743
+ * covers, or the `permission = "always"` an earlier config wrote for an allow
100744
+ * that is now withheld. Only the tables of categories the config manages are
100745
+ * touched, and only entries that overlap a restriction are removed. A
100746
+ * category's own catch-all ask is the documented default its allowlist carves
100747
+ * out of, so it removes nothing.
100748
+ */
100749
+ function retireWithheldAllows({ source, permission, tools, resolveNames }) {
100750
+ const allToolsRestrictions = Object.entries(lookupOwn({
100751
+ record: source,
100752
+ key: "*"
100753
+ }) ?? {}).filter(([pattern, action]) => action === "deny" || action === "ask" && pattern !== "*");
100754
+ for (const [category, rules] of Object.entries(source)) {
100755
+ if (category === "*") continue;
100756
+ const honored = lookupOwn({
100757
+ record: permission,
100758
+ key: category
100759
+ }) ?? {};
100760
+ const withheld = new Set(Object.entries(rules).filter(([pattern, action]) => action === "allow" && honored[pattern] !== "allow").map(([pattern]) => pattern));
100761
+ const restrictions = [...Object.entries(honored).filter(([pattern, action]) => action !== "allow" && pattern !== "*"), ...allToolsRestrictions].map(([pattern]) => ({
100762
+ pattern,
100763
+ fromAllToolsCategory: false
100764
+ }));
100765
+ const globShadowed = createShadowingRestrictionsTest(restrictions);
100766
+ const shadowed = (pattern) => category === "webfetch" ? restrictions.some((restriction) => urlPatternsOverlap(restriction.pattern, pattern)) : globShadowed(pattern).length > 0;
100767
+ const retires = (pattern) => withheld.has(pattern) || restrictions.length > 0 && honored[pattern] !== "allow" && shadowed(pattern);
100768
+ for (const vibeToolName of resolveNames(category) ?? []) {
100769
+ if (!Object.hasOwn(tools, vibeToolName)) continue;
100770
+ const tool = readVibeToolConfig({
100771
+ tools,
100772
+ vibeToolName
100773
+ });
100774
+ for (const key of ["allow", "allowlist"]) if (tool[key] !== void 0) tool[key] = toStringArray$1(tool[key]).filter((pattern) => !retires(pattern));
100775
+ if (withheld.size > 0 && tool.permission === "always" && !Object.hasOwn(honored, "*")) tool.permission = "ask";
100776
+ tools[vibeToolName] = tool;
100777
+ }
100778
+ }
100779
+ }
100780
+ /**
99961
100781
  * `enabled_tools` is an exclusive allowlist and therefore only ever
99962
100782
  * rulesync-authored explicitly, through `vibe.enabled_tools`. When the
99963
100783
  * override declares it (even empty), rulesync owns the whole list; when it
@@ -105110,4 +105930,4 @@ const CHECKS_IMPORT_STRATEGY = {
105110
105930
  };
105111
105931
  export { RulesyncRule as $, RULESYNC_RULES_RELATIVE_DIR_PATH as $n, getFileSizeAndExecutableBit as $t, CODEBUDDY_LOCAL_RULE_FILE_NAME as A, ToolTargetSchema as An, fallbackLogger as At, CLAUDECODE_LOCAL_RULE_FILE_NAME as B, RULESYNC_CONFIG_RELATIVE_FILE_PATH as Bn, assertDirectoryIfExists as Bt, LETTACODE_DIR as C, toPosixPath as Cn, SourceEntrySchema as Ct, COMMANDCODE_DIR as D, ALL_TOOL_TARGETS as Dn, ConsoleLogger as Dt, FACTORYDROID_SETTINGS_LOCAL_FILE_NAME as E, mapWithConcurrency as En, findControlCharacter as Et, sweepRefusalReason as F, FEATURE_SOURCE_TREE_ENTRIES as Fn, CLIError as Ft, toInstructionBudgetFile as G, RULESYNC_IGNORE_RELATIVE_FILE_PATH as Gn, assertWritablePathInsideRoot as Gt, CLAUDECODE_SETTINGS_LOCAL_FILE_NAME as H, RULESYNC_CURATED_RULES_RELATIVE_DIR_PATH as Hn, assertNoSymlinkBelowRoot as Ht, CODEXCLI_BASH_RULES_FILE_NAME as I, MAX_FILE_SIZE as In, ErrorCodes as It, getLocalSkillDirNames as J, RULESYNC_MCP_SCHEMA_URL as Jn, directoryExists as Jt, classifyRemoteName as K, RULESYNC_LOCAL_CONFIG_RELATIVE_FILE_PATH as Kn, checkPathTraversal as Kt, CODEXCLI_DIR as L, RULESYNC_AIIGNORE_RELATIVE_FILE_PATH as Ln, parseJsonc as Lt, AUGMENTCODE_SETTINGS_LOCAL_FILE_NAME as M, ALL_FEATURES_WITH_WILDCARD as Mn, withFallbackLoggerTarget as Mt, caseFoldIdentity as N, DEPRECATED_FEATURE_REPLACEMENTS as Nn, resetRunWarningState as Nt, COMMANDCODE_SETTINGS_LOCAL_FILE_NAME as O, ALL_TOOL_TARGETS_WITH_WILDCARD as On, JsonLogger as Ot, groupSpellingsByCaseFoldedIdentity as P, CURATED_RULES_FEATURE_SUBDIR as Pn, withWarnOnceScope as Pt, RulesyncSkillFrontmatterSchema as Q, RULESYNC_RELATIVE_DIR_PATH as Qn, findFilesByGlobs as Qt, CLAUDECODE_AGENT_MEMORY_LOCAL_DIR_NAME as R, RULESYNC_CHECKS_RELATIVE_DIR_PATH as Rn, PathOutsideRootError as Rt, QWENCODE_LOCAL_RULE_FILE_NAME as S, splitPathSegments as Sn, GITIGNORE_DESTINATION_KEY as St, FACTORYDROID_DIR as T, writeFileContent as Tn, getSourceTransport as Tt, CLAUDECODE_SKILLS_DIR_PATH as U, RULESYNC_CURATED_SKILLS_RELATIVE_DIR_PATH as Un, assertPathResolvesInsideRoot as Ut, CLAUDECODE_MEMORIES_DIR_NAME as V, RULESYNC_CONFIG_SCHEMA_URL as Vn, assertLandingOutsideVcsMetadata as Vt, findProjectInstructionBudgetFindings as W, RULESYNC_HOOKS_RELATIVE_FILE_PATH as Wn, assertTreeContainsNoSymlinks as Wt, RulesyncSubagentFrontmatterSchema as X, RULESYNC_PERMISSIONS_RELATIVE_FILE_PATH as Xn, fileExists as Xt, RulesyncSubagent as Y, RULESYNC_NPM_SOURCES_LOCK_RELATIVE_FILE_PATH as Yn, ensureDir as Yt, RulesyncSkill as Z, RULESYNC_PERMISSIONS_SCHEMA_URL as Zn, fileExistsStrict as Zt, SkillsProcessor as _, removeFileWithoutFollowingSymlinks as _n, mergeInputRootConfigs as _t, convertFromTool as a, listDirectoryEntryNames as an, formatMegabytes as ar, getRulesyncSourceCandidates as at, REASONIX_LOCAL_RULE_FILE_NAME as b, resolvedRelativePath as bn, CONFLICTING_TARGET_PAIRS as bt, ELLIPSIS_WIDTH as c, normalizePosixDirPath as cn, hasEnclosingMarkOutsideKeycap as cr, RulesyncCommandFrontmatterSchema as ct, McpProcessor as d, readFileContent as dn, stripControlCharactersKeepingLineFeeds as dr, stringifyFrontmatter as dt, getHomeDirectory as en, RULESYNC_SKILLS_RELATIVE_DIR_PATH as er, RulesyncRuleFrontmatterSchema as et, IgnoreProcessor as f, readFileContentOrNull as fn, stripControlCharactersKeepingLineFeedsAndTabs as fr, loadYaml as ft, SubagentsProcessor as g, removeFileStrict as gn, ConfigResolver as gt, RulesProcessor as h, removeFile as hn, SKILL_FILE_NAME as ht, inspectInputRoots as i, isSymlink as in, RULESYNC_XDG_CONFIG_HOME_DEFAULT_DIR_NAME as ir, RulesyncHooks as it, AUGMENTCODE_DIR as j, ALL_FEATURES as jn, warnOnConflictingFlags as jt, CODEBUDDY_DIR as k, PACKAGING_TOOL_TARGETS as kn, WarningCollectingLogger as kt, displayWidthOf as l, pathEscapesRoot as ln, quoteForLog as lr, RulesyncCheck as lt, ChecksProcessor as m, removeDirectoryStrict as mn, SHARED_USER_MANAGED_CONFIG_PATHS as mt, formatSourceLoadFailure as n, isFileSystemError as nn, RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH as nr, RulesyncMcp as nt, getProcessorRegistryEntry as o, listFilePathsRecursively as on, formatError as or, resolveRulesyncSourceWritePath as ot, HooksProcessor as p, removeDirectory as pn, stripHiddenCharacters as pr, isRecord as pt, hasWindowsFoldableName as q, RULESYNC_MCP_RELATIVE_FILE_PATH as qn, createTempDirectory as qt, generate as r, isRootDirPath as rn, RULESYNC_USER_CONFIG_DIR_NAME as rr, RulesyncIgnore as rt, parseCommaSeparatedList as s, listSubdirectoryNames as sn, truncateText as sr, RulesyncCommand as st, importFromTool as t, isFileNotFoundError as tn, RULESYNC_SOURCES_LOCK_RELATIVE_FILE_PATH as tr, RulesyncPermissions as tt, shortenToWidth as u, posixRelativePathEscapesRoot as un, stripControlCharacters as ur, RulesyncCheckFrontmatterSchema as ut, CRUSH_LOCAL_RULE_FILE_NAME as v, removeTempDirectory as vn, parseConfigFileContent as vt, LETTACODE_SETTINGS_LOCAL_FILE_NAME as w, writeFileBuffer as wn, assertTargetsFeaturesExclusive as wt, QWENCODE_DIR as x, runWithDirectoryRollback as xn, ConfigFileSchema as xt, CommandsProcessor as y, resolvePath as yn, resolveEffectiveInputRoots as yt, CLAUDECODE_DIR as z, RULESYNC_COMMANDS_RELATIVE_DIR_PATH as zn, applyFileMode as zt };
105112
105932
 
105113
- //# sourceMappingURL=import-Cu5o6uKO.js.map
105933
+ //# sourceMappingURL=import-UXidZnLu.js.map