rulesync 43.7.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 +183 -163
- package/dist/cli/index.js +181 -161
- package/dist/cli/index.js.map +1 -1
- package/dist/{import-CfxyzbvB.cjs → import-B111LEQv.cjs} +2091 -236
- package/dist/{import-tr3jHcG2.js → import-UXidZnLu.js} +2071 -234
- package/dist/{import-tr3jHcG2.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
|
@@ -1793,28 +1793,6 @@ function splitAbsolutePath(absolutePath) {
|
|
|
1793
1793
|
};
|
|
1794
1794
|
}
|
|
1795
1795
|
/**
|
|
1796
|
-
* Whether writing `targetPath` would land outside `rootPath` once every link on
|
|
1797
|
-
* the way there is resolved. Both sides are taken to where a write to them
|
|
1798
|
-
* would land (see {@link writeLandingPath}), so a root that does not fully
|
|
1799
|
-
* exist yet is judged the same way as the target below it.
|
|
1800
|
-
*
|
|
1801
|
-
* A link that stays inside the root passes. That is what sets this apart from
|
|
1802
|
-
* the stricter {@link assertWritablePathInsideRoot} the sweep paths use: a
|
|
1803
|
-
* dotfiles checkout linked from inside the home directory is a common shape for
|
|
1804
|
-
* a global write target, and refusing it would refuse `--global` outright.
|
|
1805
|
-
*
|
|
1806
|
-
* A link chain that cycles is reported as an escape: the write could not get
|
|
1807
|
-
* through it, and refusing it is the answer that never writes somewhere
|
|
1808
|
-
* unexpected.
|
|
1809
|
-
*/
|
|
1810
|
-
async function writablePathEscapesRoot({ rootPath, targetPath }) {
|
|
1811
|
-
const relativeLanding = await relativeWriteLanding({
|
|
1812
|
-
rootPath,
|
|
1813
|
-
targetPath
|
|
1814
|
-
});
|
|
1815
|
-
return relativeLanding === null || pathEscapesRoot(relativeLanding);
|
|
1816
|
-
}
|
|
1817
|
-
/**
|
|
1818
1796
|
* Where a write to `targetPath` lands relative to where a write to `rootPath`
|
|
1819
1797
|
* lands, both taken through {@link writeLandingPath}: `""` when the two land on
|
|
1820
1798
|
* the same directory, and `null` when either side's links form a cycle. Errors
|
|
@@ -1827,6 +1805,59 @@ async function relativeWriteLanding({ rootPath, targetPath }) {
|
|
|
1827
1805
|
return relative(rootLanding, targetLanding);
|
|
1828
1806
|
}
|
|
1829
1807
|
/**
|
|
1808
|
+
* Directory names that hold version-control metadata. Bytes landing in one of
|
|
1809
|
+
* them change how the VCS behaves rather than what it tracks: `.git/config`
|
|
1810
|
+
* can set `core.fsmonitor`, `.git/hooks/*` run on the next commit.
|
|
1811
|
+
*/
|
|
1812
|
+
const VCS_METADATA_DIR_NAMES = /* @__PURE__ */ new Set([
|
|
1813
|
+
".git",
|
|
1814
|
+
".hg",
|
|
1815
|
+
".svn",
|
|
1816
|
+
".jj"
|
|
1817
|
+
]);
|
|
1818
|
+
function hasVcsMetadataSegment(path) {
|
|
1819
|
+
return splitPathSegments(path).some((segment) => {
|
|
1820
|
+
const folded = segment.replace(/:.*$/, "").replace(/[. ]+$/, "").toLowerCase();
|
|
1821
|
+
return VCS_METADATA_DIR_NAMES.has(folded) || /^(git|hg|svn|jj)~\d+$/.test(folded);
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
/**
|
|
1825
|
+
* Whether a link on the way to `targetPath` carries it into version-control
|
|
1826
|
+
* metadata (`.git/` and its siblings) that its spelling does not name.
|
|
1827
|
+
*
|
|
1828
|
+
* {@link writablePathEscapesRoot} lets a link that stays inside the root
|
|
1829
|
+
* through, but a checked-out repository can commit `CLAUDE.md -> .git/config`:
|
|
1830
|
+
* the landing is inside the root, yet a write there hands the repository author
|
|
1831
|
+
* the operator's next `git` command. `git clone` never transfers `.git/`, so a
|
|
1832
|
+
* path spelled into it is never something the repository chose; only a write
|
|
1833
|
+
* that lands exactly where it is spelled may touch it.
|
|
1834
|
+
*
|
|
1835
|
+
* `relativeLanding` is {@link relativeWriteLanding}'s answer for the same pair,
|
|
1836
|
+
* passed in so a caller that already has it does not resolve the links twice.
|
|
1837
|
+
*/
|
|
1838
|
+
function landingEntersVcsMetadata({ rootPath, targetPath, relativeLanding }) {
|
|
1839
|
+
return hasVcsMetadataSegment(relativeLanding) && relativeLanding !== relative(resolve(rootPath), resolve(targetPath));
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Refuse a write target that a symbolic link carries into version-control
|
|
1843
|
+
* metadata (see {@link landingEntersVcsMetadata}). Meant for writes of remote
|
|
1844
|
+
* bytes, next to {@link assertPathResolvesInsideRoot}: an in-root link (a
|
|
1845
|
+
* skill directory linked to a shared one) stays allowed, but not one that
|
|
1846
|
+
* hands the bytes to `.git/config` or `.git/hooks/`.
|
|
1847
|
+
*/
|
|
1848
|
+
async function assertLandingOutsideVcsMetadata({ rootPath, targetPath }) {
|
|
1849
|
+
const relativeLanding = await relativeWriteLanding({
|
|
1850
|
+
rootPath,
|
|
1851
|
+
targetPath
|
|
1852
|
+
});
|
|
1853
|
+
if (relativeLanding === null) throw new PathOutsideRootError(`Refusing to write through a link cycle: ${targetPath}.`);
|
|
1854
|
+
if (landingEntersVcsMetadata({
|
|
1855
|
+
rootPath,
|
|
1856
|
+
targetPath,
|
|
1857
|
+
relativeLanding
|
|
1858
|
+
})) throw new PathOutsideRootError(`Refusing to write ${targetPath}: a symbolic link leads it into version-control metadata.`);
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1830
1861
|
* How many trailing segments `filePath` and `identity` have in common.
|
|
1831
1862
|
*
|
|
1832
1863
|
* A path that walked through no link at all shares all of its own segments with
|
|
@@ -5430,7 +5461,8 @@ const QWENCODE_HOOK_EVENTS = [
|
|
|
5430
5461
|
"todoCreated",
|
|
5431
5462
|
"todoCompleted",
|
|
5432
5463
|
"messageDisplay",
|
|
5433
|
-
"sessionDelete"
|
|
5464
|
+
"sessionDelete",
|
|
5465
|
+
"fileChanged"
|
|
5434
5466
|
];
|
|
5435
5467
|
const CANONICAL_TO_KIMI_CODE_EVENT_NAMES = {
|
|
5436
5468
|
sessionStart: "SessionStart",
|
|
@@ -6764,6 +6796,7 @@ const CANONICAL_TO_JUNIE_EVENT_NAMES = {
|
|
|
6764
6796
|
sessionStart: "SessionStart",
|
|
6765
6797
|
beforeSubmitPrompt: "UserPromptSubmit",
|
|
6766
6798
|
preToolUse: "PreToolUse",
|
|
6799
|
+
postToolUse: "PostToolUse",
|
|
6767
6800
|
stop: "Stop",
|
|
6768
6801
|
stopFailure: "StopFailure",
|
|
6769
6802
|
permissionRequest: "PermissionRequest",
|
|
@@ -6772,11 +6805,12 @@ const CANONICAL_TO_JUNIE_EVENT_NAMES = {
|
|
|
6772
6805
|
/**
|
|
6773
6806
|
* Hook events supported by JetBrains Junie CLI.
|
|
6774
6807
|
*
|
|
6775
|
-
* Junie CLI exposes
|
|
6808
|
+
* Junie CLI exposes eight lifecycle events under the `"hooks"` key of
|
|
6776
6809
|
* `~/.junie/config.json`: `SessionStart`, `UserPromptSubmit`, `PreToolUse`,
|
|
6777
|
-
* `Stop`, `StopFailure`, `PermissionRequest`, and `SessionEnd`.
|
|
6778
|
-
* to `SessionStart` (source), `PreToolUse`
|
|
6779
|
-
* type), `PermissionRequest` (tool name), and
|
|
6810
|
+
* `PostToolUse`, `Stop`, `StopFailure`, `PermissionRequest`, and `SessionEnd`.
|
|
6811
|
+
* Matchers apply to `SessionStart` (source), `PreToolUse` and `PostToolUse`
|
|
6812
|
+
* (tool name), `StopFailure` (error type), `PermissionRequest` (tool name), and
|
|
6813
|
+
* `SessionEnd` (reason);
|
|
6780
6814
|
* `UserPromptSubmit` and `Stop` are matcher-less and always run. Only
|
|
6781
6815
|
* `type: "command"` hooks are supported. Project-local hooks are ignored for
|
|
6782
6816
|
* safety.
|
|
@@ -6955,7 +6989,8 @@ const CANONICAL_TO_QWENCODE_EVENT_NAMES = {
|
|
|
6955
6989
|
todoCreated: "TodoCreated",
|
|
6956
6990
|
todoCompleted: "TodoCompleted",
|
|
6957
6991
|
messageDisplay: "MessageDisplay",
|
|
6958
|
-
sessionDelete: "SessionDelete"
|
|
6992
|
+
sessionDelete: "SessionDelete",
|
|
6993
|
+
fileChanged: "FileChanged"
|
|
6959
6994
|
};
|
|
6960
6995
|
/**
|
|
6961
6996
|
* Map Qwen Code PascalCase event names to canonical camelCase.
|
|
@@ -9210,7 +9245,8 @@ const AntigravityCliPermissionsOverrideSchema = z.looseObject({
|
|
|
9210
9245
|
* The same override also carries the two plugin-consumption keys Auggie reads
|
|
9211
9246
|
* from `settings.json`: `recommendedMarketplaces` (`"owner/repo"` marketplaces
|
|
9212
9247
|
* a workspace prompts its contributors to install; honored only in the
|
|
9213
|
-
* project's `.augment/settings.json
|
|
9248
|
+
* project's `.augment/settings.json`, and only by Auggie 0.x — 1.x no longer
|
|
9249
|
+
* reads it) and `enabledPlugins` (plugin ids of the
|
|
9214
9250
|
* form `"plugin@marketplace"` mapped to on/off, deep-merged across the user,
|
|
9215
9251
|
* project and local tiers).
|
|
9216
9252
|
*
|
|
@@ -9394,6 +9430,14 @@ const CodexBasePermissionProfileSchema = z.enum(CODEX_BASE_PERMISSION_PROFILES);
|
|
|
9394
9430
|
* `true`; only an explicit `false` suppresses it. Like
|
|
9395
9431
|
* `base_permission_profile` it is consumed by the profile builder, not
|
|
9396
9432
|
* written as a top-level config key.
|
|
9433
|
+
* - `bash_canonical_matching` — when `true`, the `forbidden` (deny) and
|
|
9434
|
+
* `prompt` (ask) rules generated from `permission.bash` into
|
|
9435
|
+
* `.codex/rules/rulesync.rules` carry `canonical_matching = True`, so Codex
|
|
9436
|
+
* compares their tokens after Unicode canonical case-insensitive folding (`rm` also
|
|
9437
|
+
* matches `RM`). `allow` rules stay exact so the opt-in never widens what is
|
|
9438
|
+
* auto-approved. Requires Codex 0.167.0 or later — an older Codex rejects the
|
|
9439
|
+
* keyword and fails to load the rules file — so it defaults to `false`. Not
|
|
9440
|
+
* written as a config key.
|
|
9397
9441
|
*
|
|
9398
9442
|
* The keys written to `config.toml` are an **allowlist**, not verbatim
|
|
9399
9443
|
* passthrough: only `CODEXCLI_OVERRIDE_KEYS`
|
|
@@ -9401,8 +9445,8 @@ const CodexBasePermissionProfileSchema = z.enum(CODEX_BASE_PERMISSION_PROFILES);
|
|
|
9401
9445
|
* `sandbox_workspace_write`, `apps`, `approvals_reviewer`, `auto_review`,
|
|
9402
9446
|
* `tui`) are emitted, and
|
|
9403
9447
|
* `computeCodexcliOverridePatch` skips anything else with a warning.
|
|
9404
|
-
* `base_permission_profile` and `
|
|
9405
|
-
*
|
|
9448
|
+
* `base_permission_profile`, `git_write_rules` and `bash_canonical_matching`
|
|
9449
|
+
* are consumed by the generators rather than written, as described above, and `permission` is the
|
|
9406
9450
|
* tool-scoped canonical block, which `RulesyncPermissions.forTarget` strips out
|
|
9407
9451
|
* of the override before it ever reaches the patch. The allowlist is what keeps
|
|
9408
9452
|
* the override from clobbering a feature-owned key: `mcp_servers.*` per-MCP
|
|
@@ -9459,7 +9503,8 @@ const CodexcliPermissionsOverrideSchema = z.looseObject({
|
|
|
9459
9503
|
* @see https://developers.openai.com/codex/config-reference
|
|
9460
9504
|
*/
|
|
9461
9505
|
tui: z.optional(z.looseObject({})),
|
|
9462
|
-
git_write_rules: z.optional(z.boolean())
|
|
9506
|
+
git_write_rules: z.optional(z.boolean()),
|
|
9507
|
+
bash_canonical_matching: z.optional(z.boolean())
|
|
9463
9508
|
});
|
|
9464
9509
|
/**
|
|
9465
9510
|
* Tool-scoped override block for Zed. These Zed `agent` keys sit outside the
|
|
@@ -9543,6 +9588,14 @@ const ZedPermissionsOverrideSchema = z.looseObject({
|
|
|
9543
9588
|
* { "sandbox": { "excluded": { "allow": ["Exec(git status *)"], "deny": ["Exec(git tag *)"] } } }
|
|
9544
9589
|
* @example
|
|
9545
9590
|
* { "forbiddenPlugins": ["*"], "optionalPlugins": ["acme/approved"] }
|
|
9591
|
+
*
|
|
9592
|
+
* `permission_mode` (CLI v3000.12.17+) is the mode new local sessions start in
|
|
9593
|
+
* (`normal`, the upstream default, `accept-edits`, `smart` or `dangerous`).
|
|
9594
|
+
* Like `sandbox` it is a **User Config Only** key, so it is emitted at global
|
|
9595
|
+
* scope only. It is never derived from the canonical rules.
|
|
9596
|
+
*
|
|
9597
|
+
* @example
|
|
9598
|
+
* { "permission_mode": "accept-edits" }
|
|
9546
9599
|
* @see https://docs.devin.ai/cli/sandbox
|
|
9547
9600
|
* @see https://docs.devin.ai/cli/reference/configuration/config-file
|
|
9548
9601
|
* @see https://docs.devin.ai/cli/extensibility/plugins/overview
|
|
@@ -9558,12 +9611,25 @@ const DEVIN_PLUGIN_GOVERNANCE_SCHEMAS = {
|
|
|
9558
9611
|
optionalPlugins: DevinPluginSourceListSchema,
|
|
9559
9612
|
forbiddenPlugins: z.array(z.string())
|
|
9560
9613
|
};
|
|
9614
|
+
/**
|
|
9615
|
+
* Values Devin accepts for the user-config `permission_mode` key. Shared by the
|
|
9616
|
+
* override schema and the import, which drops a value that would not pass it.
|
|
9617
|
+
*
|
|
9618
|
+
* @see https://docs.devin.ai/cli/reference/configuration/config-file
|
|
9619
|
+
*/
|
|
9620
|
+
const DevinPermissionModeSchema = z.enum([
|
|
9621
|
+
"normal",
|
|
9622
|
+
"accept-edits",
|
|
9623
|
+
"smart",
|
|
9624
|
+
"dangerous"
|
|
9625
|
+
]);
|
|
9561
9626
|
const DevinPermissionsOverrideSchema = z.looseObject({
|
|
9562
9627
|
permission: z.optional(ToolScopedPermissionSchema),
|
|
9563
9628
|
sandbox: z.optional(z.looseObject({})),
|
|
9564
9629
|
requiredPlugins: z.optional(DEVIN_PLUGIN_GOVERNANCE_SCHEMAS.requiredPlugins),
|
|
9565
9630
|
optionalPlugins: z.optional(DEVIN_PLUGIN_GOVERNANCE_SCHEMAS.optionalPlugins),
|
|
9566
|
-
forbiddenPlugins: z.optional(DEVIN_PLUGIN_GOVERNANCE_SCHEMAS.forbiddenPlugins)
|
|
9631
|
+
forbiddenPlugins: z.optional(DEVIN_PLUGIN_GOVERNANCE_SCHEMAS.forbiddenPlugins),
|
|
9632
|
+
permission_mode: z.optional(DevinPermissionModeSchema)
|
|
9567
9633
|
});
|
|
9568
9634
|
/**
|
|
9569
9635
|
* Permissions configuration.
|
|
@@ -11975,6 +12041,98 @@ function resolveStandardSkillFields({ rootFrontmatter, section }) {
|
|
|
11975
12041
|
})
|
|
11976
12042
|
});
|
|
11977
12043
|
}
|
|
12044
|
+
// src/utils/remote-name.ts
|
|
12045
|
+
/**
|
|
12046
|
+
* Name checks for a directory or file name chosen by a remote source (a
|
|
12047
|
+
* fetched repository, an installed git, GitHub or npm source). Shared by
|
|
12048
|
+
* `rulesync fetch` and `rulesync install`, so a name one of them turns away is
|
|
12049
|
+
* not written, or printed raw, by the other.
|
|
12050
|
+
*/
|
|
12051
|
+
/** A name with no character in it that draws anything of its own. */
|
|
12052
|
+
const NOTHING_DRAWN_PATTERN = /^[\s\p{M}]*$/u;
|
|
12053
|
+
/**
|
|
12054
|
+
* The marks a name begins with. A mark is drawn over the character before it,
|
|
12055
|
+
* and a name has nothing before it of its own: a leading one is drawn over
|
|
12056
|
+
* whatever the terminal printed last — the checkbox, the quote around a name
|
|
12057
|
+
* in a warning — while the name reads as if it began with its first letter.
|
|
12058
|
+
*/
|
|
12059
|
+
const LEADING_MARKS_PATTERN = /^\p{M}+/u;
|
|
12060
|
+
/**
|
|
12061
|
+
* A name ending in a dot or an ASCII space, which Win32 strips before it opens
|
|
12062
|
+
* the path. Only the plain space (U+0020): Win32 keeps every other trailing
|
|
12063
|
+
* blank, so a name ending in a no-break or an ideographic space is written
|
|
12064
|
+
* where it says, and is left to the whitespace note of the confusable-name
|
|
12065
|
+
* check rather than dropped here with Windows named as the reason.
|
|
12066
|
+
*/
|
|
12067
|
+
const TRAILING_DOT_OR_SPACE_PATTERN = /[. ]$/;
|
|
12068
|
+
/** A name ending in the `NAME~1` shape of a Windows 8.3 short name, extension included. */
|
|
12069
|
+
const SHORT_NAME_ALIAS_PATTERN = /~\d+(?:\.[^.]*)?$/;
|
|
12070
|
+
/**
|
|
12071
|
+
* A name Win32 reserves for a device — `CON`, `PRN`, `AUX`, `NUL`, `CONIN$`,
|
|
12072
|
+
* `CONOUT$`, `COM1`–`COM9`, `LPT1`–`LPT9` — in any case and with any
|
|
12073
|
+
* extension: `nul.md` is the null device too, since the reservation is decided
|
|
12074
|
+
* on the part before the first dot, with any spaces before that dot dropped
|
|
12075
|
+
* first, so `nul .md` is the null device as well. The port digit may also be
|
|
12076
|
+
* one of the superscript digits ¹ ² ³, which Win32 reads as 1, 2 and 3
|
|
12077
|
+
* (`RtlIsDosDeviceName_U`; CPython's `ntpath.isreserved` follows the same
|
|
12078
|
+
* rules).
|
|
12079
|
+
*/
|
|
12080
|
+
const RESERVED_DEVICE_NAME_PATTERN = /^(?:CON|PRN|AUX|NUL|CONIN\$|CONOUT\$|COM[1-9\u00B9\u00B2\u00B3]|LPT[1-9\u00B9\u00B2\u00B3]) *(?:\..*)?$/i;
|
|
12081
|
+
/**
|
|
12082
|
+
* Whether Windows resolves a path segment to something other than the entry it
|
|
12083
|
+
* reads as.
|
|
12084
|
+
*
|
|
12085
|
+
* Win32 drops a trailing dot or ASCII space when it resolves a path, so a remote
|
|
12086
|
+
* `skills/deploy.` is the existing `skills/deploy` there. A name ending in the
|
|
12087
|
+
* `NAME~1` shape is the same class of problem: on a volume that generates
|
|
12088
|
+
* short names, it opens whatever long name it stands for. The shape only
|
|
12089
|
+
* means that at the end of a name, so `data~2parser` and `v1.0` are ordinary
|
|
12090
|
+
* names. A reserved device name is the extreme case: `nul` and `nul.md` are
|
|
12091
|
+
* not entries in any directory but the null device itself, so a write to one
|
|
12092
|
+
* lands nowhere, and a directory of that name cannot be created at all.
|
|
12093
|
+
*
|
|
12094
|
+
* The predicate is asked of every segment of a written path — the skill
|
|
12095
|
+
* directory, but equally a nested `references/notes. ` or a `scripts/con.sh`
|
|
12096
|
+
* — since a folded segment anywhere in a path lands the file beside, or on top
|
|
12097
|
+
* of, a sibling the repository never published. The check is not gated on the
|
|
12098
|
+
* platform: the same repository is checked out on several of them, and a name
|
|
12099
|
+
* that lands somewhere else on any one of them is one this tool would rather
|
|
12100
|
+
* turn away everywhere than write differently depending on where it runs.
|
|
12101
|
+
*/
|
|
12102
|
+
function hasWindowsFoldableName(name) {
|
|
12103
|
+
return TRAILING_DOT_OR_SPACE_PATTERN.test(name) || SHORT_NAME_ALIAS_PATTERN.test(name) || RESERVED_DEVICE_NAME_PATTERN.test(name);
|
|
12104
|
+
}
|
|
12105
|
+
/**
|
|
12106
|
+
* Whether a remote name is safe to write and to print as it is.
|
|
12107
|
+
*
|
|
12108
|
+
* A name of nothing but blank space is shown as the empty string, the same as
|
|
12109
|
+
* one that strips down to nothing: both draw as a row with no name on it. So
|
|
12110
|
+
* is a name of nothing but combining marks, which have no character of their
|
|
12111
|
+
* own to sit on and draw as a smear over whatever the terminal puts beside
|
|
12112
|
+
* them. A name that merely begins with a mark is turned away for the same
|
|
12113
|
+
* reason, and shown without it: the mark sits on nothing the name owns. A name
|
|
12114
|
+
* carrying control characters (an ANSI, C1 or OSC sequence) or deceptive
|
|
12115
|
+
* zero-width characters is turned away too, so it can neither rewrite the
|
|
12116
|
+
* terminal nor pass for another name. The Windows-folding check comes after
|
|
12117
|
+
* the hidden characters, so a name that is both is reported by the reason that
|
|
12118
|
+
* keeps its raw form off the terminal.
|
|
12119
|
+
*/
|
|
12120
|
+
function classifyRemoteName(name) {
|
|
12121
|
+
const stripped = stripHiddenCharacters(name);
|
|
12122
|
+
const beginsWithMark = LEADING_MARKS_PATTERN.test(stripped);
|
|
12123
|
+
const display = NOTHING_DRAWN_PATTERN.test(stripped) ? "" : stripped.replace(LEADING_MARKS_PATTERN, "");
|
|
12124
|
+
if (display === "" || beginsWithMark || hasDeceptiveHiddenCharacters(name)) return {
|
|
12125
|
+
kind: "unsafe",
|
|
12126
|
+
display,
|
|
12127
|
+
reason: "hidden"
|
|
12128
|
+
};
|
|
12129
|
+
if (hasWindowsFoldableName(name)) return {
|
|
12130
|
+
kind: "unsafe",
|
|
12131
|
+
display,
|
|
12132
|
+
reason: "foldable"
|
|
12133
|
+
};
|
|
12134
|
+
return { kind: "safe" };
|
|
12135
|
+
}
|
|
11978
12136
|
// src/features/rules/instruction-budget.ts
|
|
11979
12137
|
/**
|
|
11980
12138
|
* Normalizes a relative directory path for comparison: POSIX separators, no
|
|
@@ -13862,7 +14020,11 @@ const SHARED_CONFIG_OWNERSHIP = {
|
|
|
13862
14020
|
},
|
|
13863
14021
|
permissions: {
|
|
13864
14022
|
kind: "replace-owned-keys",
|
|
13865
|
-
ownedKeys: [
|
|
14023
|
+
ownedKeys: [
|
|
14024
|
+
"permissions",
|
|
14025
|
+
"sandbox",
|
|
14026
|
+
"permission_mode"
|
|
14027
|
+
]
|
|
13866
14028
|
}
|
|
13867
14029
|
}
|
|
13868
14030
|
},
|
|
@@ -14636,6 +14798,16 @@ var RulesyncSourceConsumer = class {
|
|
|
14636
14798
|
this.dryRun = dryRun;
|
|
14637
14799
|
this.logger = logger;
|
|
14638
14800
|
}
|
|
14801
|
+
/**
|
|
14802
|
+
* Whether the orphan sweep may follow a symbolic link that stays inside the
|
|
14803
|
+
* output root. Only global scope answers true: its root is the operator's
|
|
14804
|
+
* own home directory, where a dotfiles checkout linked in (`~/.claude ->
|
|
14805
|
+
* ~/dotfiles/claude`) is a common shape. A project checkout may carry links
|
|
14806
|
+
* its author committed, so the default refuses them.
|
|
14807
|
+
*/
|
|
14808
|
+
sweepsThroughInRootLinks() {
|
|
14809
|
+
return false;
|
|
14810
|
+
}
|
|
14639
14811
|
recordRulesyncSourceLoadFailure() {
|
|
14640
14812
|
this.rulesyncSourceLoadFailed = true;
|
|
14641
14813
|
}
|
|
@@ -14768,7 +14940,8 @@ var FeatureProcessor = class extends RulesyncSourceConsumer {
|
|
|
14768
14940
|
refused = await refusesDeleteOutsideRoot({
|
|
14769
14941
|
logger: this.logger,
|
|
14770
14942
|
rootPath,
|
|
14771
|
-
dirPath
|
|
14943
|
+
dirPath,
|
|
14944
|
+
allowInRootLinks: this.sweepsThroughInRootLinks()
|
|
14772
14945
|
});
|
|
14773
14946
|
refusedDirs.set(cacheKey, refused);
|
|
14774
14947
|
}
|
|
@@ -14868,27 +15041,45 @@ function mergeByIdentity({ perRoot, identity }) {
|
|
|
14868
15041
|
return order.map((key) => winnerByKey.get(key));
|
|
14869
15042
|
}
|
|
14870
15043
|
/**
|
|
14871
|
-
*
|
|
14872
|
-
* there leads out of `rootPath`,
|
|
15044
|
+
* Why a write to `targetPath` has to be refused, or `null` when it may go
|
|
15045
|
+
* ahead: a link on the way there leads out of `rootPath`, or into
|
|
15046
|
+
* version-control metadata that the path as spelled does not name.
|
|
14873
15047
|
*
|
|
14874
15048
|
* A checked-out repository can carry a symbolic link at an output path
|
|
14875
|
-
* (`AGENTS.md -> ~/.bashrc`, a tool directory linked to `/etc`
|
|
14876
|
-
* through it would land wherever the link points.
|
|
14877
|
-
|
|
14878
|
-
|
|
15049
|
+
* (`AGENTS.md -> ~/.bashrc`, a tool directory linked to `/etc`, `CLAUDE.md ->
|
|
15050
|
+
* .git/config`), and a write through it would land wherever the link points.
|
|
15051
|
+
*/
|
|
15052
|
+
async function writeRefusalReason({ rootPath, targetPath }) {
|
|
15053
|
+
const relativeLanding = await relativeWriteLanding({
|
|
15054
|
+
rootPath,
|
|
15055
|
+
targetPath
|
|
15056
|
+
});
|
|
15057
|
+
if (relativeLanding === null || pathEscapesRoot(relativeLanding)) return `it resolves outside ${quoteForLog(rootPath)} through a symbolic link`;
|
|
15058
|
+
if (landingEntersVcsMetadata({
|
|
15059
|
+
rootPath,
|
|
15060
|
+
targetPath,
|
|
15061
|
+
relativeLanding
|
|
15062
|
+
})) return "it resolves into version-control metadata through a symbolic link";
|
|
15063
|
+
return null;
|
|
15064
|
+
}
|
|
15065
|
+
/**
|
|
15066
|
+
* Whether a write to `targetPath` has to be refused (see
|
|
15067
|
+
* {@link writeRefusalReason}), warning about the refusal. Every writer that
|
|
15068
|
+
* lets the OS follow links — file, directory, and config-rewrite alike — asks
|
|
15069
|
+
* this first so that one warning describes the one behavior.
|
|
14879
15070
|
*/
|
|
14880
15071
|
async function refusesWriteOutsideRoot({ logger, rootPath, targetPath }) {
|
|
14881
|
-
|
|
15072
|
+
const reason = await writeRefusalReason({
|
|
14882
15073
|
rootPath,
|
|
14883
15074
|
targetPath
|
|
14884
|
-
})
|
|
14885
|
-
|
|
15075
|
+
});
|
|
15076
|
+
if (reason === null) return false;
|
|
15077
|
+
logger.warn(`Refusing to write ${quoteForLog(targetPath)}: ${reason}`);
|
|
14886
15078
|
return true;
|
|
14887
15079
|
}
|
|
14888
15080
|
/**
|
|
14889
|
-
*
|
|
14890
|
-
*
|
|
14891
|
-
* once for the whole directory.
|
|
15081
|
+
* Why the orphan sweep has to leave the files in `dirPath` alone, or `null`
|
|
15082
|
+
* when it may delete them.
|
|
14892
15083
|
*
|
|
14893
15084
|
* Deletion candidates are enumerated without following links *inside* the
|
|
14894
15085
|
* scanned directory, but the scanned directory itself is reached through
|
|
@@ -14897,13 +15088,40 @@ async function refusesWriteOutsideRoot({ logger, rootPath, targetPath }) {
|
|
|
14897
15088
|
* an orphan. Only the directory is judged, never the file in it, because
|
|
14898
15089
|
* removing a file that is itself a link unlinks the link where it is spelled
|
|
14899
15090
|
* and never touches its target.
|
|
15091
|
+
*
|
|
15092
|
+
* Beyond the write rules, a project checkout is content another party may
|
|
15093
|
+
* control: a committed `.claude/rules -> ..` would make every untracked `*.md`
|
|
15094
|
+
* in the project read as an orphan. Unless `allowInRootLinks` (global scope,
|
|
15095
|
+
* where the root is the operator's own home directory) the swept directory
|
|
15096
|
+
* must therefore be the one its path spells, with no link on the way.
|
|
14900
15097
|
*/
|
|
14901
|
-
async function
|
|
14902
|
-
|
|
15098
|
+
async function sweepRefusalReason({ rootPath, dirPath, allowInRootLinks }) {
|
|
15099
|
+
const relativeLanding = await relativeWriteLanding({
|
|
14903
15100
|
rootPath,
|
|
14904
15101
|
targetPath: dirPath
|
|
14905
|
-
})
|
|
14906
|
-
|
|
15102
|
+
});
|
|
15103
|
+
if (relativeLanding === null || pathEscapesRoot(relativeLanding)) return `it resolves outside ${quoteForLog(rootPath)} through a symbolic link`;
|
|
15104
|
+
if (landingEntersVcsMetadata({
|
|
15105
|
+
rootPath,
|
|
15106
|
+
targetPath: dirPath,
|
|
15107
|
+
relativeLanding
|
|
15108
|
+
})) return "it resolves into version-control metadata through a symbolic link";
|
|
15109
|
+
if (!allowInRootLinks && relativeLanding !== relative(resolve(rootPath), resolve(dirPath))) return "it is reached through a symbolic link";
|
|
15110
|
+
return null;
|
|
15111
|
+
}
|
|
15112
|
+
/**
|
|
15113
|
+
* Whether deleting the files in `dirPath` has to be refused (see
|
|
15114
|
+
* {@link sweepRefusalReason}), warning about the refusal once for the whole
|
|
15115
|
+
* directory.
|
|
15116
|
+
*/
|
|
15117
|
+
async function refusesDeleteOutsideRoot({ logger, rootPath, dirPath, allowInRootLinks }) {
|
|
15118
|
+
const reason = await sweepRefusalReason({
|
|
15119
|
+
rootPath,
|
|
15120
|
+
dirPath,
|
|
15121
|
+
allowInRootLinks
|
|
15122
|
+
});
|
|
15123
|
+
if (reason === null) return false;
|
|
15124
|
+
logger.warn(`Refusing to delete files in ${quoteForLog(dirPath)}: ${reason}`);
|
|
14907
15125
|
return true;
|
|
14908
15126
|
}
|
|
14909
15127
|
/**
|
|
@@ -22614,6 +22832,9 @@ const commandsProcessorToolTargetsGlobal = allToolTargetKeys$3.filter((target) =
|
|
|
22614
22832
|
var CommandsProcessor = class extends FeatureProcessor {
|
|
22615
22833
|
toolTarget;
|
|
22616
22834
|
global;
|
|
22835
|
+
sweepsThroughInRootLinks() {
|
|
22836
|
+
return this.global;
|
|
22837
|
+
}
|
|
22617
22838
|
getFactory;
|
|
22618
22839
|
flattenedCommandNaming;
|
|
22619
22840
|
constructor({ outputRoot = process.cwd(), inputRoots, toolTarget, global = false, getFactory = defaultGetFactory$6, dryRun = false, flattenedCommandNaming = "basename", logger }) {
|
|
@@ -23185,6 +23406,15 @@ var DirFeatureProcessor = class extends RulesyncSourceConsumer {
|
|
|
23185
23406
|
this.logger.warn(`Refusing to sweep ${quotedDirPath}: ${stripControlCharacters(formatError(error))}`);
|
|
23186
23407
|
continue;
|
|
23187
23408
|
}
|
|
23409
|
+
const sweepRefusal = await sweepRefusalReason({
|
|
23410
|
+
rootPath: this.outputRoot,
|
|
23411
|
+
dirPath,
|
|
23412
|
+
allowInRootLinks: this.sweepsThroughInRootLinks()
|
|
23413
|
+
});
|
|
23414
|
+
if (sweepRefusal !== null) {
|
|
23415
|
+
this.logger.warn(`Refusing to sweep ${quotedDirPath}: ${sweepRefusal}`);
|
|
23416
|
+
continue;
|
|
23417
|
+
}
|
|
23188
23418
|
const generatedNames = /* @__PURE__ */ new Set();
|
|
23189
23419
|
const mainFile = aiDir.getMainFile();
|
|
23190
23420
|
if (mainFile) generatedNames.add(toPosixPath(mainFile.name));
|
|
@@ -25268,6 +25498,8 @@ const CRUSH_CONFIG_FILE_NAME = "crush.json";
|
|
|
25268
25498
|
const CRUSH_HIDDEN_CONFIG_FILE_NAME = ".crush.json";
|
|
25269
25499
|
const CRUSH_PERMISSIONS_KEY = "permissions";
|
|
25270
25500
|
const CRUSH_ALLOWED_TOOLS_KEY = "allowed_tools";
|
|
25501
|
+
const CRUSH_SAFE_COMMANDS_KEY = "safe_commands";
|
|
25502
|
+
const CRUSH_BLOCKED_COMMANDS_KEY = "blocked_commands";
|
|
25271
25503
|
const CRUSH_OPTIONS_KEY = "options";
|
|
25272
25504
|
const CRUSH_DISABLED_TOOLS_KEY = "disabled_tools";
|
|
25273
25505
|
const CRUSH_HOOKS_KEY = "hooks";
|
|
@@ -29948,6 +30180,9 @@ var SkillsProcessor = class extends DirFeatureProcessor {
|
|
|
29948
30180
|
global: this.global
|
|
29949
30181
|
});
|
|
29950
30182
|
}
|
|
30183
|
+
sweepsThroughInRootLinks() {
|
|
30184
|
+
return this.global;
|
|
30185
|
+
}
|
|
29951
30186
|
/**
|
|
29952
30187
|
* The tool's skills roots that exist on disk, each paired with its absolute
|
|
29953
30188
|
* path and vetted as writable inside this run's output root. Shared by the
|
|
@@ -29977,6 +30212,15 @@ var SkillsProcessor = class extends DirFeatureProcessor {
|
|
|
29977
30212
|
this.logger.warn(`Skipping the orphan sweep for ${quoteForLog(skillsDirPath)}; nothing under it is deleted: ${stripControlCharacters(formatError(error))}`);
|
|
29978
30213
|
continue;
|
|
29979
30214
|
}
|
|
30215
|
+
const sweepRefusal = await sweepRefusalReason({
|
|
30216
|
+
rootPath: this.outputRoot,
|
|
30217
|
+
dirPath: skillsDirPath,
|
|
30218
|
+
allowInRootLinks: this.sweepsThroughInRootLinks()
|
|
30219
|
+
});
|
|
30220
|
+
if (sweepRefusal !== null) {
|
|
30221
|
+
this.logger.warn(`Skipping the orphan sweep for ${quoteForLog(skillsDirPath)}; nothing under it is deleted: ${sweepRefusal}`);
|
|
30222
|
+
continue;
|
|
30223
|
+
}
|
|
29980
30224
|
existingRoots.push({
|
|
29981
30225
|
root,
|
|
29982
30226
|
skillsDirPath
|
|
@@ -33203,11 +33447,17 @@ var FirebenderSubagent = class FirebenderSubagent extends ToolSubagent {
|
|
|
33203
33447
|
*/
|
|
33204
33448
|
static async fromRulesyncSubagents({ outputRoot = process.cwd(), rulesyncSubagents, global = false, logger, deleteOrphans = false }) {
|
|
33205
33449
|
const agentsDirPath = this.getSettablePaths({ global }).relativeDirPath;
|
|
33206
|
-
const
|
|
33450
|
+
const agentsDirFullPath = join(outputRoot, agentsDirPath);
|
|
33451
|
+
const writeRefused = await writeRefusalReason({
|
|
33207
33452
|
rootPath: outputRoot,
|
|
33208
|
-
targetPath: join(
|
|
33209
|
-
});
|
|
33210
|
-
const
|
|
33453
|
+
targetPath: join(agentsDirFullPath, "agent.md")
|
|
33454
|
+
}) !== null;
|
|
33455
|
+
const sweepRefused = deleteOrphans && await sweepRefusalReason({
|
|
33456
|
+
rootPath: outputRoot,
|
|
33457
|
+
dirPath: agentsDirFullPath,
|
|
33458
|
+
allowInRootLinks: global
|
|
33459
|
+
}) !== null;
|
|
33460
|
+
const existingAgentFileNames = new Set(writeRefused ? [] : await listDirectoryEntryNames(agentsDirFullPath));
|
|
33211
33461
|
const subagents = rulesyncSubagents.map((rulesyncSubagent) => this.fromRulesyncSubagent({
|
|
33212
33462
|
outputRoot,
|
|
33213
33463
|
relativeDirPath: this.getSettablePaths({ global }).relativeDirPath,
|
|
@@ -33223,8 +33473,8 @@ var FirebenderSubagent = class FirebenderSubagent extends ToolSubagent {
|
|
|
33223
33473
|
global
|
|
33224
33474
|
})),
|
|
33225
33475
|
existingAgentFileNames,
|
|
33226
|
-
deleteOrphans,
|
|
33227
|
-
frozen:
|
|
33476
|
+
deleteOrphans: deleteOrphans && !sweepRefused,
|
|
33477
|
+
frozen: writeRefused,
|
|
33228
33478
|
global,
|
|
33229
33479
|
logger
|
|
33230
33480
|
});
|
|
@@ -37342,6 +37592,9 @@ function compareRelativePathsShallowestFirst(left, right) {
|
|
|
37342
37592
|
var SubagentsProcessor = class extends FeatureProcessor {
|
|
37343
37593
|
toolTarget;
|
|
37344
37594
|
global;
|
|
37595
|
+
sweepsThroughInRootLinks() {
|
|
37596
|
+
return this.global;
|
|
37597
|
+
}
|
|
37345
37598
|
deleteOrphans;
|
|
37346
37599
|
getFactory;
|
|
37347
37600
|
/**
|
|
@@ -38063,6 +38316,39 @@ function warnAndSkipMcpServer({ toolName, serverName, reason, logger }) {
|
|
|
38063
38316
|
return null;
|
|
38064
38317
|
}
|
|
38065
38318
|
/**
|
|
38319
|
+
* Drops every server whose `enabledTools` allowlist is empty, warning about
|
|
38320
|
+
* each one, for a tool that reads an empty (or missing) allowlist as "no
|
|
38321
|
+
* filter". Canonically an empty allowlist allows no tools at all, so emitting
|
|
38322
|
+
* the server unfiltered would expose every tool it reports. With
|
|
38323
|
+
* `ignoreBlankNames`, blank entries count as absent, for a tool that drops
|
|
38324
|
+
* them before applying the list. `productName` names the tool in the reason
|
|
38325
|
+
* when it differs from the `toolName` the warning starts with.
|
|
38326
|
+
*/
|
|
38327
|
+
function skipServersWithEmptyEnabledTools({ mcpServers, toolName, logger, ignoreBlankNames = false, productName = toolName }) {
|
|
38328
|
+
const kept = {};
|
|
38329
|
+
for (const [name, server] of Object.entries(mcpServers)) {
|
|
38330
|
+
const { enabledTools } = server;
|
|
38331
|
+
if (Array.isArray(enabledTools)) {
|
|
38332
|
+
if ((ignoreBlankNames ? enabledTools.filter((tool) => typeof tool !== "string" || tool.trim() !== "") : enabledTools).length === 0) {
|
|
38333
|
+
warnAndSkipMcpServer({
|
|
38334
|
+
toolName,
|
|
38335
|
+
serverName: name,
|
|
38336
|
+
reason: `an empty enabledTools list, which allows no tools at all but which ${productName} treats as no filter`,
|
|
38337
|
+
logger
|
|
38338
|
+
});
|
|
38339
|
+
continue;
|
|
38340
|
+
}
|
|
38341
|
+
}
|
|
38342
|
+
Object.defineProperty(kept, name, {
|
|
38343
|
+
value: server,
|
|
38344
|
+
enumerable: true,
|
|
38345
|
+
writable: true,
|
|
38346
|
+
configurable: true
|
|
38347
|
+
});
|
|
38348
|
+
}
|
|
38349
|
+
return kept;
|
|
38350
|
+
}
|
|
38351
|
+
/**
|
|
38066
38352
|
* The `tools` map Kilo and OpenCode keep beside `mcp` is keyed `<server>_<tool>`
|
|
38067
38353
|
* and reaches servers `mcp` does not list — ones the global config or a
|
|
38068
38354
|
* marketplace defines — so entries naming no listed
|
|
@@ -38624,7 +38910,11 @@ var KiloMcp = class KiloMcp extends ToolMcp {
|
|
|
38624
38910
|
const existingMcp = readExistingKiloMcpEntries(fileContent);
|
|
38625
38911
|
const parsedExisting = parse$1(fileContent || "{}");
|
|
38626
38912
|
const existingDocument = isRecord(parsedExisting) ? parsedExisting : {};
|
|
38627
|
-
const mcpServers =
|
|
38913
|
+
const mcpServers = skipServersWithEmptyEnabledTools({
|
|
38914
|
+
mcpServers: rulesyncMcp.getMcpServers(),
|
|
38915
|
+
toolName: "Kilo",
|
|
38916
|
+
logger
|
|
38917
|
+
});
|
|
38628
38918
|
const { mcp: convertedMcp, toolPermissions } = convertToKiloFormat(resolveKiloEnvVarRefs({
|
|
38629
38919
|
mcpServers,
|
|
38630
38920
|
global,
|
|
@@ -38753,7 +39043,8 @@ const OPENCODE_PASSTHROUGH_SERVER_FIELDS = [
|
|
|
38753
39043
|
"timeout",
|
|
38754
39044
|
"oauth",
|
|
38755
39045
|
"protocol",
|
|
38756
|
-
"codemode"
|
|
39046
|
+
"codemode",
|
|
39047
|
+
"pool"
|
|
38757
39048
|
];
|
|
38758
39049
|
const OPENCODE_MCP_TRANSPORT_KEYS = [
|
|
38759
39050
|
...Object.keys(OpencodeMcpLocalServerSchema.def.shape),
|
|
@@ -38916,7 +39207,7 @@ function warnAboutToggleDroppedKeys(serverName, serverConfig, logger) {
|
|
|
38916
39207
|
* - env -> environment
|
|
38917
39208
|
* - disabled -> enabled (inverted)
|
|
38918
39209
|
* - enabledTools/disabledTools -> top-level tools map (with server name prefix)
|
|
38919
|
-
* - OpenCode-supported extras (timeout, oauth, protocol, codemode) -> passed through verbatim
|
|
39210
|
+
* - OpenCode-supported extras (timeout, oauth, protocol, codemode, pool) -> passed through verbatim
|
|
38920
39211
|
*/
|
|
38921
39212
|
function convertServerToOpencodeFormat(serverName, serverConfig, existingEntry, configShape, logger) {
|
|
38922
39213
|
const serverRecord = serverConfig;
|
|
@@ -39156,7 +39447,11 @@ var OpencodeMcp = class extends ToolMcp {
|
|
|
39156
39447
|
if (fileContent) relativeFilePath = this.layout.jsonFileName;
|
|
39157
39448
|
}
|
|
39158
39449
|
const transformedServers = convertEnvVarRefsToToolFormat({
|
|
39159
|
-
mcpServers:
|
|
39450
|
+
mcpServers: skipServersWithEmptyEnabledTools({
|
|
39451
|
+
mcpServers: rulesyncMcp.getMcpServers(),
|
|
39452
|
+
toolName: "OpenCode",
|
|
39453
|
+
logger
|
|
39454
|
+
}),
|
|
39160
39455
|
replacement: "{env:$1}"
|
|
39161
39456
|
});
|
|
39162
39457
|
const existingJson = parse$1(fileContent || "{}");
|
|
@@ -48752,6 +49047,9 @@ var RulesProcessor = class extends FeatureProcessor {
|
|
|
48752
49047
|
language;
|
|
48753
49048
|
deriveSubprojectPathFromGlobs;
|
|
48754
49049
|
global;
|
|
49050
|
+
sweepsThroughInRootLinks() {
|
|
49051
|
+
return this.global;
|
|
49052
|
+
}
|
|
48755
49053
|
getFactory;
|
|
48756
49054
|
skills;
|
|
48757
49055
|
featureOptions;
|
|
@@ -51336,12 +51634,29 @@ var HermesagentCheck = class HermesagentCheck extends ToolCheck {
|
|
|
51336
51634
|
};
|
|
51337
51635
|
}
|
|
51338
51636
|
}
|
|
51637
|
+
/**
|
|
51638
|
+
* The `.rulesync/checks/<stem>.md` name an imported spec gets. The slug is
|
|
51639
|
+
* read from a spec file that may come from a fetched or cloned repository,
|
|
51640
|
+
* so it is kept as written only when it is a single plain file name; a slug
|
|
51641
|
+
* such as `../../docs/OPERATOR` would otherwise move the write out of
|
|
51642
|
+
* `.rulesync/checks/`. Anything else is slugified, and an empty result falls
|
|
51643
|
+
* back to the spec file's own name.
|
|
51644
|
+
*/
|
|
51645
|
+
importedCheckStem(slug) {
|
|
51646
|
+
const isPlainFileName = (name) => name !== "" && name !== "." && name !== ".." && !/[/\\<>:"|?*]/.test(name) && !hasWindowsFoldableName(name) && stripControlCharacters(name) === name;
|
|
51647
|
+
if (isPlainFileName(slug)) return slug;
|
|
51648
|
+
for (const candidate of [slugifyCheckName(slug), slugifyCheckName(basename(this.relativeFilePath, ".json"))]) {
|
|
51649
|
+
if (candidate === "") continue;
|
|
51650
|
+
return isPlainFileName(candidate) ? candidate : `${candidate}-check`;
|
|
51651
|
+
}
|
|
51652
|
+
return "check";
|
|
51653
|
+
}
|
|
51339
51654
|
toRulesyncCheck() {
|
|
51340
51655
|
const spec = HermesCheckSpecSchema.parse(JSON.parse(this.fileContent));
|
|
51341
51656
|
return new RulesyncCheck({
|
|
51342
51657
|
outputRoot: ".",
|
|
51343
51658
|
relativeDirPath: RULESYNC_CHECKS_RELATIVE_DIR_PATH,
|
|
51344
|
-
relativeFilePath: `${spec.slug}.md`,
|
|
51659
|
+
relativeFilePath: `${this.importedCheckStem(spec.slug)}.md`,
|
|
51345
51660
|
frontmatter: {
|
|
51346
51661
|
targets: ["*"],
|
|
51347
51662
|
description: spec.description,
|
|
@@ -51849,6 +52164,9 @@ const checksProcessorToolTargetsGlobal = allToolTargetKeys.filter((target) => {
|
|
|
51849
52164
|
var ChecksProcessor = class extends FeatureProcessor {
|
|
51850
52165
|
toolTarget;
|
|
51851
52166
|
global;
|
|
52167
|
+
sweepsThroughInRootLinks() {
|
|
52168
|
+
return this.global;
|
|
52169
|
+
}
|
|
51852
52170
|
getFactory;
|
|
51853
52171
|
constructor({ outputRoot = process.cwd(), inputRoots, toolTarget, global = false, getFactory = defaultGetFactory$2, dryRun = false, logger }) {
|
|
51854
52172
|
super({
|
|
@@ -54160,6 +54478,10 @@ function definingFields({ h, rawEntry, hookType, converterConfig }) {
|
|
|
54160
54478
|
field: "tool",
|
|
54161
54479
|
value: h.tool
|
|
54162
54480
|
});
|
|
54481
|
+
for (const { canonical, tool } of converterConfig.stringPassthroughFields ?? []) if (canonical === "if" && h[tool] !== "") fields.push({
|
|
54482
|
+
field: "if",
|
|
54483
|
+
value: h[tool]
|
|
54484
|
+
});
|
|
54163
54485
|
return fields;
|
|
54164
54486
|
}
|
|
54165
54487
|
/**
|
|
@@ -62936,10 +63258,12 @@ function emittedEventsWithHook(params) {
|
|
|
62936
63258
|
function converterCapabilities(config) {
|
|
62937
63259
|
if (!config.supportedHookTypes) throw new Error("Hooks converter config must declare its supportedHookTypes");
|
|
62938
63260
|
const passesThroughEnabled = (config.booleanPassthroughFields ?? []).some((field) => field.canonical === "enabled");
|
|
63261
|
+
const passesThroughIf = (config.stringPassthroughFields ?? []).some((field) => field.canonical === "if") && !(config.skippedWhenFields ?? []).includes("if");
|
|
62939
63262
|
return {
|
|
62940
63263
|
supportedEvents: config.supportedEvents,
|
|
62941
63264
|
supportedHookTypes: [...config.supportedHookTypes],
|
|
62942
|
-
...passesThroughEnabled ? { supportsPerHookEnabled: true } : {}
|
|
63265
|
+
...passesThroughEnabled ? { supportsPerHookEnabled: true } : {},
|
|
63266
|
+
...passesThroughIf ? { supportsPerHookIf: true } : {}
|
|
62943
63267
|
};
|
|
62944
63268
|
}
|
|
62945
63269
|
const toolHooksFactories = /* @__PURE__ */ new Map([
|
|
@@ -63584,6 +63908,9 @@ const hooksProcessorToolTargetsGlobalImportable = [...toolHooksFactories.entries
|
|
|
63584
63908
|
var HooksProcessor = class extends FeatureProcessor {
|
|
63585
63909
|
toolTarget;
|
|
63586
63910
|
global;
|
|
63911
|
+
sweepsThroughInRootLinks() {
|
|
63912
|
+
return this.global;
|
|
63913
|
+
}
|
|
63587
63914
|
preserveUnownedHooks;
|
|
63588
63915
|
constructor({ outputRoot = process.cwd(), inputRoots, toolTarget, global = false, dryRun = false, preserveUnownedHooks = false, logger }) {
|
|
63589
63916
|
super({
|
|
@@ -63662,7 +63989,8 @@ var HooksProcessor = class extends FeatureProcessor {
|
|
|
63662
63989
|
if (!factory) throw new Error(`Unsupported tool target: ${this.toolTarget}`);
|
|
63663
63990
|
const config = rulesyncHooks.getJson();
|
|
63664
63991
|
const sharedHooks = config.hooks;
|
|
63665
|
-
const
|
|
63992
|
+
const overrideKey = HOOKS_OVERRIDE_KEY_ALIASES[this.toolTarget] ?? this.toolTarget;
|
|
63993
|
+
const overrideHooks = config[overrideKey]?.hooks ?? {};
|
|
63666
63994
|
const effectiveHooks = {
|
|
63667
63995
|
...sharedHooks,
|
|
63668
63996
|
...overrideHooks
|
|
@@ -63700,7 +64028,10 @@ var HooksProcessor = class extends FeatureProcessor {
|
|
|
63700
64028
|
if (eventsWithUnsupportedMatcher.length > 0) this.logger.warn(`Skipped matcher hook(s) for ${this.toolTarget} (not supported): ${eventsWithUnsupportedMatcher.join(", ")}`);
|
|
63701
64029
|
const toolHooks = await factory.class.fromRulesyncHooks({
|
|
63702
64030
|
outputRoot: this.outputRoot,
|
|
63703
|
-
rulesyncHooks
|
|
64031
|
+
rulesyncHooks: factory.supportsPerHookIf ? rulesyncHooks : this.withoutConditionalHooks({
|
|
64032
|
+
rulesyncHooks,
|
|
64033
|
+
overrideKey
|
|
64034
|
+
}),
|
|
63704
64035
|
validate: true,
|
|
63705
64036
|
global: this.global,
|
|
63706
64037
|
preserveUnowned: this.preserveUnownedHooks,
|
|
@@ -63723,6 +64054,53 @@ var HooksProcessor = class extends FeatureProcessor {
|
|
|
63723
64054
|
return result;
|
|
63724
64055
|
}
|
|
63725
64056
|
/**
|
|
64057
|
+
* Returns the hooks source without the definitions that carry a per-hook
|
|
64058
|
+
* `if` condition, warning about each one. Used for targets that cannot
|
|
64059
|
+
* express `if`: emitting such a hook without its condition would make it
|
|
64060
|
+
* fire on every call its matcher selects, so a permission-granting hook
|
|
64061
|
+
* scoped by `if` would approve far more than its author meant.
|
|
64062
|
+
*/
|
|
64063
|
+
withoutConditionalHooks(params) {
|
|
64064
|
+
const { rulesyncHooks, overrideKey } = params;
|
|
64065
|
+
const config = rulesyncHooks.getJson();
|
|
64066
|
+
const skipped = [];
|
|
64067
|
+
const filterHooks = (hooks) => {
|
|
64068
|
+
if (!isPlainObject(hooks)) return hooks;
|
|
64069
|
+
const filtered = {};
|
|
64070
|
+
for (const [event, defs] of Object.entries(hooks)) {
|
|
64071
|
+
if (!Array.isArray(defs)) {
|
|
64072
|
+
filtered[event] = defs;
|
|
64073
|
+
continue;
|
|
64074
|
+
}
|
|
64075
|
+
filtered[event] = defs.filter((def) => {
|
|
64076
|
+
const condition = isPlainObject(def) ? def.if : void 0;
|
|
64077
|
+
if (typeof condition !== "string" || condition.trim() === "") return true;
|
|
64078
|
+
skipped.push(`${event} (${quoteValueForWarning(condition)})`);
|
|
64079
|
+
return false;
|
|
64080
|
+
});
|
|
64081
|
+
}
|
|
64082
|
+
return filtered;
|
|
64083
|
+
};
|
|
64084
|
+
const filteredConfig = {
|
|
64085
|
+
...config,
|
|
64086
|
+
hooks: filterHooks(config.hooks)
|
|
64087
|
+
};
|
|
64088
|
+
const override = config[overrideKey];
|
|
64089
|
+
if (Object.hasOwn(config, overrideKey) && isPlainObject(override)) filteredConfig[overrideKey] = {
|
|
64090
|
+
...override,
|
|
64091
|
+
hooks: filterHooks(override.hooks)
|
|
64092
|
+
};
|
|
64093
|
+
if (skipped.length === 0) return rulesyncHooks;
|
|
64094
|
+
this.logger.warn(`Skipped hook(s) with an "if" condition for ${this.toolTarget} (only the ${targetsSupporting("supportsPerHookIf")} hooks formats support it, and without it the hook would run on every call its matcher selects): ${skipped.join(", ")}`);
|
|
64095
|
+
return new RulesyncHooks({
|
|
64096
|
+
outputRoot: rulesyncHooks.getOutputRoot(),
|
|
64097
|
+
relativeDirPath: rulesyncHooks.getRelativeDirPath(),
|
|
64098
|
+
relativeFilePath: rulesyncHooks.getRelativeFilePath(),
|
|
64099
|
+
fileContent: JSON.stringify(filteredConfig),
|
|
64100
|
+
validate: false
|
|
64101
|
+
});
|
|
64102
|
+
}
|
|
64103
|
+
/**
|
|
63726
64104
|
* Warns about canonical per-hook fields that this target's hooks format
|
|
63727
64105
|
* cannot express, so a hook does not silently change behavior on generation.
|
|
63728
64106
|
* Only canonical definitions are considered: a tool-native field inside an
|
|
@@ -63967,6 +64345,35 @@ var BobIgnore = class extends PlainToolIgnore {
|
|
|
63967
64345
|
};
|
|
63968
64346
|
}
|
|
63969
64347
|
};
|
|
64348
|
+
// src/features/ignore/claude-read-deny-pattern.ts
|
|
64349
|
+
/**
|
|
64350
|
+
* Translate the path of a Claude Code style `Read(<path>)` deny into the
|
|
64351
|
+
* gitignore syntax of `.rulesync/.aiignore`.
|
|
64352
|
+
*
|
|
64353
|
+
* Claude Code reads the path forms differently from gitignore: `./path` is
|
|
64354
|
+
* relative to the current directory, `/path` to the project root, `//path` is
|
|
64355
|
+
* absolute and `~/path` is under the home directory. Copied verbatim, the
|
|
64356
|
+
* common `Read(./.env)` idiom would become `./.env`, which matches nothing in
|
|
64357
|
+
* a gitignore-syntax ignore file, so every other tool would lose the deny.
|
|
64358
|
+
*
|
|
64359
|
+
* - `./path` is anchored to the project root as `/path`.
|
|
64360
|
+
* - `//path` and `~/path` (or a bare `~`) name locations a project-relative
|
|
64361
|
+
* ignore file cannot express; they are skipped with a warning and `null` is
|
|
64362
|
+
* returned.
|
|
64363
|
+
* - Every other path (`.env`, `secrets/**`, `/path`) already means the same
|
|
64364
|
+
* project files in gitignore syntax and is kept as is.
|
|
64365
|
+
*/
|
|
64366
|
+
function claudeReadDenyPathToIgnorePattern({ path, toolLabel, logger }) {
|
|
64367
|
+
if (path.startsWith("//") || path === "~" || path.startsWith("~/")) {
|
|
64368
|
+
warnWithFallback(logger, `Skipping ${toolLabel} read deny ${quoteValueForWarning(path)} on ignore import: an absolute or home-directory path cannot be expressed in the project-relative .rulesync/.aiignore.`);
|
|
64369
|
+
return null;
|
|
64370
|
+
}
|
|
64371
|
+
if (path.startsWith("./")) {
|
|
64372
|
+
const rest = path.slice(2).replace(/^(?:\.\/)+/, "");
|
|
64373
|
+
return rest.length > 0 ? `/${rest}` : null;
|
|
64374
|
+
}
|
|
64375
|
+
return path;
|
|
64376
|
+
}
|
|
63970
64377
|
// src/features/ignore/claudecode-ignore.ts
|
|
63971
64378
|
const DEFAULT_FILE_MODE = "shared";
|
|
63972
64379
|
/**
|
|
@@ -64025,9 +64432,12 @@ var ClaudecodeIgnore = class ClaudecodeIgnore extends ToolIgnore {
|
|
|
64025
64432
|
}
|
|
64026
64433
|
toRulesyncIgnore() {
|
|
64027
64434
|
const fileContent = this.patterns.map((pattern) => {
|
|
64028
|
-
if (isReadDenyEntry(pattern)) return
|
|
64435
|
+
if (isReadDenyEntry(pattern)) return claudeReadDenyPathToIgnorePattern({
|
|
64436
|
+
path: pattern.slice(5, -1),
|
|
64437
|
+
toolLabel: "Claude Code"
|
|
64438
|
+
});
|
|
64029
64439
|
return pattern;
|
|
64030
|
-
}).filter((pattern) => pattern.length > 0).join("\n");
|
|
64440
|
+
}).filter((pattern) => pattern !== null && pattern.length > 0).join("\n");
|
|
64031
64441
|
return new RulesyncIgnore({
|
|
64032
64442
|
outputRoot: this.outputRoot,
|
|
64033
64443
|
relativeDirPath: RulesyncIgnore.getSettablePaths().recommended.relativeDirPath,
|
|
@@ -64302,7 +64712,7 @@ var FirebenderIgnore = class FirebenderIgnore extends ToolIgnore {
|
|
|
64302
64712
|
const paths = this.getSettablePaths({ global });
|
|
64303
64713
|
const filePath = join(outputRoot, paths.relativeDirPath, paths.relativeFilePath);
|
|
64304
64714
|
const existingContent = await readFileContentOrNull(filePath) ?? "{}";
|
|
64305
|
-
const managedPatterns =
|
|
64715
|
+
const managedPatterns = patterns.filter((pattern, index) => patterns.lastIndexOf(pattern) === index);
|
|
64306
64716
|
return new FirebenderIgnore({
|
|
64307
64717
|
outputRoot,
|
|
64308
64718
|
relativeDirPath: paths.relativeDirPath,
|
|
@@ -64957,7 +65367,10 @@ const asClaudeStyleSettings = (document) => {
|
|
|
64957
65367
|
};
|
|
64958
65368
|
/** The pattern of a `read_file(...)` (or legacy `Read(...)`) deny, else null. */
|
|
64959
65369
|
const readDenyPatternOf = (entry) => {
|
|
64960
|
-
for (const toolName of [REASONIX_READ_TOOL_NAME, REASONIX_LEGACY_READ_TOOL_NAME]) if (isReadDenyEntry(entry, toolName)) return
|
|
65370
|
+
for (const toolName of [REASONIX_READ_TOOL_NAME, REASONIX_LEGACY_READ_TOOL_NAME]) if (isReadDenyEntry(entry, toolName)) return claudeReadDenyPathToIgnorePattern({
|
|
65371
|
+
path: entry.slice(toolName.length + 1, -1),
|
|
65372
|
+
toolLabel: "Reasonix"
|
|
65373
|
+
});
|
|
64961
65374
|
return null;
|
|
64962
65375
|
};
|
|
64963
65376
|
/**
|
|
@@ -65297,6 +65710,9 @@ var IgnoreProcessor = class extends FeatureProcessor {
|
|
|
65297
65710
|
getFactory;
|
|
65298
65711
|
featureOptions;
|
|
65299
65712
|
global;
|
|
65713
|
+
sweepsThroughInRootLinks() {
|
|
65714
|
+
return this.global;
|
|
65715
|
+
}
|
|
65300
65716
|
constructor({ outputRoot = process.cwd(), inputRoots, toolTarget, getFactory = defaultGetFactory$1, global = false, dryRun = false, logger, featureOptions }) {
|
|
65301
65717
|
super({
|
|
65302
65718
|
outputRoot,
|
|
@@ -65630,30 +66046,71 @@ function isEmptyValue(value) {
|
|
|
65630
66046
|
if (Array.isArray(value)) return value.length === 0;
|
|
65631
66047
|
return isPlainObject(value) && Object.keys(value).length === 0;
|
|
65632
66048
|
}
|
|
66049
|
+
const MILLISECONDS_PER_SECOND$4 = 1e3;
|
|
66050
|
+
/**
|
|
66051
|
+
* Convert the canonical `timeout` (milliseconds) into Antigravity's
|
|
66052
|
+
* `timeoutSeconds` (integer seconds), rounding up so a sub-second timeout does
|
|
66053
|
+
* not become `0`. A negative value disables the timeout upstream, so it is
|
|
66054
|
+
* written as `-1`. An authored native `timeoutSeconds` wins over `timeout`.
|
|
66055
|
+
*/
|
|
66056
|
+
function convertTimeoutToAntigravity({ serverName, config, logger }) {
|
|
66057
|
+
if (!("timeout" in config)) return config;
|
|
66058
|
+
const { timeout, ...rest } = config;
|
|
66059
|
+
if (rest.timeoutSeconds !== void 0) {
|
|
66060
|
+
logger?.warn(`Antigravity MCP: ${quoteValueForWarning(serverName)} sets both "timeout" and "timeoutSeconds"; keeping "timeoutSeconds" and dropping "timeout".`);
|
|
66061
|
+
return rest;
|
|
66062
|
+
}
|
|
66063
|
+
if (typeof timeout !== "number" || !Number.isFinite(timeout)) {
|
|
66064
|
+
logger?.warn(`Antigravity MCP: dropping the "timeout" of ${quoteValueForWarning(serverName)}: expected a number of milliseconds.`);
|
|
66065
|
+
return rest;
|
|
66066
|
+
}
|
|
66067
|
+
const timeoutSeconds = timeout < 0 ? -1 : Math.ceil(timeout / MILLISECONDS_PER_SECOND$4);
|
|
66068
|
+
return Object.fromEntries(Object.entries(config).map(([key, value]) => key === "timeout" ? ["timeoutSeconds", timeoutSeconds] : [key, value]));
|
|
66069
|
+
}
|
|
65633
66070
|
/**
|
|
65634
|
-
* Antigravity uses `serverUrl` (not the canonical `url`) for
|
|
66071
|
+
* Antigravity uses `serverUrl` (not the canonical `url`) for remote MCP
|
|
65635
66072
|
* servers. Convert the canonical shape into Antigravity's on the way out, and
|
|
65636
66073
|
* back to canonical on the way in.
|
|
65637
66074
|
*
|
|
65638
66075
|
* Antigravity documents no `type` field: the transport follows from `command`
|
|
65639
|
-
* (stdio) or `serverUrl` (Streamable HTTP
|
|
66076
|
+
* (stdio) or `serverUrl` (Streamable HTTP), and `agy plugin validate`
|
|
65640
66077
|
* reports the canonical `type` as an unknown field, so it is not written. A
|
|
65641
66078
|
* remote server that carries `command`, `args` or `env` was also observed to be
|
|
65642
66079
|
* refused at startup (runtime behavior reported by `agy plugin validate` 1.4.4,
|
|
65643
66080
|
* not documented), so an empty `args` / `env` left on a `serverUrl` server is
|
|
65644
66081
|
* dropped.
|
|
66082
|
+
*
|
|
66083
|
+
* Remote servers must use Streamable HTTP: the legacy HTTP+SSE transport is
|
|
66084
|
+
* not supported, so a canonical `sse` server is still written but warned
|
|
66085
|
+
* about. The canonical `timeout` (milliseconds) becomes `timeoutSeconds`.
|
|
65645
66086
|
* https://antigravity.google/docs/mcp
|
|
65646
66087
|
*/
|
|
65647
|
-
function toAntigravityMcpServers(servers) {
|
|
66088
|
+
function toAntigravityMcpServers(servers, logger) {
|
|
65648
66089
|
const renamed = renameServerField(servers, "url", "serverUrl");
|
|
65649
66090
|
return Object.fromEntries(Object.entries(renamed).map(([name, config]) => {
|
|
65650
66091
|
if (!isPlainObject(config)) return [name, config];
|
|
66092
|
+
if (config.type === "sse" || config.transport === "sse") logger?.warn(`Antigravity MCP: ${quoteValueForWarning(name)} uses the SSE transport, which Antigravity does not support (remote servers must use Streamable HTTP); it is written as "serverUrl" and may fail to connect.`);
|
|
65651
66093
|
const isRemote = typeof config.serverUrl === "string";
|
|
65652
|
-
return [name,
|
|
66094
|
+
return [name, convertTimeoutToAntigravity({
|
|
66095
|
+
serverName: name,
|
|
66096
|
+
config: Object.fromEntries(Object.entries(config).filter(([key, value]) => key !== "type" && !(isRemote && (key === "args" || key === "env") && isEmptyValue(value)))),
|
|
66097
|
+
logger
|
|
66098
|
+
})];
|
|
65653
66099
|
}));
|
|
65654
66100
|
}
|
|
66101
|
+
/**
|
|
66102
|
+
* Convert Antigravity servers back to the canonical shape: `serverUrl` becomes
|
|
66103
|
+
* `url`, and `timeoutSeconds` becomes the canonical `timeout` in milliseconds
|
|
66104
|
+
* (a negative value, which disables the timeout upstream, stays `-1`).
|
|
66105
|
+
*/
|
|
65655
66106
|
function toCanonicalMcpServers(servers) {
|
|
65656
|
-
|
|
66107
|
+
const renamed = renameServerField(servers, "serverUrl", "url");
|
|
66108
|
+
return Object.fromEntries(Object.entries(renamed).map(([name, config]) => {
|
|
66109
|
+
if (!isPlainObject(config) || typeof config.timeoutSeconds !== "number") return [name, config];
|
|
66110
|
+
const timeoutSeconds = config.timeoutSeconds;
|
|
66111
|
+
const timeout = timeoutSeconds < 0 ? -1 : timeoutSeconds * MILLISECONDS_PER_SECOND$4;
|
|
66112
|
+
return [name, Object.fromEntries(Object.entries(config).filter(([key]) => key !== "timeout").map(([key, value]) => key === "timeoutSeconds" ? ["timeout", timeout] : [key, value]))];
|
|
66113
|
+
}));
|
|
65657
66114
|
}
|
|
65658
66115
|
/**
|
|
65659
66116
|
* Parse `mcp_config.json` as JSONC and require a top-level object, so a file
|
|
@@ -65671,7 +66128,8 @@ function parseAntigravityMcpConfig(fileContent) {
|
|
|
65671
66128
|
* the IDE and the CLI.
|
|
65672
66129
|
*
|
|
65673
66130
|
* Antigravity writes a dedicated `mcp_config.json` whose `mcpServers` map lives
|
|
65674
|
-
* at the top level (`disabledTools` per server
|
|
66131
|
+
* at the top level (`enabledTools` / `disabledTools` per server are supported
|
|
66132
|
+
* under the same names). Unlike Gemini
|
|
65675
66133
|
* CLI's shared `settings.json`, this file is dedicated to MCP, so it is safely
|
|
65676
66134
|
* deletable. HTTP servers use `serverUrl` rather than the canonical `url`, so
|
|
65677
66135
|
* the field is translated in both directions.
|
|
@@ -65724,11 +66182,11 @@ var AntigravityMcp = class extends ToolMcp {
|
|
|
65724
66182
|
global
|
|
65725
66183
|
});
|
|
65726
66184
|
}
|
|
65727
|
-
static async fromRulesyncMcp({ outputRoot = process.cwd(), rulesyncMcp, validate = true, global = false }) {
|
|
66185
|
+
static async fromRulesyncMcp({ outputRoot = process.cwd(), rulesyncMcp, validate = true, global = false, logger }) {
|
|
65728
66186
|
const paths = this.getSettablePaths({ global });
|
|
65729
66187
|
const newJson = {
|
|
65730
66188
|
...parseAntigravityMcpConfig(await readFileContentOrNull(join(outputRoot, paths.relativeDirPath, paths.relativeFilePath)) ?? JSON.stringify({ mcpServers: {} }, null, 2)),
|
|
65731
|
-
mcpServers: toAntigravityMcpServers(rulesyncMcp.getMcpServers())
|
|
66189
|
+
mcpServers: toAntigravityMcpServers(rulesyncMcp.getMcpServers(), logger)
|
|
65732
66190
|
};
|
|
65733
66191
|
return new this({
|
|
65734
66192
|
outputRoot,
|
|
@@ -69397,7 +69855,11 @@ var CrushMcp = class CrushMcp extends ToolMcp {
|
|
|
69397
69855
|
ownedPaths: [["mcp"]],
|
|
69398
69856
|
logger
|
|
69399
69857
|
});
|
|
69400
|
-
const converted = convertToCrushFormat(Object.fromEntries(Object.entries(
|
|
69858
|
+
const converted = convertToCrushFormat(Object.fromEntries(Object.entries(skipServersWithEmptyEnabledTools({
|
|
69859
|
+
mcpServers: rulesyncMcp.getMcpServers(),
|
|
69860
|
+
toolName: "Crush",
|
|
69861
|
+
logger
|
|
69862
|
+
})).map(([serverName, serverConfig]) => [serverName, {
|
|
69401
69863
|
...serverConfig,
|
|
69402
69864
|
...readCrushOnlyKeys({
|
|
69403
69865
|
serverName,
|
|
@@ -70357,31 +70819,6 @@ var DshMcp = class DshMcp extends ToolMcp {
|
|
|
70357
70819
|
};
|
|
70358
70820
|
// src/features/mcp/factorydroid-mcp.ts
|
|
70359
70821
|
const TOOL_NAME = "factorydroid";
|
|
70360
|
-
/**
|
|
70361
|
-
* Drop servers whose `enabledTools` allowlist is empty.
|
|
70362
|
-
*
|
|
70363
|
-
* Canonically an empty allowlist allows no tools, but Droid applies
|
|
70364
|
-
* `enabledTools` only "when the list is non-empty"
|
|
70365
|
-
* (https://docs.factory.com/harness/mcp), so writing `[]` would load every
|
|
70366
|
-
* tool the server reports. Skipping the server is the only form that does not
|
|
70367
|
-
* hand the model more tools than the canonical config allows.
|
|
70368
|
-
*/
|
|
70369
|
-
function skipEmptyAllowlistServers({ mcpServers, logger }) {
|
|
70370
|
-
const kept = {};
|
|
70371
|
-
for (const [name, server] of Object.entries(mcpServers)) {
|
|
70372
|
-
if (server.enabledTools?.length === 0) {
|
|
70373
|
-
warnAndSkipMcpServer({
|
|
70374
|
-
toolName: TOOL_NAME,
|
|
70375
|
-
serverName: name,
|
|
70376
|
-
reason: "an empty enabledTools list, which allows no tools at all but which Factory Droid treats as no filter",
|
|
70377
|
-
logger
|
|
70378
|
-
});
|
|
70379
|
-
continue;
|
|
70380
|
-
}
|
|
70381
|
-
kept[name] = server;
|
|
70382
|
-
}
|
|
70383
|
-
return kept;
|
|
70384
|
-
}
|
|
70385
70822
|
var FactorydroidMcp = class FactorydroidMcp extends ToolMcp {
|
|
70386
70823
|
json;
|
|
70387
70824
|
constructor(params) {
|
|
@@ -70408,8 +70845,10 @@ var FactorydroidMcp = class FactorydroidMcp extends ToolMcp {
|
|
|
70408
70845
|
});
|
|
70409
70846
|
}
|
|
70410
70847
|
static fromRulesyncMcp({ outputRoot = process.cwd(), rulesyncMcp, validate = true, logger }) {
|
|
70411
|
-
const factorydroidConfig = { mcpServers:
|
|
70848
|
+
const factorydroidConfig = { mcpServers: skipServersWithEmptyEnabledTools({
|
|
70412
70849
|
mcpServers: rulesyncMcp.getMcpServers(),
|
|
70850
|
+
toolName: TOOL_NAME,
|
|
70851
|
+
productName: "Factory Droid",
|
|
70413
70852
|
logger
|
|
70414
70853
|
}) };
|
|
70415
70854
|
const fileContent = JSON.stringify(factorydroidConfig, null, 2);
|
|
@@ -71840,19 +72279,42 @@ function normalizeKimiCodeTransport({ transport, hasCommand }) {
|
|
|
71840
72279
|
return hasCommand ? "stdio" : "http";
|
|
71841
72280
|
}
|
|
71842
72281
|
/**
|
|
71843
|
-
* The only `executor` value Kimi Code accepts on a stdio
|
|
71844
|
-
* the never-implemented `kaos` option and narrowed the
|
|
71845
|
-
* `z.enum(['local'])`, so
|
|
71846
|
-
*
|
|
72282
|
+
* The only `executor` value every current Kimi Code release accepts on a stdio
|
|
72283
|
+
* server. 2.2.0 removed the never-implemented `kaos` option and narrowed the
|
|
72284
|
+
* schema to `z.enum(['local'])`, so 2.2.0 through 2.4.x fail validation on any
|
|
72285
|
+
* other value when they load `mcp.json`. 2.5.0 widened the enum back to
|
|
72286
|
+
* `'local' | 'kaos'`, but `kaos` is still undocumented and would break the
|
|
72287
|
+
* older releases, so it keeps being dropped.
|
|
71847
72288
|
* @see https://github.com/MoonshotAI/kimi-code/pull/4184
|
|
72289
|
+
* @see https://github.com/MoonshotAI/kimi-code/pull/4062
|
|
71848
72290
|
*/
|
|
71849
72291
|
const KIMI_CODE_MCP_EXECUTOR = "local";
|
|
71850
72292
|
/** Remove, with a warning, an `executor` value Kimi Code would reject. Mutates `server`. */
|
|
71851
72293
|
function dropUnsupportedKimiCodeExecutor({ name, server, logger }) {
|
|
71852
72294
|
if (server.executor === void 0 || server.executor === KIMI_CODE_MCP_EXECUTOR) return;
|
|
71853
|
-
warnWithFallback(logger, `Kimi Code MCP: dropping executor ${JSON.stringify(server.executor)} from "${name}" because Kimi Code only
|
|
72295
|
+
warnWithFallback(logger, `Kimi Code MCP: dropping executor ${JSON.stringify(server.executor)} from "${name}" because Kimi Code 2.2.0 through 2.4.x accept only "${KIMI_CODE_MCP_EXECUTOR}".`);
|
|
71854
72296
|
delete server.executor;
|
|
71855
72297
|
}
|
|
72298
|
+
/**
|
|
72299
|
+
* Remove, with a warning, an `environment_id` Kimi Code cannot use. Kimi Code
|
|
72300
|
+
* 2.5.0 added it to stdio servers only, as a non-empty string naming an
|
|
72301
|
+
* `[environments.<id>]` entry of `config.toml`; an empty or non-string value
|
|
72302
|
+
* fails Kimi's validation. Mutates `server`.
|
|
72303
|
+
* @see https://github.com/MoonshotAI/kimi-code/pull/4062
|
|
72304
|
+
*/
|
|
72305
|
+
function dropUnsupportedKimiCodeEnvironmentId({ name, server, isStdio, logger }) {
|
|
72306
|
+
const environmentId = server.environment_id;
|
|
72307
|
+
if (environmentId === void 0) return;
|
|
72308
|
+
if (!isStdio) {
|
|
72309
|
+
warnWithFallback(logger, `Kimi Code MCP: dropping environment_id from "${name}" because Kimi Code only accepts it on stdio servers.`);
|
|
72310
|
+
delete server.environment_id;
|
|
72311
|
+
return;
|
|
72312
|
+
}
|
|
72313
|
+
if (typeof environmentId !== "string" || environmentId.length === 0) {
|
|
72314
|
+
warnWithFallback(logger, `Kimi Code MCP: dropping environment_id ${JSON.stringify(environmentId)} from "${name}" because Kimi Code requires a non-empty string.`);
|
|
72315
|
+
delete server.environment_id;
|
|
72316
|
+
}
|
|
72317
|
+
}
|
|
71856
72318
|
function toKimiCodeServer({ name, server, logger }) {
|
|
71857
72319
|
const transport = server.transport ?? server.type;
|
|
71858
72320
|
if (transport === "ws") {
|
|
@@ -71880,6 +72342,7 @@ function toKimiCodeServer({ name, server, logger }) {
|
|
|
71880
72342
|
for (const field of [
|
|
71881
72343
|
"env",
|
|
71882
72344
|
"cwd",
|
|
72345
|
+
"environment_id",
|
|
71883
72346
|
"executor",
|
|
71884
72347
|
"runtime_id",
|
|
71885
72348
|
"headers",
|
|
@@ -71896,6 +72359,12 @@ function toKimiCodeServer({ name, server, logger }) {
|
|
|
71896
72359
|
server: converted,
|
|
71897
72360
|
logger
|
|
71898
72361
|
});
|
|
72362
|
+
dropUnsupportedKimiCodeEnvironmentId({
|
|
72363
|
+
name,
|
|
72364
|
+
server: converted,
|
|
72365
|
+
isStdio: normalizedTransport === "stdio",
|
|
72366
|
+
logger
|
|
72367
|
+
});
|
|
71899
72368
|
if (server.disabled === true) converted.enabled = false;
|
|
71900
72369
|
return converted;
|
|
71901
72370
|
}
|
|
@@ -71920,6 +72389,15 @@ function fromKimiCodeServers({ servers, logger }) {
|
|
|
71920
72389
|
logger
|
|
71921
72390
|
});
|
|
71922
72391
|
const type = transport === "stdio" || transport === "sse" || transport === "http" ? transport : void 0;
|
|
72392
|
+
dropUnsupportedKimiCodeEnvironmentId({
|
|
72393
|
+
name,
|
|
72394
|
+
server: rest,
|
|
72395
|
+
isStdio: normalizeKimiCodeTransport({
|
|
72396
|
+
transport,
|
|
72397
|
+
hasCommand: rest.command !== void 0
|
|
72398
|
+
}) === "stdio",
|
|
72399
|
+
logger
|
|
72400
|
+
});
|
|
71923
72401
|
return [name, {
|
|
71924
72402
|
...rest,
|
|
71925
72403
|
...type && { type },
|
|
@@ -73088,7 +73566,12 @@ var OpenclawMcp = class OpenclawMcp extends ToolMcp {
|
|
|
73088
73566
|
const existingMcp = isRecord(existing["mcp"]) ? existing["mcp"] : {};
|
|
73089
73567
|
const existingServers = isRecord(existingMcp["servers"]) ? existingMcp[OPENCLAW_MCP_SERVERS_KEY] : {};
|
|
73090
73568
|
const converted = convertToOpenclawFormat({
|
|
73091
|
-
mcpServers:
|
|
73569
|
+
mcpServers: skipServersWithEmptyEnabledTools({
|
|
73570
|
+
mcpServers: rulesyncMcp.getMcpServers(),
|
|
73571
|
+
toolName: "OpenClaw",
|
|
73572
|
+
ignoreBlankNames: true,
|
|
73573
|
+
logger
|
|
73574
|
+
}),
|
|
73092
73575
|
logger
|
|
73093
73576
|
});
|
|
73094
73577
|
const servers = {
|
|
@@ -73716,7 +74199,11 @@ var PoolMcp = class PoolMcp extends ToolMcp {
|
|
|
73716
74199
|
const paths = this.getSettablePaths({ global });
|
|
73717
74200
|
const filePath = join(outputRoot, paths.relativeDirPath, paths.relativeFilePath);
|
|
73718
74201
|
const existingContent = await readFileContentOrNull(filePath) ?? "";
|
|
73719
|
-
const converted = convertToPoolFormat(Object.fromEntries(Object.entries(
|
|
74202
|
+
const converted = convertToPoolFormat(Object.fromEntries(Object.entries(skipServersWithEmptyEnabledTools({
|
|
74203
|
+
mcpServers: rulesyncMcp.getMcpServers(),
|
|
74204
|
+
toolName: "Pool",
|
|
74205
|
+
logger
|
|
74206
|
+
})).map(([serverName, serverConfig]) => {
|
|
73720
74207
|
const rawServer = rulesyncMcp.getRawMcpServer(serverName);
|
|
73721
74208
|
const poolAllow = isRecord(rawServer) ? rawServer.poolAllow : void 0;
|
|
73722
74209
|
return [serverName, {
|
|
@@ -77242,7 +77729,7 @@ const toolMcpFactories = /* @__PURE__ */ new Map([
|
|
|
77242
77729
|
meta: {
|
|
77243
77730
|
supportsProject: true,
|
|
77244
77731
|
supportsGlobal: true,
|
|
77245
|
-
supportsEnabledTools:
|
|
77732
|
+
supportsEnabledTools: true,
|
|
77246
77733
|
supportsDisabledTools: true
|
|
77247
77734
|
}
|
|
77248
77735
|
}],
|
|
@@ -77251,7 +77738,7 @@ const toolMcpFactories = /* @__PURE__ */ new Map([
|
|
|
77251
77738
|
meta: {
|
|
77252
77739
|
supportsProject: true,
|
|
77253
77740
|
supportsGlobal: true,
|
|
77254
|
-
supportsEnabledTools:
|
|
77741
|
+
supportsEnabledTools: true,
|
|
77255
77742
|
supportsDisabledTools: true
|
|
77256
77743
|
}
|
|
77257
77744
|
}],
|
|
@@ -77260,7 +77747,7 @@ const toolMcpFactories = /* @__PURE__ */ new Map([
|
|
|
77260
77747
|
meta: {
|
|
77261
77748
|
supportsProject: true,
|
|
77262
77749
|
supportsGlobal: false,
|
|
77263
|
-
supportsEnabledTools:
|
|
77750
|
+
supportsEnabledTools: true,
|
|
77264
77751
|
supportsDisabledTools: true
|
|
77265
77752
|
}
|
|
77266
77753
|
}],
|
|
@@ -77827,6 +78314,9 @@ function warnStrippedMcpServerFields({ mcpServers, fields, toolTarget, logger })
|
|
|
77827
78314
|
var McpProcessor = class extends FeatureProcessor {
|
|
77828
78315
|
toolTarget;
|
|
77829
78316
|
global;
|
|
78317
|
+
sweepsThroughInRootLinks() {
|
|
78318
|
+
return this.global;
|
|
78319
|
+
}
|
|
77830
78320
|
getFactory;
|
|
77831
78321
|
featureOptions;
|
|
77832
78322
|
constructor({ outputRoot = process.cwd(), inputRoots, toolTarget, global = false, getFactory = defaultGetFactory, dryRun = false, logger, featureOptions }) {
|
|
@@ -78968,6 +79458,30 @@ function maxRangeCount(steps) {
|
|
|
78968
79458
|
return most;
|
|
78969
79459
|
}
|
|
78970
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
|
+
/**
|
|
78971
79485
|
* `globsIntersect` for two globs already parsed, optionally spending a budget
|
|
78972
79486
|
* shared with the rest of the caller's run — see `createIntersectionBudget`.
|
|
78973
79487
|
* Once that budget is exhausted every further pair answers `true` without being
|
|
@@ -79595,6 +80109,11 @@ function collectShellCommandRules(permission) {
|
|
|
79595
80109
|
function widenToPrefixGlob$1(pattern) {
|
|
79596
80110
|
return pattern.endsWith("*") ? pattern : `${pattern}*`;
|
|
79597
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
|
+
}
|
|
79598
80117
|
/**
|
|
79599
80118
|
* Build the test an adapter applies to an `allow` pattern before writing it:
|
|
79600
80119
|
* which restrictions it cannot write name some of the same commands? The
|
|
@@ -79626,11 +80145,11 @@ function widenToPrefixGlob$1(pattern) {
|
|
|
79626
80145
|
function createShadowingRestrictionsTest(restrictions, { normalizePattern = (pattern) => pattern, budget = createIntersectionBudget() } = {}) {
|
|
79627
80146
|
const normalized = restrictions.map(({ pattern, fromAllToolsCategory }) => ({
|
|
79628
80147
|
pattern,
|
|
79629
|
-
glob: parseGlobPattern(fromAllToolsCategory ? pattern : normalizePattern(pattern))
|
|
80148
|
+
glob: parseGlobPattern(widenForOverlap(fromAllToolsCategory ? pattern : normalizePattern(pattern)))
|
|
79630
80149
|
}));
|
|
79631
80150
|
return (allowPattern) => {
|
|
79632
80151
|
if (budget.remaining === 0) return normalized.map(({ pattern }) => pattern);
|
|
79633
|
-
const allowGlob = parseGlobPattern(normalizePattern(allowPattern));
|
|
80152
|
+
const allowGlob = parseGlobPattern(widenForOverlap(normalizePattern(allowPattern)));
|
|
79634
80153
|
return normalized.filter(({ pattern, glob }) => pattern === allowPattern || parsedGlobsIntersect(glob, allowGlob, budget)).map(({ pattern }) => pattern);
|
|
79635
80154
|
};
|
|
79636
80155
|
}
|
|
@@ -79793,6 +80312,336 @@ function honorAllToolsOnBash(permission) {
|
|
|
79793
80312
|
bash: bashRulesHonoringAllTools(permission)
|
|
79794
80313
|
};
|
|
79795
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
|
+
}
|
|
79796
80645
|
// src/features/permissions/tool-pattern-entry.ts
|
|
79797
80646
|
/**
|
|
79798
80647
|
* Parse a `Tool(pattern)` permission entry (e.g. `Bash(npm run *)`) into its
|
|
@@ -79878,7 +80727,7 @@ const MATCH_ALL_PATH_GLOBS = /* @__PURE__ */ new Set([
|
|
|
79878
80727
|
"**/*"
|
|
79879
80728
|
]);
|
|
79880
80729
|
const DIRECTORY_CONTENTS_SUFFIX = /\/\*\*(?:\/\*)?$/;
|
|
79881
|
-
const HOME_OR_VARIABLE_PATH = /^~(
|
|
80730
|
+
const HOME_OR_VARIABLE_PATH = /^~(?:[A-Za-z_][\w.-]*)?(?:[/\\]|$)|^\$[A-Za-z_]|^%[A-Za-z_]\w*%|\$\{[A-Za-z_]/;
|
|
79882
80731
|
const LEADING_HOME = /^~(?:\/|$)/;
|
|
79883
80732
|
/**
|
|
79884
80733
|
* The home directory as an Antigravity path: forward slashes, no trailing
|
|
@@ -79893,7 +80742,7 @@ function toAntigravityHomePath(homeDirectory) {
|
|
|
79893
80742
|
* apply (rulesync#3324). Only a file the user's own home holds, such as the
|
|
79894
80743
|
* global Antigravity CLI settings, may carry a machine-specific path, so the
|
|
79895
80744
|
* caller passes `homeDirectory` only then. `$HOME`, `${HOME}`, `%VAR%` and
|
|
79896
|
-
* `~user/` are left as written
|
|
80745
|
+
* `~user/` are left as written and still warned about.
|
|
79897
80746
|
*/
|
|
79898
80747
|
function expandLeadingHome(target, homeDirectory) {
|
|
79899
80748
|
if (homeDirectory === void 0 || !LEADING_HOME.test(target)) return target;
|
|
@@ -79936,12 +80785,30 @@ function toPathTarget(pattern) {
|
|
|
79936
80785
|
"**",
|
|
79937
80786
|
"**/*"
|
|
79938
80787
|
].includes(path)) return { target: "." };
|
|
79939
|
-
const
|
|
80788
|
+
const stripped = path.replace(DIRECTORY_CONTENTS_SUFFIX, "");
|
|
80789
|
+
const directory = stripped === "" && path.startsWith("/") ? "/" : /^[A-Za-z]:$/.test(stripped) && stripped !== path ? `${stripped}/` : stripped;
|
|
79940
80790
|
if (directory !== path && directory.length > 0 && !hasGlob(directory)) return { target: directory };
|
|
79941
80791
|
if (!hasGlob(path)) return { target: path };
|
|
79942
80792
|
return { skipReason: "Antigravity file targets are paths, not globs. Only a plain path, `dir/**` or `*` can be expressed" };
|
|
79943
80793
|
}
|
|
79944
80794
|
/**
|
|
80795
|
+
* The canonical patterns a `read_file` / `write_file` target imports as. A
|
|
80796
|
+
* target can name a file or a directory, and a directory covers everything
|
|
80797
|
+
* inside it, but the target alone does not say which. A plain path such as
|
|
80798
|
+
* `src` imports as both `src` and `src/**`, so re-exporting it to a tool whose
|
|
80799
|
+
* plain path matches only that one path keeps covering the subtree; regenerating
|
|
80800
|
+
* collapses both back into one target. The bare `*`, and a target that already
|
|
80801
|
+
* holds glob characters (verbatim output of an older Rulesync), stay as written.
|
|
80802
|
+
*/
|
|
80803
|
+
function fromPathTarget(target) {
|
|
80804
|
+
if (target === "*" || hasGlob(target) || /^[A-Za-z]:$/.test(target)) return [target];
|
|
80805
|
+
if (target === ".") return [".", "./**"];
|
|
80806
|
+
const root = /^((?:[A-Za-z]:)?\/)\/*$/.exec(target)?.[1];
|
|
80807
|
+
if (root !== void 0) return [root, `${root}**`];
|
|
80808
|
+
const path = target.replace(/\/+$/, "");
|
|
80809
|
+
return [path, `${path}/**`];
|
|
80810
|
+
}
|
|
80811
|
+
/**
|
|
79945
80812
|
* A URL or domain pattern becomes its hostname. A leading `*.` is dropped,
|
|
79946
80813
|
* since a domain already covers its subdomains, and the URL path is ignored.
|
|
79947
80814
|
* Claude Code's `domain:` form is read as well.
|
|
@@ -80117,30 +80984,84 @@ function convertRulesyncToAntigravityPermissions({ config, toAction, toolLabel,
|
|
|
80117
80984
|
const allow = [];
|
|
80118
80985
|
const ask = [];
|
|
80119
80986
|
const deny = [];
|
|
80120
|
-
|
|
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)) {
|
|
80121
80994
|
const action = toAction(category);
|
|
80122
|
-
for (const [pattern,
|
|
80995
|
+
for (const [pattern, decision] of Object.entries(rules)) {
|
|
80123
80996
|
const entry = buildAntigravityPermissionEntry({
|
|
80124
80997
|
action,
|
|
80125
80998
|
category,
|
|
80126
80999
|
pattern,
|
|
80127
|
-
decision
|
|
81000
|
+
decision,
|
|
80128
81001
|
logger,
|
|
80129
81002
|
toolLabel,
|
|
80130
81003
|
homeDirectory
|
|
80131
81004
|
});
|
|
80132
|
-
|
|
80133
|
-
|
|
80134
|
-
|
|
80135
|
-
|
|
80136
|
-
|
|
80137
|
-
|
|
80138
|
-
|
|
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}`);
|
|
80139
81054
|
break;
|
|
80140
|
-
|
|
80141
|
-
|
|
81055
|
+
}
|
|
81056
|
+
allow.push(entry);
|
|
81057
|
+
break;
|
|
81058
|
+
case "ask":
|
|
81059
|
+
ask.push(entry);
|
|
81060
|
+
break;
|
|
81061
|
+
case "deny": deny.push(entry);
|
|
80142
81062
|
}
|
|
80143
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.`);
|
|
80144
81065
|
return {
|
|
80145
81066
|
allow: [...new Set(allow)],
|
|
80146
81067
|
ask: [...new Set(ask)],
|
|
@@ -80148,6 +81069,24 @@ function convertRulesyncToAntigravityPermissions({ config, toAction, toolLabel,
|
|
|
80148
81069
|
};
|
|
80149
81070
|
}
|
|
80150
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
|
+
/**
|
|
80151
81090
|
* Convert Antigravity allow/ask/deny arrays to rulesync permissions config,
|
|
80152
81091
|
* shared by the CLI and IDE adapters; `toCategory` maps the target's tool or
|
|
80153
81092
|
* action name back to a canonical category.
|
|
@@ -80158,19 +81097,21 @@ function convertAntigravityToRulesyncPermissions({ allow, ask, deny, toCategory,
|
|
|
80158
81097
|
for (const entry of entries) {
|
|
80159
81098
|
const { toolName, pattern: target } = parseToolPatternEntry(entry);
|
|
80160
81099
|
const canonical = toCategory(toolName);
|
|
80161
|
-
const
|
|
81100
|
+
const patterns = ANTIGRAVITY_COMMAND_ACTIONS.has(toolName) ? [importAntigravityCommandTarget({
|
|
80162
81101
|
target,
|
|
80163
81102
|
entry,
|
|
80164
81103
|
decision: action,
|
|
80165
81104
|
logger,
|
|
80166
81105
|
toolLabel
|
|
80167
|
-
}) : PATH_ACTIONS.has(toolName) ? collapseLeadingHome(target, homeDirectory) : target;
|
|
80168
|
-
|
|
80169
|
-
|
|
80170
|
-
|
|
80171
|
-
|
|
80172
|
-
|
|
80173
|
-
|
|
81106
|
+
})] : PATH_ACTIONS.has(toolName) ? fromPathTarget(collapseLeadingHome(target, homeDirectory)) : [target];
|
|
81107
|
+
for (const pattern of patterns) {
|
|
81108
|
+
if (isPrototypePollutionKey(canonical) || isPrototypePollutionKey(pattern)) continue;
|
|
81109
|
+
getOrCreateOwn({
|
|
81110
|
+
record: permission,
|
|
81111
|
+
key: canonical,
|
|
81112
|
+
create: () => ({})
|
|
81113
|
+
})[pattern] = action;
|
|
81114
|
+
}
|
|
80174
81115
|
}
|
|
80175
81116
|
};
|
|
80176
81117
|
processEntries(allow, "allow");
|
|
@@ -80941,6 +81882,10 @@ var AugmentcodePermissions = class AugmentcodePermissions extends ToolPermission
|
|
|
80941
81882
|
* in global mode it is dropped with a warning instead of written somewhere it
|
|
80942
81883
|
* does nothing.
|
|
80943
81884
|
*
|
|
81885
|
+
* Only Auggie 0.x reads `recommendedMarketplaces`: the 1.x plugin settings
|
|
81886
|
+
* reference lists `enabledPlugins` alone. The key is still written because the
|
|
81887
|
+
* stable CLI is 0.x, and the write warning says it is 0.x-only.
|
|
81888
|
+
*
|
|
80944
81889
|
* Both make Auggie load code the repository did not ship — a recommended
|
|
80945
81890
|
* marketplace is one prompt away from being cloned, and an enabled plugin can
|
|
80946
81891
|
* carry its own hooks and MCP servers — so writing either is logged, unless
|
|
@@ -80960,7 +81905,7 @@ function buildPluginConsumptionPatch({ override, existing, global, logger }) {
|
|
|
80960
81905
|
else {
|
|
80961
81906
|
patch.recommendedMarketplaces = recommendedMarketplaces;
|
|
80962
81907
|
const existingMarketplaces = existingKeys.recommendedMarketplaces;
|
|
80963
|
-
if (recommendedMarketplaces.length > 0 && !isDeepStrictEqual(recommendedMarketplaces, existingMarketplaces)) logger?.warn(`Writing AugmentCode \`recommendedMarketplaces\` (${recommendedMarketplaces.map(quoteValueForWarning).join(", ")}): Auggie prompts everyone who opens this workspace to install these plugin marketplaces.`);
|
|
81908
|
+
if (recommendedMarketplaces.length > 0 && !isDeepStrictEqual(recommendedMarketplaces, existingMarketplaces)) logger?.warn(`Writing AugmentCode \`recommendedMarketplaces\` (${recommendedMarketplaces.map(quoteValueForWarning).join(", ")}): Auggie 0.x prompts everyone who opens this workspace to install these plugin marketplaces (Auggie 1.x no longer reads this key).`);
|
|
80964
81909
|
warnAboutRemovedPluginIds({
|
|
80965
81910
|
key: "recommendedMarketplaces",
|
|
80966
81911
|
removed: (existingMarketplaces ?? []).filter((marketplace) => !recommendedMarketplaces.includes(marketplace)),
|
|
@@ -81042,15 +81987,21 @@ async function withBaseEnabledPlugins({ mergedContent, baseFilePath }) {
|
|
|
81042
81987
|
function convertRulesyncToAugmentEntries({ config, logger }) {
|
|
81043
81988
|
const entries = [];
|
|
81044
81989
|
const resolvedBashRules = bashRulesHonoringAllTools(config.permission);
|
|
81990
|
+
const honoredPermission = honorAllToolsRestrictions({
|
|
81991
|
+
permission: config.permission,
|
|
81992
|
+
toolLabel: "AugmentCode",
|
|
81993
|
+
logger,
|
|
81994
|
+
writesAllToolsCatchAll: true
|
|
81995
|
+
});
|
|
81045
81996
|
const permission = config.permission.bash !== void 0 || Object.keys(resolvedBashRules).length > 0 ? {
|
|
81046
|
-
...
|
|
81997
|
+
...honoredPermission,
|
|
81047
81998
|
bash: resolvedBashRules
|
|
81048
|
-
} :
|
|
81999
|
+
} : honoredPermission;
|
|
81049
82000
|
const allToolsFailClosedType = computeAllToolsFailClosedType(config.permission["*"]);
|
|
81050
82001
|
const categoriesWithOwnEntries = /* @__PURE__ */ new Set();
|
|
81051
82002
|
for (const [category, rules] of Object.entries(permission)) {
|
|
81052
82003
|
if (category === "*") {
|
|
81053
|
-
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
|
|
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.");
|
|
81054
82005
|
continue;
|
|
81055
82006
|
}
|
|
81056
82007
|
const augmentToolName = toAugmentToolName(category);
|
|
@@ -81109,9 +82060,10 @@ function computeAllToolsFailClosedType(allToolsRules) {
|
|
|
81109
82060
|
* other managed tools: one that produced no entries of its own above must not fall back to
|
|
81110
82061
|
* AugmentCode's own default just because it has no per-input matcher to narrow the all-tools
|
|
81111
82062
|
* restriction onto. A category can be stated yet still emit nothing (e.g. only non-`*` allow/ask
|
|
81112
|
-
* patterns, dropped with a warning
|
|
81113
|
-
*
|
|
81114
|
-
*
|
|
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.
|
|
81115
82067
|
*/
|
|
81116
82068
|
function synthesizeManagedToolFallbackEntries(categoriesWithOwnEntries, allToolsFailClosedType) {
|
|
81117
82069
|
if (allToolsFailClosedType === void 0) return [];
|
|
@@ -81189,12 +82141,12 @@ function convertAugmentToRulesyncPermissions({ entries, logger }) {
|
|
|
81189
82141
|
const regex = entry.shellInputRegex;
|
|
81190
82142
|
if (isShellRegexRoundtrippable(regex)) pattern = shellRegexToGlob(regex);
|
|
81191
82143
|
else {
|
|
81192
|
-
if (action
|
|
81193
|
-
logger?.warn(`AugmentCode permissions: skipping
|
|
82144
|
+
if (action === "allow" && !canApproximateShellRegexWithoutWidening(regex)) {
|
|
82145
|
+
logger?.warn(`AugmentCode permissions: skipping allow entry for tool '${entry.toolName}': shellInputRegex '${regex}' uses a quantifier or a literal '*' / '?' that a glob cannot express, and converting it would widen the rule. The entry is not imported.`);
|
|
81194
82146
|
continue;
|
|
81195
82147
|
}
|
|
81196
|
-
if (action
|
|
81197
|
-
logger?.warn(`AugmentCode permissions: shellInputRegex '${regex}' on tool '${entry.toolName}' is not faithfully roundtrippable to a glob. Importing as the catch-all '*' pattern (fail-closed) so
|
|
82148
|
+
if (action !== "allow") {
|
|
82149
|
+
logger?.warn(`AugmentCode permissions: shellInputRegex '${regex}' on tool '${entry.toolName}' is not faithfully roundtrippable to a glob. Importing the ${action} rule as the catch-all '*' pattern (fail-closed) so it cannot be silently narrowed on regenerate.`);
|
|
81198
82150
|
pattern = "*";
|
|
81199
82151
|
} else {
|
|
81200
82152
|
pattern = shellRegexToGlob(regex);
|
|
@@ -81280,6 +82232,62 @@ function classifyPattern(pattern, bareStarIsWildcard) {
|
|
|
81280
82232
|
};
|
|
81281
82233
|
return { kind: "literal" };
|
|
81282
82234
|
}
|
|
82235
|
+
/** The trimmed spellings of the literal (prefix) deny entries, minus the bare wildcard. */
|
|
82236
|
+
function collectLiteralDenyStems({ rules, bareStarIsWildcard }) {
|
|
82237
|
+
const stems = /* @__PURE__ */ new Set();
|
|
82238
|
+
for (const [pattern, action] of Object.entries(rules)) {
|
|
82239
|
+
if (action !== "deny" || pattern === "*") continue;
|
|
82240
|
+
const stem = pattern.trimEnd();
|
|
82241
|
+
if (stem.length > 0 && classifyPattern(pattern, bareStarIsWildcard).kind === "literal") stems.add(stem);
|
|
82242
|
+
}
|
|
82243
|
+
return stems;
|
|
82244
|
+
}
|
|
82245
|
+
function isCoveredByLiteralDeny({ pattern, literalDenyStems }) {
|
|
82246
|
+
if (!pattern.endsWith(" *")) return false;
|
|
82247
|
+
const stem = pattern.slice(0, -2).trimEnd();
|
|
82248
|
+
return stem.length > 0 && literalDenyStems.has(stem);
|
|
82249
|
+
}
|
|
82250
|
+
/**
|
|
82251
|
+
* Lower a VS Code style command allow/deny list pair into canonical `bash`
|
|
82252
|
+
* rules on import.
|
|
82253
|
+
*
|
|
82254
|
+
* The native entries are compared as literal command prefixes, while canonical
|
|
82255
|
+
* patterns are globs, so a verbatim copy changes their meaning:
|
|
82256
|
+
*
|
|
82257
|
+
* - A prefix deny such as `curl` blocks `curl https://…` natively but would
|
|
82258
|
+
* only block the exact command `curl` canonically, so a broad allow beside
|
|
82259
|
+
* it would auto-approve what the native config blocked. Each deny that does
|
|
82260
|
+
* not already end in `*` is imported as itself plus `<deny> *`.
|
|
82261
|
+
* - An allow holding glob syntax (`npm *`) is literal prefix text natively and
|
|
82262
|
+
* approves almost nothing, but canonically it is a wildcard. Such an allow is
|
|
82263
|
+
* not imported (with a warning) rather than imported wider than it matched.
|
|
82264
|
+
* The Roo Code lineage's bare `*` is a real wildcard natively and is kept.
|
|
82265
|
+
*
|
|
82266
|
+
* A pattern in both lists imports as `deny`, matching both tools' precedence
|
|
82267
|
+
* for identical entries.
|
|
82268
|
+
*/
|
|
82269
|
+
function importVscodeCommandLists({ allowed, denied, toolLabel, logger, prefixSemantics = "roo-lineage" }) {
|
|
82270
|
+
const isRooLineage = prefixSemantics === "roo-lineage";
|
|
82271
|
+
const rules = {};
|
|
82272
|
+
const skippedAllows = [];
|
|
82273
|
+
for (const pattern of allowed) {
|
|
82274
|
+
if (!(isRooLineage && pattern === "*") && /[*?]/.test(pattern)) {
|
|
82275
|
+
skippedAllows.push(pattern);
|
|
82276
|
+
continue;
|
|
82277
|
+
}
|
|
82278
|
+
rules[pattern] = "allow";
|
|
82279
|
+
}
|
|
82280
|
+
for (const pattern of denied) {
|
|
82281
|
+
rules[pattern] = "deny";
|
|
82282
|
+
const stem = pattern.trimEnd();
|
|
82283
|
+
if (!pattern.endsWith("*") && stem.length > 0) rules[`${stem} *`] = "deny";
|
|
82284
|
+
}
|
|
82285
|
+
if (skippedAllows.length > 0) {
|
|
82286
|
+
const count = skippedAllows.length;
|
|
82287
|
+
warnWithFallback(logger, `${toolLabel}: allow ${pluralize(count, "pattern", "patterns")} ${formatPatterns(skippedAllows)} ${pluralize(count, "was", "were")} not imported. ${toolLabel} compares ${pluralize(count, "it", "them")} as literal command prefix text, while a rulesync pattern is a glob, so importing ${pluralize(count, "it", "them")} would approve more commands than the native config does.` + (isRooLineage ? ` Only a bare "*" is a wildcard there.` : ""));
|
|
82288
|
+
}
|
|
82289
|
+
return rules;
|
|
82290
|
+
}
|
|
81283
82291
|
function pluralize(count, singular, plural) {
|
|
81284
82292
|
return count === 1 ? singular : plural;
|
|
81285
82293
|
}
|
|
@@ -81374,8 +82382,16 @@ function buildVscodeCommandLists({ rules, toolLabel, logger, prefixSemantics = "
|
|
|
81374
82382
|
const matcherAllows = [];
|
|
81375
82383
|
const widenedDenies = [];
|
|
81376
82384
|
const inertDenies = [];
|
|
82385
|
+
const literalDenyStems = collectLiteralDenyStems({
|
|
82386
|
+
rules,
|
|
82387
|
+
bareStarIsWildcard: isRooLineage
|
|
82388
|
+
});
|
|
81377
82389
|
for (const [pattern, action] of Object.entries(rules)) {
|
|
81378
82390
|
if (action !== "allow" && action !== "deny") continue;
|
|
82391
|
+
if (action === "deny" && isCoveredByLiteralDeny({
|
|
82392
|
+
pattern,
|
|
82393
|
+
literalDenyStems
|
|
82394
|
+
})) continue;
|
|
81379
82395
|
const shape = classifyPattern(pattern, isRooLineage);
|
|
81380
82396
|
if (action === "allow") {
|
|
81381
82397
|
allowed.push(pattern);
|
|
@@ -81738,16 +82754,20 @@ var BobPermissions = class BobPermissions extends ToolPermissions {
|
|
|
81738
82754
|
validate: true
|
|
81739
82755
|
});
|
|
81740
82756
|
}
|
|
81741
|
-
toRulesyncPermissions() {
|
|
82757
|
+
toRulesyncPermissions({ logger } = {}) {
|
|
81742
82758
|
const settings = parseBobSettings({
|
|
81743
82759
|
fileContent: this.getFileContent(),
|
|
81744
82760
|
filePath: join(this.getRelativeDirPath(), this.getRelativeFilePath())
|
|
81745
82761
|
});
|
|
81746
82762
|
const approval = settings[APPROVAL_KEY$1];
|
|
81747
82763
|
const entry = (isPlainObject(approval) && Array.isArray(approval.allowedExecutors) ? approval.allowedExecutors : []).find(isExecuteCommandEntry);
|
|
81748
|
-
const rules = {
|
|
81749
|
-
|
|
81750
|
-
|
|
82764
|
+
const rules = importVscodeCommandLists({
|
|
82765
|
+
allowed: toStringArray$1(entry?.approvedCommands),
|
|
82766
|
+
denied: toStringArray$1(entry?.deniedCommands),
|
|
82767
|
+
toolLabel: TOOL_LABEL,
|
|
82768
|
+
logger,
|
|
82769
|
+
prefixSemantics: "documented-prefix"
|
|
82770
|
+
});
|
|
81751
82771
|
const permission = {};
|
|
81752
82772
|
if (Object.keys(rules).length > 0) permission[SHELL_PERMISSION_CATEGORY] = rules;
|
|
81753
82773
|
const bob = readBobOverride(settings);
|
|
@@ -83507,8 +84527,10 @@ function categoryOfRule$2(rule) {
|
|
|
83507
84527
|
* - MCP rules take no specifier, so a scoped `mcp__<...>` category is written
|
|
83508
84528
|
* for its catch-all pattern only.
|
|
83509
84529
|
* - The all-tools `*` category is CodeBuddy's documented standalone `*` rule
|
|
83510
|
-
* for its catch-all pattern.
|
|
83511
|
-
*
|
|
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 *`.
|
|
83512
84534
|
*/
|
|
83513
84535
|
function buildCodebuddyRule({ category, pattern, action, logger }) {
|
|
83514
84536
|
const catchAll = pattern === "*";
|
|
@@ -83556,7 +84578,13 @@ function parseCodebuddyRule(rule) {
|
|
|
83556
84578
|
* manage (and every entry rulesync cannot parse).
|
|
83557
84579
|
*/
|
|
83558
84580
|
function buildCodebuddyRuleLists({ config, existingPermissions, logger }) {
|
|
83559
|
-
const permission =
|
|
84581
|
+
const permission = honorAllToolsRestrictions({
|
|
84582
|
+
permission: config.permission,
|
|
84583
|
+
toolLabel: "CodeBuddy",
|
|
84584
|
+
logger,
|
|
84585
|
+
restateAs: restatesAsCategoryRule(),
|
|
84586
|
+
writesAllToolsCatchAll: true
|
|
84587
|
+
});
|
|
83560
84588
|
const ranked = /* @__PURE__ */ new Map();
|
|
83561
84589
|
const managedCategories = /* @__PURE__ */ new Set();
|
|
83562
84590
|
for (const [category, rules] of Object.entries(permission)) {
|
|
@@ -85151,6 +86179,44 @@ function addCodexWebfetchRules({ rules, domains, logger }) {
|
|
|
85151
86179
|
domains[pattern] = action;
|
|
85152
86180
|
}
|
|
85153
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
|
+
}
|
|
85154
86220
|
function convertRulesyncToCodexProfile({ config, logger }) {
|
|
85155
86221
|
const filesystem = { [CODEX_MINIMAL_KEY]: "read" };
|
|
85156
86222
|
const workspaceRootFilesystem = {};
|
|
@@ -85162,8 +86228,24 @@ function convertRulesyncToCodexProfile({ config, logger }) {
|
|
|
85162
86228
|
continue;
|
|
85163
86229
|
}
|
|
85164
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
|
+
});
|
|
85165
86247
|
addCodexWebfetchRules({
|
|
85166
|
-
rules,
|
|
86248
|
+
rules: webfetchRules,
|
|
85167
86249
|
domains,
|
|
85168
86250
|
logger
|
|
85169
86251
|
});
|
|
@@ -85172,6 +86254,10 @@ function convertRulesyncToCodexProfile({ config, logger }) {
|
|
|
85172
86254
|
if (toolName === "bash") continue;
|
|
85173
86255
|
logger?.warn(`Codex CLI permission profiles support only read/edit/write/webfetch categories (bash goes to .codex/rules/rulesync.rules). Skipping: ${toolName}`);
|
|
85174
86256
|
}
|
|
86257
|
+
restateAllToolsPathRestrictions({
|
|
86258
|
+
config,
|
|
86259
|
+
filesystemCategoryRules
|
|
86260
|
+
});
|
|
85175
86261
|
addCodexFilesystemRules({
|
|
85176
86262
|
categoryRules: filesystemCategoryRules,
|
|
85177
86263
|
filesystem,
|
|
@@ -85511,7 +86597,7 @@ function computeCodexcliOverridePatch({ existing, override, logger }) {
|
|
|
85511
86597
|
const patch = {};
|
|
85512
86598
|
const allowed = new Set(CODEXCLI_OVERRIDE_KEYS);
|
|
85513
86599
|
for (const [key, value] of Object.entries(override ?? {})) {
|
|
85514
|
-
if (key === "base_permission_profile" || key === "git_write_rules") continue;
|
|
86600
|
+
if (key === "base_permission_profile" || key === "git_write_rules" || key === "bash_canonical_matching") continue;
|
|
85515
86601
|
if (!allowed.has(key)) {
|
|
85516
86602
|
logger?.warn(`Codex CLI permission override key "${key}" is not managed and was skipped. "permissions"/"default_permissions" are owned by the canonical permission model and "mcp_servers" gating by the MCP feature.`);
|
|
85517
86603
|
continue;
|
|
@@ -85800,6 +86886,7 @@ function stripTrailingSlash(pattern) {
|
|
|
85800
86886
|
function buildCodexBashRulesContent({ config, logger }) {
|
|
85801
86887
|
const bashRules = bashRulesHonoringAllTools(config.permission);
|
|
85802
86888
|
const entries = Object.entries(bashRules);
|
|
86889
|
+
const canonicalMatching = config.codexcli?.bash_canonical_matching === true;
|
|
85803
86890
|
const header = ["# Generated by Rulesync from .rulesync/permissions.jsonc (permission.bash)", "# https://developers.openai.com/codex/rules"];
|
|
85804
86891
|
if (entries.length === 0) return [...header, "# No bash permission rules were configured."].join("\n");
|
|
85805
86892
|
const ruleBlocks = entries.map(([pattern, action]) => {
|
|
@@ -85818,6 +86905,7 @@ function buildCodexBashRulesContent({ config, logger }) {
|
|
|
85818
86905
|
` pattern = [${serializedTokens}],`,
|
|
85819
86906
|
` decision = ${JSON.stringify(decision)},`,
|
|
85820
86907
|
` justification = ${JSON.stringify(`Generated from Rulesync permission.bash: ${pattern}`)},`,
|
|
86908
|
+
...canonicalMatching && decision !== "allow" ? [" canonical_matching = True,"] : [],
|
|
85821
86909
|
")"
|
|
85822
86910
|
].join("\n");
|
|
85823
86911
|
}).filter((block) => block !== null);
|
|
@@ -85913,8 +87001,10 @@ const PADDED_SHELL_WILDCARD_REASON = "a pattern narrower than the bare 'Shell' (
|
|
|
85913
87001
|
* server or tool). A pattern on an MCP category is still written as the
|
|
85914
87002
|
* `(specifier)` here; `writableCommandcodeRule` decides what to do with it,
|
|
85915
87003
|
* because Command Code ignores it. The all-tools `*` category is only
|
|
85916
|
-
* written for its catch-all pattern; narrower `*`
|
|
85917
|
-
*
|
|
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 *`.
|
|
85918
87008
|
*/
|
|
85919
87009
|
function buildCommandcodeRule(category, pattern) {
|
|
85920
87010
|
const catchAll = pattern === "*" || pattern === "";
|
|
@@ -86208,7 +87298,13 @@ function rankCommandcodeRule({ ranked, rule, action, logger }) {
|
|
|
86208
87298
|
* rewritten by `writableCommandcodeRule`.
|
|
86209
87299
|
*/
|
|
86210
87300
|
function buildCommandcodeRuleLists({ config, existingPermissions, logger }) {
|
|
86211
|
-
const permission =
|
|
87301
|
+
const permission = honorAllToolsRestrictions({
|
|
87302
|
+
permission: config.permission,
|
|
87303
|
+
toolLabel: "Command Code",
|
|
87304
|
+
logger,
|
|
87305
|
+
restateAs: restatesAsCategoryRule(),
|
|
87306
|
+
writesAllToolsCatchAll: true
|
|
87307
|
+
});
|
|
86212
87308
|
const ranked = /* @__PURE__ */ new Map();
|
|
86213
87309
|
const managedCategories = /* @__PURE__ */ new Set();
|
|
86214
87310
|
for (const [category, rules] of Object.entries(permission)) {
|
|
@@ -86668,7 +87764,13 @@ function convertRulesyncToContinuePermissions({ config, logger }) {
|
|
|
86668
87764
|
allow: []
|
|
86669
87765
|
};
|
|
86670
87766
|
const actionByEntry = /* @__PURE__ */ new Map();
|
|
86671
|
-
for (const [category, rules] of Object.entries(
|
|
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
|
+
}))) {
|
|
86672
87774
|
if (isPrototypePollutionKey(category)) continue;
|
|
86673
87775
|
const toolName = category === "*" ? "*" : toContinueToolName(category);
|
|
86674
87776
|
for (const [rawPattern, action] of Object.entries(rules)) {
|
|
@@ -87040,6 +88142,58 @@ function asAutoApproveMap(value) {
|
|
|
87040
88142
|
return result;
|
|
87041
88143
|
}
|
|
87042
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
|
+
/**
|
|
87043
88197
|
* Render one canonical category's rules as a VS Code auto-approve map. Returns
|
|
87044
88198
|
* `undefined` when the category contributes nothing, so the key is retracted
|
|
87045
88199
|
* rather than written as an empty object.
|
|
@@ -87117,11 +88271,14 @@ var CopilotPermissions = class CopilotPermissions extends ToolPermissions {
|
|
|
87117
88271
|
const config = rulesyncPermissions.getJson();
|
|
87118
88272
|
const patch = {};
|
|
87119
88273
|
for (const [category, settingKey] of Object.entries(AUTO_APPROVE_KEYS)) {
|
|
87120
|
-
|
|
87121
|
-
if (rules === void 0) continue;
|
|
88274
|
+
if (!Object.hasOwn(config.permission, category)) continue;
|
|
87122
88275
|
patch[settingKey] = buildAutoApproveValue({
|
|
87123
88276
|
category,
|
|
87124
|
-
rules
|
|
88277
|
+
rules: category === "bash" ? bashRulesHonoringAllTools(config.permission) : honorCopilotAllToolsRestrictions({
|
|
88278
|
+
permission: config.permission,
|
|
88279
|
+
category,
|
|
88280
|
+
logger
|
|
88281
|
+
})
|
|
87125
88282
|
});
|
|
87126
88283
|
}
|
|
87127
88284
|
const existingSettings = () => parseSharedConfig({
|
|
@@ -87222,6 +88379,15 @@ const DEFAULT_PERMISSION_MODE_KEY = "defaultPermissionMode";
|
|
|
87222
88379
|
function isCopilotcliDefaultPermissionMode(value) {
|
|
87223
88380
|
return COPILOTCLI_DEFAULT_PERMISSION_MODES.some((mode) => mode === value);
|
|
87224
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
|
+
}
|
|
87225
88391
|
function toUrlList(value) {
|
|
87226
88392
|
if (!Array.isArray(value)) return [];
|
|
87227
88393
|
return value.filter((entry) => typeof entry === "string");
|
|
@@ -87306,7 +88472,15 @@ var CopilotcliPermissions = class CopilotcliPermissions extends ToolPermissions
|
|
|
87306
88472
|
const filePath = join(outputRoot, paths.relativeDirPath, paths.relativeFilePath);
|
|
87307
88473
|
const existingContent = await readFileContentOrNull(filePath) ?? "{}";
|
|
87308
88474
|
const config = rulesyncPermissions.getJson();
|
|
87309
|
-
const rules =
|
|
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];
|
|
87310
88484
|
const patch = {};
|
|
87311
88485
|
if (rules !== void 0) {
|
|
87312
88486
|
const { allowedUrls, deniedUrls } = splitUrlRules(rules);
|
|
@@ -87402,9 +88576,126 @@ function toCanonicalToolName$5(crushName) {
|
|
|
87402
88576
|
function isMcpToolName(crushName) {
|
|
87403
88577
|
return crushName.startsWith(MCP_CRUSH_PREFIX) && crushName.length > 4;
|
|
87404
88578
|
}
|
|
88579
|
+
const CRUSH_COMMAND_WRAPPERS = /* @__PURE__ */ new Set([
|
|
88580
|
+
"env",
|
|
88581
|
+
"nohup",
|
|
88582
|
+
"nice",
|
|
88583
|
+
"timeout"
|
|
88584
|
+
]);
|
|
88585
|
+
const CRUSH_COMMAND_PREFIXES = [...CRUSH_COMMAND_WRAPPERS, "time"];
|
|
88586
|
+
const CRUSH_COMMAND_NAME = /^[a-z0-9_][a-z0-9_.+-]*$/;
|
|
88587
|
+
const CRUSH_COMMAND_ARGUMENT = /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
88588
|
+
const CRUSH_COMMAND_NAME_SUFFIXES = [
|
|
88589
|
+
".exe",
|
|
88590
|
+
".bat",
|
|
88591
|
+
".cmd"
|
|
88592
|
+
];
|
|
88593
|
+
function isCrushCommandName(name) {
|
|
88594
|
+
return CRUSH_COMMAND_NAME.test(name) && !CRUSH_COMMAND_NAME_SUFFIXES.some((suffix) => name.endsWith(suffix)) && !isPrototypePollutionKey(name);
|
|
88595
|
+
}
|
|
88596
|
+
/**
|
|
88597
|
+
* Reduce a command name the way Crush matches it (`shell.NormalizeCommandName`):
|
|
88598
|
+
* trimmed, without its directory, lower-cased, and without a Windows
|
|
88599
|
+
* executable suffix.
|
|
88600
|
+
*/
|
|
88601
|
+
function normalizeCrushCommandName(raw) {
|
|
88602
|
+
const base = (raw.trim().split(/[\\/]/).at(-1) ?? "").toLowerCase();
|
|
88603
|
+
const suffix = CRUSH_COMMAND_NAME_SUFFIXES.find((candidate) => base.length > candidate.length && base.endsWith(candidate));
|
|
88604
|
+
return suffix === void 0 ? base : base.slice(0, -suffix.length);
|
|
88605
|
+
}
|
|
88606
|
+
/**
|
|
88607
|
+
* Whether a canonical pattern is a literal command line that a Crush
|
|
88608
|
+
* `safe_commands` entry reproduces exactly: Crush matches an entry only when
|
|
88609
|
+
* the command is written with exactly those tokens, no extra arguments and no
|
|
88610
|
+
* flags, which is what a wildcard-free glob means. A leading wrapper is
|
|
88611
|
+
* refused, since Crush would resolve it away and approve the bare command.
|
|
88612
|
+
*/
|
|
88613
|
+
function isExactCrushCommandLine(pattern) {
|
|
88614
|
+
const [name, ...args] = pattern.split(" ");
|
|
88615
|
+
return name !== void 0 && isCrushCommandName(name) && !CRUSH_COMMAND_WRAPPERS.has(name) && args.every((arg) => CRUSH_COMMAND_ARGUMENT.test(arg));
|
|
88616
|
+
}
|
|
88617
|
+
/**
|
|
88618
|
+
* The command name a canonical `<name>` / `<name> *` pattern names as a
|
|
88619
|
+
* whole, i.e. the `blocked_commands` entry for it, or undefined.
|
|
88620
|
+
*/
|
|
88621
|
+
function wholeCommandName(pattern) {
|
|
88622
|
+
const name = pattern.endsWith(" *") ? pattern.slice(0, -2) : pattern;
|
|
88623
|
+
return isCrushCommandName(name) ? name : void 0;
|
|
88624
|
+
}
|
|
88625
|
+
/**
|
|
88626
|
+
* The line a Crush `safe_commands` entry effectively stands for, in canonical
|
|
88627
|
+
* form (whitespace collapsed, command name normalized), or undefined when the
|
|
88628
|
+
* entry has no exact canonical spelling (wildcards, quoting, a wrapper, ...).
|
|
88629
|
+
*/
|
|
88630
|
+
function effectiveSafeCommandLine(entry) {
|
|
88631
|
+
const [name, ...args] = entry.trim().split(/\s+/);
|
|
88632
|
+
if (name === void 0 || name === "") return void 0;
|
|
88633
|
+
const line = [normalizeCrushCommandName(name), ...args].join(" ");
|
|
88634
|
+
return isExactCrushCommandLine(line) ? line : void 0;
|
|
88635
|
+
}
|
|
88636
|
+
/**
|
|
88637
|
+
* A restriction pattern with its command word reduced the way Crush reduces a
|
|
88638
|
+
* wrapper's name before peeling it (`shell.NormalizeCommandName`): any
|
|
88639
|
+
* directory dropped (`./nice`, `bin\env.exe`, `/usr/bin/env`), lower-cased,
|
|
88640
|
+
* and without a Windows executable suffix. A `*` in the command word may
|
|
88641
|
+
* stand for a directory and part of a name, so when what follows it is the
|
|
88642
|
+
* tail of a wrapper name, everything before it collapses into `*`
|
|
88643
|
+
* (`b*nice` -> `*nice`, `/u*v` -> `*v`; `rm*` is left alone). The rest of the pattern is lower-cased as well, for a
|
|
88644
|
+
* nested wrapper spelled in another case. Used only to compare against the
|
|
88645
|
+
* wrapper spellings of a safe line, where it can only withhold more.
|
|
88646
|
+
*/
|
|
88647
|
+
function normalizeRestrictionCommandWord(pattern) {
|
|
88648
|
+
const space = pattern.indexOf(" ");
|
|
88649
|
+
let head = space < 0 ? pattern : pattern.slice(0, space);
|
|
88650
|
+
const rest = space < 0 ? "" : pattern.slice(space);
|
|
88651
|
+
head = normalizeCrushCommandName(head);
|
|
88652
|
+
const star = head.lastIndexOf("*");
|
|
88653
|
+
const tail = head.slice(star + 1);
|
|
88654
|
+
if (star > 0 && tail !== "" && CRUSH_COMMAND_PREFIXES.some((prefix) => prefix.endsWith(tail))) head = `*${tail}`;
|
|
88655
|
+
return `${head}${rest.toLowerCase()}`;
|
|
88656
|
+
}
|
|
88657
|
+
/**
|
|
88658
|
+
* Build the test for a `safe_commands` line: which canonical `deny`/`ask`
|
|
88659
|
+
* rules govern a command Crush would approve through it? Besides the line
|
|
88660
|
+
* itself, Crush approves it followed by `--` and behind a wrapper (or the
|
|
88661
|
+
* `time` keyword), whose name it normalizes (`./nice`, `/usr/bin/env`, `NICE`,
|
|
88662
|
+
* `nohup.exe`). The line and its wrapper spellings are compared against the
|
|
88663
|
+
* restrictions as written, and the wrapper spellings also against the
|
|
88664
|
+
* restrictions with their command word normalized the same way — which keeps
|
|
88665
|
+
* an unrelated `rm *` from withholding the line, as a leading wildcard on the
|
|
88666
|
+
* spelling would. Canonically the stricter rule wins whatever its width
|
|
88667
|
+
* (`deny > ask > allow`), so any overlap withholds the line.
|
|
88668
|
+
*
|
|
88669
|
+
* Crush also approves a line composed with other safe lines (`&&`, `||`, `|`,
|
|
88670
|
+
* `;`, a parenthesized group); those compositions are not compared, the way
|
|
88671
|
+
* other tools' per-subcommand matching treats an allowed command.
|
|
88672
|
+
*/
|
|
88673
|
+
function createSafeCommandShadowTest(permission) {
|
|
88674
|
+
const restrictions = collectShellCommandRules(permission).rules.filter(({ action }) => action !== "allow");
|
|
88675
|
+
const test = createShadowingRestrictionsTest(restrictions);
|
|
88676
|
+
const normalized = restrictions.map((rule) => ({
|
|
88677
|
+
...rule,
|
|
88678
|
+
pattern: normalizeRestrictionCommandWord(rule.pattern)
|
|
88679
|
+
}));
|
|
88680
|
+
const testNormalized = createShadowingRestrictionsTest(normalized);
|
|
88681
|
+
const originalOf = /* @__PURE__ */ new Map();
|
|
88682
|
+
normalized.forEach((rule, index) => {
|
|
88683
|
+
const original = restrictions[index]?.pattern;
|
|
88684
|
+
if (original !== void 0 && !originalOf.has(rule.pattern)) originalOf.set(rule.pattern, original);
|
|
88685
|
+
});
|
|
88686
|
+
const withSeparator = (spellings) => spellings.flatMap((spelling) => [spelling, `${spelling} --*`]);
|
|
88687
|
+
const wrapped = (base) => CRUSH_COMMAND_PREFIXES.map((prefix) => `${prefix}*${base}`);
|
|
88688
|
+
return (line) => uniq$1([...withSeparator([line, ...wrapped(line)]).flatMap((spelling) => test(spelling)), ...withSeparator(wrapped(line.toLowerCase())).flatMap((spelling) => testNormalized(spelling).map((pattern) => originalOf.get(pattern) ?? pattern))]);
|
|
88689
|
+
}
|
|
87405
88690
|
function uniq$1(values) {
|
|
87406
88691
|
return [...new Set(values)];
|
|
87407
88692
|
}
|
|
88693
|
+
function stringList(value) {
|
|
88694
|
+
return isStringArray(value) ? value : [];
|
|
88695
|
+
}
|
|
88696
|
+
function listOrUndefined(values) {
|
|
88697
|
+
return values.length > 0 ? values : void 0;
|
|
88698
|
+
}
|
|
87408
88699
|
/**
|
|
87409
88700
|
* Permissions adapter for Crush.
|
|
87410
88701
|
*
|
|
@@ -87426,8 +88717,24 @@ function uniq$1(values) {
|
|
|
87426
88717
|
* `webfetch` -> `fetch`, `mcp__<server>__<tool>` -> `mcp_<server>_<tool>`;
|
|
87427
88718
|
* any other category passes through verbatim.
|
|
87428
88719
|
*
|
|
87429
|
-
*
|
|
87430
|
-
*
|
|
88720
|
+
* Crush v0.100.0+ also carries two command lists, which the `bash` category's
|
|
88721
|
+
* pattern rules map onto (see `convertBashCommandRules`):
|
|
88722
|
+
* - `permissions.safe_commands`: exact command lines that skip the prompt
|
|
88723
|
+
* (no extra arguments, no flags) <- an `allow` on a literal command line
|
|
88724
|
+
* that no canonical `deny`/`ask` overlaps.
|
|
88725
|
+
* - `permissions.blocked_commands`: command names added to the dangerous
|
|
88726
|
+
* list <- a `deny` on `<name>` or `<name> *`. Not a full deny: a direct
|
|
88727
|
+
* invocation is still prompted for (and auto-approved in yolo mode or
|
|
88728
|
+
* through `allowed_tools: ["bash"]`); only the forms Crush would not
|
|
88729
|
+
* prompt for (its read-only commands, `safe_commands`) and indirect
|
|
88730
|
+
* invocations are refused at exec time. An `ask` is not written there,
|
|
88731
|
+
* since it would turn the read-only forms into a refusal.
|
|
88732
|
+
* `permissions.allowed_commands` only drops names from the dangerous list (the
|
|
88733
|
+
* commands keep prompting), so it has no canonical counterpart and is left
|
|
88734
|
+
* untouched.
|
|
88735
|
+
*
|
|
88736
|
+
* Any other pattern-specific rule cannot be expressed and is reported and
|
|
88737
|
+
* skipped. Because Crush cannot narrow an allowed tool, a category's catch-all `allow`
|
|
87431
88738
|
* is not written while the same category carries a pattern-specific `deny` or
|
|
87432
88739
|
* `ask`: the tool keeps prompting (fail closed) rather than being widened to
|
|
87433
88740
|
* everything. The all-tools `*` category is mirrored onto `bash` by
|
|
@@ -87491,7 +88798,12 @@ var CrushPermissions = class CrushPermissions extends ToolPermissions {
|
|
|
87491
88798
|
const existingContent = location.fileContent ?? "";
|
|
87492
88799
|
warnCrushTwinLeftovers({
|
|
87493
88800
|
location,
|
|
87494
|
-
ownedPaths: [
|
|
88801
|
+
ownedPaths: [
|
|
88802
|
+
[CRUSH_PERMISSIONS_KEY, CRUSH_ALLOWED_TOOLS_KEY],
|
|
88803
|
+
[CRUSH_PERMISSIONS_KEY, CRUSH_SAFE_COMMANDS_KEY],
|
|
88804
|
+
[CRUSH_PERMISSIONS_KEY, CRUSH_BLOCKED_COMMANDS_KEY],
|
|
88805
|
+
[CRUSH_OPTIONS_KEY, CRUSH_DISABLED_TOOLS_KEY]
|
|
88806
|
+
],
|
|
87495
88807
|
logger
|
|
87496
88808
|
});
|
|
87497
88809
|
const existing = parseCrushConfig(existingContent, location.filePath);
|
|
@@ -87503,12 +88815,22 @@ var CrushPermissions = class CrushPermissions extends ToolPermissions {
|
|
|
87503
88815
|
logger
|
|
87504
88816
|
});
|
|
87505
88817
|
const managedToolNames = managedCrushToolNames(config);
|
|
88818
|
+
const commands = rebuildCrushCommandLists({
|
|
88819
|
+
config,
|
|
88820
|
+
existingPermissions,
|
|
88821
|
+
logger
|
|
88822
|
+
});
|
|
87506
88823
|
const preservedAllowed = (isStringArray(existingPermissions?.["allowed_tools"]) ? existingPermissions[CRUSH_ALLOWED_TOOLS_KEY] : []).filter((entry) => entry.includes(":") || !managedToolNames.has(entry));
|
|
87507
88824
|
const preservedDisabled = (isStringArray(existingOptions?.["disabled_tools"]) ? existingOptions[CRUSH_DISABLED_TOOLS_KEY] : []).filter((entry) => !managedToolNames.has(entry));
|
|
87508
88825
|
const allowedList = uniq$1([...preservedAllowed, ...generated.allowed]);
|
|
87509
88826
|
const disabledList = uniq$1([...preservedDisabled, ...generated.disabled]);
|
|
88827
|
+
const permissionsHasContent = allowedList.length > 0 || commands.safe.length > 0 || commands.blocked.length > 0;
|
|
87510
88828
|
const patch = {};
|
|
87511
|
-
if (
|
|
88829
|
+
if (permissionsHasContent || existingPermissions !== void 0) patch[CRUSH_PERMISSIONS_KEY] = {
|
|
88830
|
+
[CRUSH_ALLOWED_TOOLS_KEY]: listOrUndefined(allowedList),
|
|
88831
|
+
[CRUSH_SAFE_COMMANDS_KEY]: listOrUndefined(commands.safe),
|
|
88832
|
+
[CRUSH_BLOCKED_COMMANDS_KEY]: listOrUndefined(commands.blocked)
|
|
88833
|
+
};
|
|
87512
88834
|
if (disabledList.length > 0 || existingOptions !== void 0) patch[CRUSH_OPTIONS_KEY] = { [CRUSH_DISABLED_TOOLS_KEY]: disabledList.length > 0 ? disabledList : void 0 };
|
|
87513
88835
|
return new CrushPermissions({
|
|
87514
88836
|
outputRoot,
|
|
@@ -87526,17 +88848,79 @@ var CrushPermissions = class CrushPermissions extends ToolPermissions {
|
|
|
87526
88848
|
global
|
|
87527
88849
|
});
|
|
87528
88850
|
}
|
|
87529
|
-
toRulesyncPermissions() {
|
|
88851
|
+
toRulesyncPermissions({ logger } = {}) {
|
|
87530
88852
|
const permissions = isRecord(this.json["permissions"]) ? this.json[CRUSH_PERMISSIONS_KEY] : {};
|
|
87531
88853
|
const options = toRecord(this.json[CRUSH_OPTIONS_KEY]);
|
|
87532
88854
|
const rulesyncConfig = convertCrushListsToRulesync({
|
|
87533
|
-
allowed:
|
|
87534
|
-
disabled:
|
|
88855
|
+
allowed: stringList(permissions[CRUSH_ALLOWED_TOOLS_KEY]),
|
|
88856
|
+
disabled: stringList(options[CRUSH_DISABLED_TOOLS_KEY]),
|
|
88857
|
+
safe: stringList(permissions[CRUSH_SAFE_COMMANDS_KEY]),
|
|
88858
|
+
blocked: stringList(permissions[CRUSH_BLOCKED_COMMANDS_KEY]),
|
|
88859
|
+
logger
|
|
87535
88860
|
});
|
|
87536
88861
|
return this.toRulesyncPermissionsDefault({ fileContent: JSON.stringify(rulesyncConfig, null, 2) });
|
|
87537
88862
|
}
|
|
87538
88863
|
};
|
|
87539
88864
|
/**
|
|
88865
|
+
* The `safe_commands` / `blocked_commands` lists a generate writes: the
|
|
88866
|
+
* existing entries rulesync keeps, followed by the ones derived from the
|
|
88867
|
+
* canonical `bash` rules. Existing `blocked_commands` entries are all kept:
|
|
88868
|
+
* rulesync cannot tell its own from hand-written ones, and dropping one only
|
|
88869
|
+
* ever loosens. A derived blocked name that is the command of a written safe
|
|
88870
|
+
* line is withheld, since Crush would refuse that line at exec time.
|
|
88871
|
+
*/
|
|
88872
|
+
function rebuildCrushCommandLists({ config, existingPermissions, logger }) {
|
|
88873
|
+
const bashRules = honorAllToolsOnBash(config.permission)["bash"] ?? {};
|
|
88874
|
+
const shadowTest = createSafeCommandShadowTest(config.permission);
|
|
88875
|
+
const generated = convertBashCommandRules({
|
|
88876
|
+
bashRules,
|
|
88877
|
+
shadowTest,
|
|
88878
|
+
logger
|
|
88879
|
+
});
|
|
88880
|
+
const safe = uniq$1([...preserveSafeCommands({
|
|
88881
|
+
existing: stringList(existingPermissions?.[CRUSH_SAFE_COMMANDS_KEY]),
|
|
88882
|
+
bashRules,
|
|
88883
|
+
shadowTest,
|
|
88884
|
+
logger
|
|
88885
|
+
}), ...generated.safe]);
|
|
88886
|
+
const safeCommandNames = new Set(safe.flatMap((entry) => {
|
|
88887
|
+
const name = entry.trim().split(/\s+/)[0];
|
|
88888
|
+
return name === void 0 || name === "" ? [] : [normalizeCrushCommandName(name)];
|
|
88889
|
+
}));
|
|
88890
|
+
const blocked = generated.blocked.filter((name) => {
|
|
88891
|
+
if (!safeCommandNames.has(name)) return true;
|
|
88892
|
+
logger?.warn(`The "deny" rule for "bash" on ${quoteValueForWarning(name)} is not added to permissions.blocked_commands because Crush would then refuse the allowed permissions.safe_commands line(s) for that command; Crush keeps prompting for it.`);
|
|
88893
|
+
return false;
|
|
88894
|
+
});
|
|
88895
|
+
const existingBlocked = stringList(existingPermissions?.[CRUSH_BLOCKED_COMMANDS_KEY]);
|
|
88896
|
+
for (const entry of existingBlocked) {
|
|
88897
|
+
if (!safeCommandNames.has(normalizeCrushCommandName(entry))) continue;
|
|
88898
|
+
logger?.warn(`The existing permissions.blocked_commands entry ${quoteValueForWarning(entry)} is kept, but Crush will refuse the permissions.safe_commands line(s) for that command at exec time; remove one of them by hand.`);
|
|
88899
|
+
}
|
|
88900
|
+
return {
|
|
88901
|
+
safe,
|
|
88902
|
+
blocked: uniq$1([...existingBlocked, ...blocked])
|
|
88903
|
+
};
|
|
88904
|
+
}
|
|
88905
|
+
/**
|
|
88906
|
+
* The existing `safe_commands` entries a generate keeps: those the canonical
|
|
88907
|
+
* `bash` rules do not spell out themselves (an entry they do spell is rebuilt
|
|
88908
|
+
* from them), minus any entry a canonical `deny`/`ask` governs, which would
|
|
88909
|
+
* otherwise auto-approve what the config restricts. An entry whose exact
|
|
88910
|
+
* meaning cannot be read is dropped whenever the config restricts anything.
|
|
88911
|
+
*/
|
|
88912
|
+
function preserveSafeCommands({ existing, bashRules, shadowTest, logger }) {
|
|
88913
|
+
const managedLines = new Set(Object.keys(bashRules));
|
|
88914
|
+
const restricts = shadowTest("*").length > 0;
|
|
88915
|
+
return existing.filter((entry) => {
|
|
88916
|
+
if (managedLines.has(entry)) return false;
|
|
88917
|
+
const line = effectiveSafeCommandLine(entry);
|
|
88918
|
+
const shadowed = line === void 0 ? restricts : shadowTest(line).length > 0;
|
|
88919
|
+
if (shadowed) logger?.warn(`Crush permissions.safe_commands entry ${quoteValueForWarning(entry)} was removed because a canonical deny/ask rule may cover the commands it approves.`);
|
|
88920
|
+
return !shadowed;
|
|
88921
|
+
});
|
|
88922
|
+
}
|
|
88923
|
+
/**
|
|
87540
88924
|
* The Crush tool names the canonical config manages, i.e. the names its
|
|
87541
88925
|
* categories map to. Entries naming any other tool are the user's and survive
|
|
87542
88926
|
* a generate. The all-tools `*` category names no Crush tool of its own.
|
|
@@ -87561,7 +88945,7 @@ function resolveCategoryAction({ category, toolName, rules, logger }) {
|
|
|
87561
88945
|
catchAllAction = action;
|
|
87562
88946
|
continue;
|
|
87563
88947
|
}
|
|
87564
|
-
logger?.warn(`Crush permissions are tool-wide (no argument patterns), so the "${action}" rule for "${category}" (pattern ${quoteValueForWarning(pattern)}) was skipped.`);
|
|
88948
|
+
if (category !== "bash") logger?.warn(`Crush permissions are tool-wide (no argument patterns), so the "${action}" rule for "${category}" (pattern ${quoteValueForWarning(pattern)}) was skipped.`);
|
|
87565
88949
|
if (action !== "allow") restricted = true;
|
|
87566
88950
|
}
|
|
87567
88951
|
if (catchAllAction === "allow" && restricted) {
|
|
@@ -87575,6 +88959,26 @@ function resolveCategoryAction({ category, toolName, rules, logger }) {
|
|
|
87575
88959
|
return catchAllAction;
|
|
87576
88960
|
}
|
|
87577
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
|
+
/**
|
|
87578
88982
|
* Convert a rulesync permissions config into Crush's two tool lists.
|
|
87579
88983
|
*/
|
|
87580
88984
|
function convertRulesyncToCrushLists({ config, logger }) {
|
|
@@ -87583,7 +88987,10 @@ function convertRulesyncToCrushLists({ config, logger }) {
|
|
|
87583
88987
|
disabled: []
|
|
87584
88988
|
};
|
|
87585
88989
|
const actionByTool = /* @__PURE__ */ new Map();
|
|
87586
|
-
for (const [category, rules] of Object.entries(
|
|
88990
|
+
for (const [category, rules] of Object.entries(honorCrushAllToolsRestrictions({
|
|
88991
|
+
config,
|
|
88992
|
+
logger
|
|
88993
|
+
}))) {
|
|
87587
88994
|
if (isPrototypePollutionKey(category)) continue;
|
|
87588
88995
|
if (category === "*") {
|
|
87589
88996
|
for (const [rawPattern, action] of Object.entries(rules)) {
|
|
@@ -87612,11 +89019,71 @@ function convertRulesyncToCrushLists({ config, logger }) {
|
|
|
87612
89019
|
};
|
|
87613
89020
|
}
|
|
87614
89021
|
/**
|
|
89022
|
+
* Map the `bash` category's pattern rules onto Crush's command lists:
|
|
89023
|
+
* - `allow` on a literal command line -> `permissions.safe_commands`, which
|
|
89024
|
+
* Crush matches exactly (no extra arguments, no flags). It is withheld
|
|
89025
|
+
* when a canonical `deny`/`ask` governs any command Crush would approve
|
|
89026
|
+
* through it.
|
|
89027
|
+
* - `deny` on `<name>` / `<name> *` -> `permissions.blocked_commands`, the
|
|
89028
|
+
* strictest Crush can say about a single command: a direct invocation is
|
|
89029
|
+
* still prompted for, while the forms Crush would not prompt for and
|
|
89030
|
+
* indirect invocations are refused at exec time. Reported, since it is
|
|
89031
|
+
* not a full deny.
|
|
89032
|
+
* - Anything else is reported and skipped. A pattern `ask` is never written
|
|
89033
|
+
* to `blocked_commands`, which would refuse the command's read-only forms
|
|
89034
|
+
* outright, and an `allow` with a wildcard has no list that auto-approves
|
|
89035
|
+
* it.
|
|
89036
|
+
*/
|
|
89037
|
+
function convertBashCommandRules({ bashRules, shadowTest, logger }) {
|
|
89038
|
+
const lists = {
|
|
89039
|
+
safe: [],
|
|
89040
|
+
blocked: []
|
|
89041
|
+
};
|
|
89042
|
+
for (const [rawPattern, action] of Object.entries(bashRules)) {
|
|
89043
|
+
if (isPrototypePollutionKey(rawPattern)) continue;
|
|
89044
|
+
const pattern = normalizeCatchAllPattern(rawPattern);
|
|
89045
|
+
if (pattern === "*") continue;
|
|
89046
|
+
const quoted = quoteValueForWarning(pattern);
|
|
89047
|
+
if (action === "allow") {
|
|
89048
|
+
if (!isExactCrushCommandLine(pattern)) {
|
|
89049
|
+
logger?.warn(`Crush auto-approves a command only as an exact line in permissions.safe_commands (no wildcards or shell syntax), so the "allow" rule for "bash" (pattern ${quoted}) was skipped; Crush keeps prompting for it.`);
|
|
89050
|
+
continue;
|
|
89051
|
+
}
|
|
89052
|
+
const shadows = shadowTest(pattern);
|
|
89053
|
+
if (shadows.length > 0) {
|
|
89054
|
+
logger?.warn(`The "allow" rule for "bash" (pattern ${quoted}) is not added to permissions.safe_commands because the deny/ask rule(s) ${shadows.map(quoteValueForWarning).join(", ")} also cover commands Crush would approve through it; Crush keeps prompting for it.`);
|
|
89055
|
+
continue;
|
|
89056
|
+
}
|
|
89057
|
+
lists.safe.push(pattern);
|
|
89058
|
+
continue;
|
|
89059
|
+
}
|
|
89060
|
+
if (action === "ask") {
|
|
89061
|
+
logger?.warn(`Crush has no per-command prompt list (permissions.blocked_commands would refuse the command's read-only forms outright), so the "ask" rule for "bash" (pattern ${quoted}) was skipped; Crush still prompts for it unless it is one of Crush's built-in read-only commands.`);
|
|
89062
|
+
continue;
|
|
89063
|
+
}
|
|
89064
|
+
const name = wholeCommandName(pattern);
|
|
89065
|
+
if (name !== void 0 && CRUSH_COMMAND_PREFIXES.includes(name)) {
|
|
89066
|
+
logger?.warn(`Crush resolves the command wrapper or keyword ${quoteValueForWarning(name)} before matching permissions.blocked_commands, so an entry for it would have no effect; the "deny" rule for "bash" (pattern ${quoted}) was skipped and Crush still prompts for it.`);
|
|
89067
|
+
continue;
|
|
89068
|
+
}
|
|
89069
|
+
if (name === void 0) {
|
|
89070
|
+
logger?.warn(`Crush can only restrict a whole command (permissions.blocked_commands), so the "deny" rule for "bash" (pattern ${quoted}) was skipped; Crush still prompts for it unless it is one of Crush's built-in read-only commands.`);
|
|
89071
|
+
continue;
|
|
89072
|
+
}
|
|
89073
|
+
logger?.warn(`The "deny" rule for "bash" (pattern ${quoted}) is written as permissions.blocked_commands entry ${quoteValueForWarning(name)}, which is not a full deny: Crush still prompts for a direct invocation (and runs it unprompted in yolo mode or with "bash" in allowed_tools).`);
|
|
89074
|
+
lists.blocked.push(name);
|
|
89075
|
+
}
|
|
89076
|
+
return {
|
|
89077
|
+
safe: uniq$1(lists.safe),
|
|
89078
|
+
blocked: uniq$1(lists.blocked)
|
|
89079
|
+
};
|
|
89080
|
+
}
|
|
89081
|
+
/**
|
|
87615
89082
|
* Convert Crush's two tool lists back into a rulesync config. A `tool:action`
|
|
87616
89083
|
* entry scopes an allow to one action of a tool, which the canonical model
|
|
87617
89084
|
* cannot express, so it is left out rather than widened to the whole tool.
|
|
87618
89085
|
*/
|
|
87619
|
-
function convertCrushListsToRulesync({ allowed, disabled }) {
|
|
89086
|
+
function convertCrushListsToRulesync({ allowed, disabled, safe, blocked, logger }) {
|
|
87620
89087
|
const permission = {};
|
|
87621
89088
|
const bucketFor = (category) => {
|
|
87622
89089
|
const own = lookupOwn({
|
|
@@ -87632,6 +89099,29 @@ function convertCrushListsToRulesync({ allowed, disabled }) {
|
|
|
87632
89099
|
if (entry === "" || isPrototypePollutionKey(entry)) continue;
|
|
87633
89100
|
bucketFor(toCanonicalToolName$5(entry))["*"] = "deny";
|
|
87634
89101
|
}
|
|
89102
|
+
const setBashRule = (pattern, action) => {
|
|
89103
|
+
const bucket = bucketFor(SHELL_PERMISSION_CATEGORY);
|
|
89104
|
+
if (!Object.hasOwn(bucket, pattern)) bucket[pattern] = action;
|
|
89105
|
+
};
|
|
89106
|
+
for (const entry of blocked) {
|
|
89107
|
+
const name = normalizeCrushCommandName(entry);
|
|
89108
|
+
if (name === "") continue;
|
|
89109
|
+
if (!isCrushCommandName(name)) {
|
|
89110
|
+
logger?.warn(`Crush permissions.blocked_commands entry ${quoteValueForWarning(entry)} is not a plain command name, so it was not imported.`);
|
|
89111
|
+
continue;
|
|
89112
|
+
}
|
|
89113
|
+
setBashRule(name, "deny");
|
|
89114
|
+
setBashRule(`${name} *`, "deny");
|
|
89115
|
+
}
|
|
89116
|
+
for (const entry of safe) {
|
|
89117
|
+
if (entry.trim() === "") continue;
|
|
89118
|
+
const line = effectiveSafeCommandLine(entry);
|
|
89119
|
+
if (line === void 0) {
|
|
89120
|
+
logger?.warn(`Crush permissions.safe_commands entry ${quoteValueForWarning(entry)} has no exact rulesync pattern (wildcards, shell syntax or a command wrapper), so it was not imported.`);
|
|
89121
|
+
continue;
|
|
89122
|
+
}
|
|
89123
|
+
setBashRule(line, "allow");
|
|
89124
|
+
}
|
|
87635
89125
|
for (const entry of allowed) {
|
|
87636
89126
|
if (entry === "" || entry.includes(":") || isPrototypePollutionKey(entry)) continue;
|
|
87637
89127
|
bucketFor(toCanonicalToolName$5(entry))["*"] ??= "allow";
|
|
@@ -87945,7 +89435,17 @@ var CursorPermissions = class CursorPermissions extends ToolPermissions {
|
|
|
87945
89435
|
function convertRulesyncToCursorPermissions(config, logger) {
|
|
87946
89436
|
const allow = [];
|
|
87947
89437
|
const deny = [];
|
|
87948
|
-
|
|
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)) {
|
|
87949
89449
|
const cursorType = toCursorType(category);
|
|
87950
89450
|
for (const [pattern, action] of Object.entries(rules)) {
|
|
87951
89451
|
const entry = buildToolPatternEntry({
|
|
@@ -89011,8 +90511,8 @@ const DEVIN_RESTRICTION_LOSING_SANDBOX_PATHS = [
|
|
|
89011
90511
|
* In global mode the config file is shared with the hooks (`hooks`) feature
|
|
89012
90512
|
* (MCP moved to the dedicated mcp_config.json in v3000.3), so reads and writes
|
|
89013
90513
|
* merge into the existing JSON and the file is never deleted; only the keys
|
|
89014
|
-
* this feature manages are rewritten — `permissions`, plus `sandbox`
|
|
89015
|
-
* mode and the plugin governance lists (`requiredPlugins` / `optionalPlugins` /
|
|
90514
|
+
* this feature manages are rewritten — `permissions`, plus `sandbox` and
|
|
90515
|
+
* `permission_mode` in global mode and the plugin governance lists (`requiredPlugins` / `optionalPlugins` /
|
|
89016
90516
|
* `forbiddenPlugins`) in project mode when the `devin` override authors them.
|
|
89017
90517
|
*
|
|
89018
90518
|
* The sibling `sandbox` block — which decides what a permitted command may
|
|
@@ -89120,6 +90620,12 @@ var DevinPermissions = class DevinPermissions extends ToolPermissions {
|
|
|
89120
90620
|
});
|
|
89121
90621
|
} else if (Object.keys(authoredSandboxRecord).length > 0) logger?.warn("Devin reads 'sandbox' from the user config only, so the 'devin.sandbox' override was dropped from the project config. Generate with --global to author it.");
|
|
89122
90622
|
}
|
|
90623
|
+
applyPermissionModeOverride({
|
|
90624
|
+
permissionMode: config.devin?.permission_mode,
|
|
90625
|
+
patch,
|
|
90626
|
+
global,
|
|
90627
|
+
logger
|
|
90628
|
+
});
|
|
89123
90629
|
applyPluginGovernanceOverride({
|
|
89124
90630
|
override: config.devin,
|
|
89125
90631
|
settings,
|
|
@@ -89163,6 +90669,12 @@ var DevinPermissions = class DevinPermissions extends ToolPermissions {
|
|
|
89163
90669
|
if (DEVIN_PLUGIN_GOVERNANCE_SCHEMAS[key].safeParse(value).success) devinOverride[key] = value;
|
|
89164
90670
|
else logger?.warn(`Skipped Devin \`${key}\` on import: ${key === "forbiddenPlugins" ? "expected an array of strings" : "expected an array of plugin sources (strings or objects)"}.`);
|
|
89165
90671
|
}
|
|
90672
|
+
const permissionMode = importPermissionMode({
|
|
90673
|
+
value: settings.permission_mode,
|
|
90674
|
+
isGlobalFile: toPosixPath(this.getRelativeDirPath()) === toPosixPath(DevinPermissions.getSettablePaths({ global: true }).relativeDirPath),
|
|
90675
|
+
logger
|
|
90676
|
+
});
|
|
90677
|
+
if (permissionMode !== void 0) devinOverride.permission_mode = permissionMode;
|
|
89166
90678
|
const result = { ...config };
|
|
89167
90679
|
if (Object.keys(devinOverride).length > 0) result.devin = devinOverride;
|
|
89168
90680
|
return this.toRulesyncPermissionsDefault({ fileContent: JSON.stringify(result, null, 2) });
|
|
@@ -89179,6 +90691,48 @@ const DEVIN_PLUGIN_GOVERNANCE_KEYS = [
|
|
|
89179
90691
|
"forbiddenPlugins"
|
|
89180
90692
|
];
|
|
89181
90693
|
/**
|
|
90694
|
+
* Decide what an imported `permission_mode` contributes to the `devin`
|
|
90695
|
+
* override. It is lifted from the user config only: unlike `sandbox`, a
|
|
90696
|
+
* project value Devin ignores is skipped with a warning rather than surfaced,
|
|
90697
|
+
* so it cannot slip into a `--global` generate later. `null` is Devin's
|
|
90698
|
+
* spelling of the default and carries nothing to keep; any other value the
|
|
90699
|
+
* override schema would reject is dropped with a warning so the next generate
|
|
90700
|
+
* cannot fail. `dangerous` is lifted but named, as on generate.
|
|
90701
|
+
*/
|
|
90702
|
+
function importPermissionMode({ value, isGlobalFile, logger }) {
|
|
90703
|
+
if (value === void 0 || value === null) return void 0;
|
|
90704
|
+
if (!isGlobalFile) {
|
|
90705
|
+
logger?.warn("Skipped Devin `permission_mode` on import: Devin reads it from the user config only, so the project config's value has no effect. Import with --global to lift it.");
|
|
90706
|
+
return;
|
|
90707
|
+
}
|
|
90708
|
+
const parsed = DevinPermissionModeSchema.safeParse(value);
|
|
90709
|
+
if (!parsed.success) {
|
|
90710
|
+
logger?.warn(`Skipped Devin \`permission_mode\` ${quoteValueForWarning(value)} on import: expected one of ${DevinPermissionModeSchema.options.join(", ")}.`);
|
|
90711
|
+
return;
|
|
90712
|
+
}
|
|
90713
|
+
if (parsed.data === "dangerous") logger?.warn("Imported Devin `permission_mode: \"dangerous\"`: every new local session starts with all permission prompts bypassed, and the next --global generate writes it back.");
|
|
90714
|
+
return parsed.data;
|
|
90715
|
+
}
|
|
90716
|
+
/**
|
|
90717
|
+
* Patch the `permission_mode` the `devin` override authors into the user
|
|
90718
|
+
* `config.json`. It sets the mode new local sessions start in, and Devin reads
|
|
90719
|
+
* it from the user config only, so in project mode it is dropped with a
|
|
90720
|
+
* warning. It is only ever written as authored — never derived from the
|
|
90721
|
+
* canonical rules — and `dangerous` is named in a warning, because every new
|
|
90722
|
+
* session then starts with all permission prompts bypassed.
|
|
90723
|
+
*
|
|
90724
|
+
* @see https://docs.devin.ai/cli/reference/configuration/config-file
|
|
90725
|
+
*/
|
|
90726
|
+
function applyPermissionModeOverride({ permissionMode, patch, global, logger }) {
|
|
90727
|
+
if (permissionMode === void 0) return;
|
|
90728
|
+
if (!global) {
|
|
90729
|
+
logger?.warn("Devin reads 'permission_mode' from the user config only, so the 'devin.permission_mode' override was dropped from the project config. Generate with --global to author it.");
|
|
90730
|
+
return;
|
|
90731
|
+
}
|
|
90732
|
+
patch.permission_mode = permissionMode;
|
|
90733
|
+
if (permissionMode === "dangerous") logger?.warn("Writing Devin `permission_mode: \"dangerous\"` to the user config: every new local session then starts with all permission prompts bypassed.");
|
|
90734
|
+
}
|
|
90735
|
+
/**
|
|
89182
90736
|
* Patch the plugin governance lists the `devin` override authors into the
|
|
89183
90737
|
* project `.devin/config.json`. Each authored list replaces the file's list
|
|
89184
90738
|
* whole; a list it does not author is left as the file holds it. Devin reads these
|
|
@@ -89236,7 +90790,11 @@ function convertRulesyncToDevinPermissions({ config, logger }) {
|
|
|
89236
90790
|
case "deny": deny.push(entry);
|
|
89237
90791
|
}
|
|
89238
90792
|
};
|
|
89239
|
-
for (const [category, rules] of Object.entries(
|
|
90793
|
+
for (const [category, rules] of Object.entries(honorAllToolsRestrictions({
|
|
90794
|
+
permission: config.permission,
|
|
90795
|
+
toolLabel: "Devin",
|
|
90796
|
+
logger
|
|
90797
|
+
}))) {
|
|
89240
90798
|
const scope = toDevinScope(category);
|
|
89241
90799
|
if (DEVIN_BARE_ONLY_SCOPES.has(scope)) {
|
|
89242
90800
|
const action = collapseBareOnlyScopeRules({
|
|
@@ -89980,7 +91538,12 @@ function unmanagedEntries(existingPermission, key) {
|
|
|
89980
91538
|
*/
|
|
89981
91539
|
function buildGrokPermissionArrays(config, existingPermission, logger) {
|
|
89982
91540
|
const ranked = /* @__PURE__ */ new Map();
|
|
89983
|
-
for (const [category, rules] of Object.entries(
|
|
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)) {
|
|
89984
91547
|
const entry = buildGrokEntry(category, pattern);
|
|
89985
91548
|
if (entry === null) {
|
|
89986
91549
|
if (category === "*") {
|
|
@@ -90039,7 +91602,7 @@ function warnRemovedAllToolsRestrictions({ existingPermission, ranked, logger })
|
|
|
90039
91602
|
* Warn about entries that a bare `*` `deny`/`ask` makes ineffective: Grok
|
|
90040
91603
|
* evaluates by severity (`deny > ask > allow`), so a specific `allow` (and,
|
|
90041
91604
|
* under a `*` deny, a specific `ask`) never takes effect next to it. Shell
|
|
90042
|
-
* rules are already folded by `
|
|
91605
|
+
* rules are already folded by `honorAllToolsRestrictions`, so this covers the other
|
|
90043
91606
|
* tools.
|
|
90044
91607
|
*/
|
|
90045
91608
|
function warnEntriesShadowedByAllTools({ ranked, logger }) {
|
|
@@ -90796,7 +92359,12 @@ var JuniePermissions = class JuniePermissions extends ToolPermissions {
|
|
|
90796
92359
|
*/
|
|
90797
92360
|
function convertRulesyncToJunieRules({ config, logger, existingRules, overrideSecretFile, overrideRuleDefaults }) {
|
|
90798
92361
|
const ruleLists = {};
|
|
90799
|
-
|
|
92362
|
+
const permission = honorAllToolsRestrictions({
|
|
92363
|
+
permission: config.permission,
|
|
92364
|
+
toolLabel: "Junie allowlist",
|
|
92365
|
+
logger
|
|
92366
|
+
});
|
|
92367
|
+
for (const [category, patterns] of Object.entries(permission)) {
|
|
90800
92368
|
const group = lookupOwn({
|
|
90801
92369
|
record: CANONICAL_TO_JUNIE_GROUP,
|
|
90802
92370
|
key: category
|
|
@@ -90824,13 +92392,16 @@ function convertRulesyncToJunieRules({ config, logger, existingRules, overrideSe
|
|
|
90824
92392
|
if (list === void 0 && groupDefault === void 0) continue;
|
|
90825
92393
|
rules[group] = {
|
|
90826
92394
|
...groupDefault !== void 0 && { default: groupDefault },
|
|
90827
|
-
rules: list
|
|
92395
|
+
rules: list === void 0 ? [] : sortRestrictionsFirst(list)
|
|
90828
92396
|
};
|
|
90829
92397
|
}
|
|
90830
92398
|
const secretFile = overrideSecretFile ?? toRuleSet(existingRules[JUNIE_SECRET_FILE_GROUP]);
|
|
90831
92399
|
if (secretFile !== void 0) rules[JUNIE_SECRET_FILE_GROUP] = sanitizeRuleSet(secretFile);
|
|
90832
92400
|
return rules;
|
|
90833
92401
|
}
|
|
92402
|
+
function sortRestrictionsFirst(list) {
|
|
92403
|
+
return [...list.filter((rule) => rule.action !== "allow"), ...list.filter((rule) => rule.action === "allow")];
|
|
92404
|
+
}
|
|
90834
92405
|
/**
|
|
90835
92406
|
* Map a canonical action onto a valid Junie allowlist action. Junie supports
|
|
90836
92407
|
* only `allow` and `ask`; a canonical `deny` is downgraded to `ask` (the
|
|
@@ -90876,6 +92447,69 @@ function convertJunieToRulesyncPermissions({ allowlist }) {
|
|
|
90876
92447
|
readSecretFile
|
|
90877
92448
|
};
|
|
90878
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
|
+
}
|
|
90879
92513
|
// src/features/permissions/kilo-permissions.ts
|
|
90880
92514
|
const KiloPermissionSchema = z.union([z.enum([
|
|
90881
92515
|
"allow",
|
|
@@ -91091,7 +92725,7 @@ var KiloPermissions = class KiloPermissions extends ToolPermissions {
|
|
|
91091
92725
|
const rulesyncJson = rulesyncPermissions.getJson();
|
|
91092
92726
|
const kiloOverride = rulesyncJson.kilo;
|
|
91093
92727
|
const incomingPermission = {
|
|
91094
|
-
...honorAllToolsOnBash(rulesyncJson.permission),
|
|
92728
|
+
...restateAllToolsRestrictionsLast(honorAllToolsOnBash(rulesyncJson.permission)),
|
|
91095
92729
|
...kiloOverride?.permission
|
|
91096
92730
|
};
|
|
91097
92731
|
if (!global && Object.hasOwn(incomingPermission, KILO_MARKDOWN_SOURCE_KEY)) {
|
|
@@ -91296,7 +92930,12 @@ function warnAboutMistypedToolLists(section) {
|
|
|
91296
92930
|
function canonicalToKimiCodeRules({ config, logger }) {
|
|
91297
92931
|
const canonicalRules = [];
|
|
91298
92932
|
const overrideRules = config["kimi-code"]?.rules ?? [];
|
|
91299
|
-
|
|
92933
|
+
const permission = honorAllToolsRestrictions({
|
|
92934
|
+
permission: config.permission,
|
|
92935
|
+
toolLabel: "Kimi Code",
|
|
92936
|
+
logger
|
|
92937
|
+
});
|
|
92938
|
+
for (const [category, rules] of Object.entries(permission)) {
|
|
91300
92939
|
if (!(category === "mcp" || category.startsWith("mcp__") || lookupOwn({
|
|
91301
92940
|
record: CATEGORY_TO_KIMI_CODE_TOOL,
|
|
91302
92941
|
key: category
|
|
@@ -92143,7 +93782,11 @@ var KiroCapabilityPermissions = class KiroCapabilityPermissions extends ToolPerm
|
|
|
92143
93782
|
*/
|
|
92144
93783
|
function buildKiroCapabilityRules({ config, logger }) {
|
|
92145
93784
|
const buckets = /* @__PURE__ */ new Map();
|
|
92146
|
-
for (const [category, rules] of Object.entries(
|
|
93785
|
+
for (const [category, rules] of Object.entries(honorAllToolsRestrictions({
|
|
93786
|
+
permission: config.permission,
|
|
93787
|
+
toolLabel: "Kiro",
|
|
93788
|
+
logger
|
|
93789
|
+
}))) {
|
|
92147
93790
|
const capability = lookupOwn({
|
|
92148
93791
|
record: CANONICAL_TO_KIRO_CAPABILITY,
|
|
92149
93792
|
key: category
|
|
@@ -92351,7 +93994,12 @@ function fromLettacodeRule(rule) {
|
|
|
92351
93994
|
* absent from the config).
|
|
92352
93995
|
*/
|
|
92353
93996
|
function buildLettacodeRuleLists({ config, existingPermissions, logger }) {
|
|
92354
|
-
const permission =
|
|
93997
|
+
const permission = honorAllToolsRestrictions({
|
|
93998
|
+
permission: config.permission,
|
|
93999
|
+
toolLabel: "Letta Code",
|
|
94000
|
+
logger,
|
|
94001
|
+
restateAs: restatesAsCategoryRule()
|
|
94002
|
+
});
|
|
92355
94003
|
const ranked = /* @__PURE__ */ new Map();
|
|
92356
94004
|
const managedCategories = /* @__PURE__ */ new Set();
|
|
92357
94005
|
for (const [category, rules] of Object.entries(permission)) {
|
|
@@ -92771,7 +94419,7 @@ function toOpencodeSharedPermission({ permission, toolTarget, logger }) {
|
|
|
92771
94419
|
sharedPermission[key] = merged;
|
|
92772
94420
|
} else sharedPermission[key] = value;
|
|
92773
94421
|
}
|
|
92774
|
-
return sharedPermission;
|
|
94422
|
+
return restateAllToolsRestrictionsLast(sharedPermission);
|
|
92775
94423
|
}
|
|
92776
94424
|
const OpencodePermissionsConfigSchema = z.looseObject({
|
|
92777
94425
|
permission: z.optional(z.union([z.enum([
|
|
@@ -93596,7 +95244,7 @@ function listPatterns(patterns) {
|
|
|
93596
95244
|
* - `mcp__<server>__<tool>` is skipped: Pool approves MCP tools per server
|
|
93597
95245
|
* under `mcp_servers.<server>.allow`, authored as `poolAllow` in
|
|
93598
95246
|
* `.rulesync/mcp.json`. The all-tools `*` category is mirrored onto
|
|
93599
|
-
* `bash` by `
|
|
95247
|
+
* `bash` by `honorAllToolsRestrictions` and otherwise skipped.
|
|
93600
95248
|
*
|
|
93601
95249
|
* Project settings take project-relative paths and the user settings absolute
|
|
93602
95250
|
* or `~` paths, so a path of the other kind is skipped with a warning at each
|
|
@@ -93689,7 +95337,11 @@ var PoolPermissions = class PoolPermissions extends ToolPermissions {
|
|
|
93689
95337
|
* `tools: {}` / `paths: {}`.
|
|
93690
95338
|
*/
|
|
93691
95339
|
function buildPoolPermissionsPatch({ config, existing, global, logger }) {
|
|
93692
|
-
const permission =
|
|
95340
|
+
const permission = honorAllToolsRestrictions({
|
|
95341
|
+
permission: config.permission,
|
|
95342
|
+
toolLabel: "Pool",
|
|
95343
|
+
logger
|
|
95344
|
+
});
|
|
93693
95345
|
const existingTools = isRecord(existing["tools"]) ? existing[POOL_TOOLS_KEY] : void 0;
|
|
93694
95346
|
const existingPaths = isRecord(existing["paths"]) ? existing[POOL_PATHS_KEY] : void 0;
|
|
93695
95347
|
const patch = {};
|
|
@@ -94129,8 +95781,10 @@ function categoryOfRule(rule) {
|
|
|
94129
95781
|
* when Qoder has no spelling for it.
|
|
94130
95782
|
*
|
|
94131
95783
|
* - The all-tools `*` category is Qoder's bare `*` rule; a narrower pattern
|
|
94132
|
-
* under it names no single tool and is skipped
|
|
94133
|
-
* already
|
|
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 *`.
|
|
94134
95788
|
* - An `mcp__...` category is a fully qualified MCP tool name (or a Qoder MCP
|
|
94135
95789
|
* wildcard like `mcp__github__*`) and only takes the catch-all pattern.
|
|
94136
95790
|
* - Every other category maps to its Qoder tool name; `*` is the bare tool
|
|
@@ -94182,7 +95836,13 @@ function fromQoderRule(rule) {
|
|
|
94182
95836
|
* ...). An existing entry this run writes is moved to its new list.
|
|
94183
95837
|
*/
|
|
94184
95838
|
function buildQoderRuleLists({ config, existingPermissions, logger }) {
|
|
94185
|
-
const permission =
|
|
95839
|
+
const permission = honorAllToolsRestrictions({
|
|
95840
|
+
permission: config.permission,
|
|
95841
|
+
toolLabel: "Qoder",
|
|
95842
|
+
logger,
|
|
95843
|
+
restateAs: restatesAsCategoryRule(),
|
|
95844
|
+
writesAllToolsCatchAll: true
|
|
95845
|
+
});
|
|
94186
95846
|
const ranked = /* @__PURE__ */ new Map();
|
|
94187
95847
|
const managedCategories = /* @__PURE__ */ new Set();
|
|
94188
95848
|
for (const [category, rules] of Object.entries(permission)) {
|
|
@@ -94995,7 +96655,10 @@ var QwencodePermissions = class QwencodePermissions extends ToolPermissions {
|
|
|
94995
96655
|
}
|
|
94996
96656
|
const displayPath = toPosixPath(join(global ? "~" : ".", paths.relativeDirPath, paths.relativeFilePath));
|
|
94997
96657
|
const config = rulesyncPermissions.getJson();
|
|
94998
|
-
const { allow, ask, deny } = convertRulesyncToQwenPermissions(
|
|
96658
|
+
const { allow, ask, deny } = convertRulesyncToQwenPermissions({
|
|
96659
|
+
config,
|
|
96660
|
+
logger
|
|
96661
|
+
});
|
|
94999
96662
|
const managedToolNames = new Set(Object.keys(config.permission).map((category) => toQwenToolName(category)));
|
|
95000
96663
|
const existingPermissions = settings.permissions ?? {};
|
|
95001
96664
|
const preservedAllow = (existingPermissions.allow ?? []).filter((entry) => !managedToolNames.has(parseQwenPermissionEntry(entry, { logger }).toolName));
|
|
@@ -95100,11 +96763,17 @@ var QwencodePermissions = class QwencodePermissions extends ToolPermissions {
|
|
|
95100
96763
|
}
|
|
95101
96764
|
}
|
|
95102
96765
|
};
|
|
95103
|
-
function convertRulesyncToQwenPermissions(config) {
|
|
96766
|
+
function convertRulesyncToQwenPermissions({ config, logger }) {
|
|
95104
96767
|
const allow = [];
|
|
95105
96768
|
const ask = [];
|
|
95106
96769
|
const deny = [];
|
|
95107
|
-
|
|
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)) {
|
|
95108
96777
|
const qwenToolName = toQwenToolName(category);
|
|
95109
96778
|
for (const [pattern, action] of Object.entries(rules)) {
|
|
95110
96779
|
const entry = buildToolPatternEntry({
|
|
@@ -95168,7 +96837,8 @@ function convertQwenToRulesyncPermissions(params) {
|
|
|
95168
96837
|
*
|
|
95169
96838
|
* Reasonix matches a rule's tool exactly against its registered tools, which
|
|
95170
96839
|
* are snake_case (`read_file`, `write_file`, `grep`, `glob`, `web_fetch`,
|
|
95171
|
-
* `web_search`, `notebook_edit`, `task`
|
|
96840
|
+
* `web_search`, `notebook_edit`, and `task` up to v2.57.x / `spawn_agents` from
|
|
96841
|
+
* v2.58.0). Only `Bash`, `Edit` (every file
|
|
95172
96842
|
* writer: `write_file`, `edit_file`, `multi_edit`, `notebook_edit`, ...),
|
|
95173
96843
|
* `Browser` and `Computer` are Claude-Code-style family aliases
|
|
95174
96844
|
* (`canonicalRuleTool` / `groupOf`), so a `Read(...)` or `Write(...)` rule
|
|
@@ -95191,6 +96861,21 @@ const CANONICAL_TO_REASONIX_TOOL_NAMES = {
|
|
|
95191
96861
|
agent: "task"
|
|
95192
96862
|
};
|
|
95193
96863
|
/**
|
|
96864
|
+
* Reasonix tool names a canonical category writes beside its primary name, for
|
|
96865
|
+
* a tool Reasonix renamed. studio-v2.58.0 replaced the `task` delegation family
|
|
96866
|
+
* with `spawn_agents` (commit ad2c96347), while the 1.x line and v2 up to
|
|
96867
|
+
* v2.57.x still register `task`. When Reasonix loads the config file it checks
|
|
96868
|
+
* only a rule's syntax: a rule naming a tool the running build lacks matches
|
|
96869
|
+
* nothing (v2.34.0+ reports it as dormant) and is not rejected. (The v2 Web UI
|
|
96870
|
+
* permissions editor refuses to newly add such a rule with `ErrUnknownTool`,
|
|
96871
|
+
* but keeps the ones already in the file.) So writing both names keeps an
|
|
96872
|
+
* `agent` rule in force on old and new builds alike. Both names are read back
|
|
96873
|
+
* to the same category.
|
|
96874
|
+
* @see https://github.com/esengine/DeepSeek-Reasonix/blob/studio-v2.58.0/internal/runtime/delegation/spawn.go
|
|
96875
|
+
* @see https://github.com/esengine/DeepSeek-Reasonix/blob/studio-v2.57.0/internal/runtime/delegation/task.go
|
|
96876
|
+
*/
|
|
96877
|
+
const CANONICAL_TO_EXTRA_REASONIX_TOOL_NAMES = { agent: ["spawn_agents"] };
|
|
96878
|
+
/**
|
|
95194
96879
|
* The Claude-Code-style spellings rulesync emitted before it followed the
|
|
95195
96880
|
* Reasonix tool vocabulary. None of them reaches a Reasonix tool, so they are
|
|
95196
96881
|
* read back on import (a file generated by an older rulesync still imports)
|
|
@@ -95213,7 +96898,8 @@ const CANONICAL_TO_LEGACY_REASONIX_TOOL_NAMES = {
|
|
|
95213
96898
|
*/
|
|
95214
96899
|
const REASONIX_TO_CANONICAL_TOOL_NAMES = {
|
|
95215
96900
|
...invertRecord(CANONICAL_TO_LEGACY_REASONIX_TOOL_NAMES),
|
|
95216
|
-
...invertRecord(CANONICAL_TO_REASONIX_TOOL_NAMES)
|
|
96901
|
+
...invertRecord(CANONICAL_TO_REASONIX_TOOL_NAMES),
|
|
96902
|
+
...Object.fromEntries(Object.entries(CANONICAL_TO_EXTRA_REASONIX_TOOL_NAMES).flatMap(([canonical, names]) => names.map((name) => [name, canonical])))
|
|
95217
96903
|
};
|
|
95218
96904
|
/** Every Reasonix tool name a canonical category owns on generate. */
|
|
95219
96905
|
function reasonixToolNamesOf(canonical) {
|
|
@@ -95221,14 +96907,20 @@ function reasonixToolNamesOf(canonical) {
|
|
|
95221
96907
|
record: CANONICAL_TO_LEGACY_REASONIX_TOOL_NAMES,
|
|
95222
96908
|
key: canonical
|
|
95223
96909
|
});
|
|
95224
|
-
const current =
|
|
95225
|
-
return legacy === void 0 ?
|
|
96910
|
+
const current = toReasonixToolNames(canonical);
|
|
96911
|
+
return legacy === void 0 ? current : [...current, legacy];
|
|
95226
96912
|
}
|
|
95227
|
-
|
|
95228
|
-
|
|
96913
|
+
/** The Reasonix tool names a canonical category's rules are written under. */
|
|
96914
|
+
function toReasonixToolNames(canonical) {
|
|
96915
|
+
const primary = lookupOwn({
|
|
95229
96916
|
record: CANONICAL_TO_REASONIX_TOOL_NAMES,
|
|
95230
96917
|
key: canonical
|
|
95231
96918
|
}) ?? canonical;
|
|
96919
|
+
const extra = lookupOwn({
|
|
96920
|
+
record: CANONICAL_TO_EXTRA_REASONIX_TOOL_NAMES,
|
|
96921
|
+
key: canonical
|
|
96922
|
+
});
|
|
96923
|
+
return extra === void 0 ? [primary] : [primary, ...extra];
|
|
95232
96924
|
}
|
|
95233
96925
|
function toCanonicalToolName$2(reasonixName) {
|
|
95234
96926
|
return lookupOwn({
|
|
@@ -95610,7 +97302,10 @@ var ReasonixPermissions = class ReasonixPermissions extends ToolPermissions {
|
|
|
95610
97302
|
const existingContent = await readFileContentOrNull(filePath) ?? "";
|
|
95611
97303
|
const parsed = parseReasonixConfig(existingContent);
|
|
95612
97304
|
const config = rulesyncPermissions.getJson();
|
|
95613
|
-
const { allow, ask, deny } = convertRulesyncToReasonixPermissions(
|
|
97305
|
+
const { allow, ask, deny } = convertRulesyncToReasonixPermissions({
|
|
97306
|
+
config,
|
|
97307
|
+
logger
|
|
97308
|
+
});
|
|
95614
97309
|
const managedToolNames = new Set(Object.keys(config.permission).flatMap((category) => reasonixToolNamesOf(category)));
|
|
95615
97310
|
const override = config.reasonix;
|
|
95616
97311
|
const rawAllow = toStringArray$1(override?.rawAllow);
|
|
@@ -95636,6 +97331,17 @@ var ReasonixPermissions = class ReasonixPermissions extends ToolPermissions {
|
|
|
95636
97331
|
});
|
|
95637
97332
|
if (droppedReadDenyEntries.length > 0) logger.warn(`Permissions feature manages '${REASONIX_READ_TOOL_NAME}' tool and will overwrite ${droppedReadDenyEntries.length} existing read deny entries (possibly from ignore feature). Permissions take precedence.`);
|
|
95638
97333
|
}
|
|
97334
|
+
warnOnLoosenedAgentEntries({
|
|
97335
|
+
existingPermissions,
|
|
97336
|
+
managedToolNames,
|
|
97337
|
+
generated: {
|
|
97338
|
+
allow: [...allow, ...rawAllow],
|
|
97339
|
+
ask: [...ask, ...rawAsk],
|
|
97340
|
+
deny: [...deny, ...rawDeny]
|
|
97341
|
+
},
|
|
97342
|
+
relativeFilePath: relativeFilePathForLog,
|
|
97343
|
+
logger
|
|
97344
|
+
});
|
|
95639
97345
|
const mergedPermissions = { ...existingPermissions };
|
|
95640
97346
|
setOrDeleteEntries(mergedPermissions, "allow", [
|
|
95641
97347
|
...preservedAllow,
|
|
@@ -95811,6 +97517,55 @@ function preserveExistingEntries({ existingPermissions, managedToolNames, rawOwn
|
|
|
95811
97517
|
deny
|
|
95812
97518
|
};
|
|
95813
97519
|
}
|
|
97520
|
+
/**
|
|
97521
|
+
* `spawn_agents` became a managed name with Reasonix v2.58.0 support, so a
|
|
97522
|
+
* stricter rule the user wrote for it by hand (e.g. a v2.58-era
|
|
97523
|
+
* `deny = ["spawn_agents"]` next to an older `agent: allow` source) would be
|
|
97524
|
+
* silently replaced by a looser one. Name every such loosening.
|
|
97525
|
+
*/
|
|
97526
|
+
function warnOnLoosenedAgentEntries({ existingPermissions, managedToolNames, generated, relativeFilePath, logger }) {
|
|
97527
|
+
if (!logger || !managedToolNames.has("spawn_agents")) return;
|
|
97528
|
+
const loosened = findLoosenedEntries({
|
|
97529
|
+
existingPermissions,
|
|
97530
|
+
toolNames: new Set(reasonixToolNamesOf("agent")),
|
|
97531
|
+
generated
|
|
97532
|
+
});
|
|
97533
|
+
if (loosened.length === 0) return;
|
|
97534
|
+
logger.warn(`Permissions feature manages the Reasonix delegation tools ('task', 'spawn_agents') through the 'agent' category and will replace ${loosened.length} stricter existing entries in ${relativeFilePath}: ${loosened.join(", ")}. To keep them, tighten the 'agent' category in ${RULESYNC_RELATIVE_DIR_PATH}/${RULESYNC_PERMISSIONS_FILE_NAME} or move them to 'reasonix.rawDeny' / 'reasonix.rawAsk'.`);
|
|
97535
|
+
}
|
|
97536
|
+
const PERMISSION_STRICTNESS = {
|
|
97537
|
+
allow: 0,
|
|
97538
|
+
ask: 1,
|
|
97539
|
+
deny: 2
|
|
97540
|
+
};
|
|
97541
|
+
/**
|
|
97542
|
+
* Existing entries for `toolNames` whose action is stricter than the one the
|
|
97543
|
+
* generated lists give the same entry, formatted `<list> "<entry>"`. An entry
|
|
97544
|
+
* the generated lists drop counts as no stricter than `allow`.
|
|
97545
|
+
*/
|
|
97546
|
+
function findLoosenedEntries({ existingPermissions, toolNames, generated }) {
|
|
97547
|
+
const generatedStrictness = /* @__PURE__ */ new Map();
|
|
97548
|
+
for (const list of [
|
|
97549
|
+
"allow",
|
|
97550
|
+
"ask",
|
|
97551
|
+
"deny"
|
|
97552
|
+
]) for (const entry of generated[list]) {
|
|
97553
|
+
const key = normalizeToolPatternEntry(entry);
|
|
97554
|
+
generatedStrictness.set(key, Math.max(generatedStrictness.get(key) ?? 0, PERMISSION_STRICTNESS[list]));
|
|
97555
|
+
}
|
|
97556
|
+
const loosened = [];
|
|
97557
|
+
for (const list of ["ask", "deny"]) for (const entry of toStringArray$1(existingPermissions[list])) {
|
|
97558
|
+
if (isReasonixExactCommandEntry(entry)) continue;
|
|
97559
|
+
if (!toolNames.has(parseToolPatternEntry(entry).toolName)) continue;
|
|
97560
|
+
const key = normalizeToolPatternEntry(entry);
|
|
97561
|
+
if ((generatedStrictness.get(key) ?? 0) < PERMISSION_STRICTNESS[list]) loosened.push(`${list} "${entry}"`);
|
|
97562
|
+
}
|
|
97563
|
+
return loosened;
|
|
97564
|
+
}
|
|
97565
|
+
/** Spell an entry the way rulesync writes it, so `name(*)` equals `name`. */
|
|
97566
|
+
function normalizeToolPatternEntry(entry) {
|
|
97567
|
+
return buildToolPatternEntry(parseToolPatternEntry(entry));
|
|
97568
|
+
}
|
|
95814
97569
|
/** Sort, dedupe and set a permissions array key, deleting it when empty. */
|
|
95815
97570
|
function setOrDeleteEntries(table, key, entries) {
|
|
95816
97571
|
const merged = uniq(entries.toSorted());
|
|
@@ -95820,26 +97575,28 @@ function setOrDeleteEntries(table, key, entries) {
|
|
|
95820
97575
|
/**
|
|
95821
97576
|
* Convert rulesync permissions config to Reasonix allow/ask/deny arrays.
|
|
95822
97577
|
*/
|
|
95823
|
-
function convertRulesyncToReasonixPermissions(config) {
|
|
97578
|
+
function convertRulesyncToReasonixPermissions({ config, logger }) {
|
|
95824
97579
|
const allow = [];
|
|
95825
97580
|
const ask = [];
|
|
95826
97581
|
const deny = [];
|
|
95827
|
-
|
|
95828
|
-
|
|
95829
|
-
|
|
95830
|
-
|
|
95831
|
-
|
|
95832
|
-
|
|
95833
|
-
|
|
95834
|
-
|
|
95835
|
-
|
|
95836
|
-
|
|
95837
|
-
|
|
95838
|
-
|
|
95839
|
-
|
|
95840
|
-
|
|
95841
|
-
|
|
95842
|
-
|
|
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)) {
|
|
97588
|
+
const entry = buildToolPatternEntry({
|
|
97589
|
+
toolName: reasonixToolName,
|
|
97590
|
+
pattern
|
|
97591
|
+
});
|
|
97592
|
+
switch (action) {
|
|
97593
|
+
case "allow":
|
|
97594
|
+
allow.push(entry);
|
|
97595
|
+
break;
|
|
97596
|
+
case "ask":
|
|
97597
|
+
ask.push(entry);
|
|
97598
|
+
break;
|
|
97599
|
+
case "deny": deny.push(entry);
|
|
95843
97600
|
}
|
|
95844
97601
|
}
|
|
95845
97602
|
return {
|
|
@@ -96066,7 +97823,7 @@ var RooPermissions = class extends ToolPermissions {
|
|
|
96066
97823
|
validate: true
|
|
96067
97824
|
});
|
|
96068
97825
|
}
|
|
96069
|
-
toRulesyncPermissions() {
|
|
97826
|
+
toRulesyncPermissions({ logger } = {}) {
|
|
96070
97827
|
const constructor = this.constructor;
|
|
96071
97828
|
let settings;
|
|
96072
97829
|
try {
|
|
@@ -96080,9 +97837,12 @@ var RooPermissions = class extends ToolPermissions {
|
|
|
96080
97837
|
} catch (error) {
|
|
96081
97838
|
throw new Error(`Failed to parse ${constructor.getToolLabel()} VS Code settings in ${join(this.getRelativeDirPath(), this.getRelativeFilePath())}: ${formatError(error)}`, { cause: error });
|
|
96082
97839
|
}
|
|
96083
|
-
const rules = {
|
|
96084
|
-
|
|
96085
|
-
|
|
97840
|
+
const rules = importVscodeCommandLists({
|
|
97841
|
+
allowed: toStringArray$1(settings[constructor.getAllowedCommandsKey()]),
|
|
97842
|
+
denied: toStringArray$1(settings[constructor.getDeniedCommandsKey()]),
|
|
97843
|
+
toolLabel: constructor.getToolLabel(),
|
|
97844
|
+
logger
|
|
97845
|
+
});
|
|
96086
97846
|
const permission = {};
|
|
96087
97847
|
if (Object.keys(rules).length > 0) permission[COMMAND_CATEGORY] = rules;
|
|
96088
97848
|
return this.toRulesyncPermissionsDefault({ fileContent: JSON.stringify({ permission }, null, 2) });
|
|
@@ -97844,14 +99604,19 @@ async function readTaktRuntimeConfig({ outputRoot, logger }) {
|
|
|
97844
99604
|
/**
|
|
97845
99605
|
* Collapse a rulesync permissions config into Takt's single coarse mode.
|
|
97846
99606
|
*
|
|
97847
|
-
* Precedence: any `deny` ⇒ `readonly`; else an `edit`/`write` `allow`
|
|
97848
|
-
* 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`.
|
|
97849
99614
|
*/
|
|
97850
99615
|
function deriveTaktPermissionMode(config) {
|
|
97851
99616
|
let hasEditAllow = false;
|
|
97852
99617
|
let hasBashAllow = false;
|
|
97853
99618
|
for (const [category, rules] of Object.entries(config.permission)) for (const action of Object.values(rules)) {
|
|
97854
|
-
if (action === "deny") return "readonly";
|
|
99619
|
+
if (action === "deny" || action === "ask") return "readonly";
|
|
97855
99620
|
if (action === "allow") {
|
|
97856
99621
|
if (category === "edit" || category === "write") hasEditAllow = true;
|
|
97857
99622
|
else if (category === "bash") hasBashAllow = true;
|
|
@@ -98134,7 +99899,12 @@ function buildMcpRules({ permission, existing, logger }) {
|
|
|
98134
99899
|
/** Split the canonical `webfetch` rules into TRAE's network allow/deny lists. */
|
|
98135
99900
|
function buildNetworkLists({ webfetchRules, logger }) {
|
|
98136
99901
|
const ranked = /* @__PURE__ */ new Map();
|
|
98137
|
-
|
|
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)) {
|
|
98138
99908
|
if (isPrototypePollutionKey(pattern)) continue;
|
|
98139
99909
|
if (pattern === "*") {
|
|
98140
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.`);
|
|
@@ -98262,7 +100032,11 @@ var TraePermissions = class TraePermissions extends ToolPermissions {
|
|
|
98262
100032
|
fileContent: existingContent,
|
|
98263
100033
|
relativePath
|
|
98264
100034
|
});
|
|
98265
|
-
const permission =
|
|
100035
|
+
const permission = honorAllToolsRestrictions({
|
|
100036
|
+
permission: rulesyncPermissions.getJson().permission,
|
|
100037
|
+
toolLabel: "TRAE",
|
|
100038
|
+
logger
|
|
100039
|
+
});
|
|
98266
100040
|
warnUnmappedCategories({
|
|
98267
100041
|
permission,
|
|
98268
100042
|
logger
|
|
@@ -98511,7 +100285,18 @@ var VibePermissions = class VibePermissions extends ToolPermissions {
|
|
|
98511
100285
|
const filePath = join(outputRoot, paths.relativeDirPath, paths.relativeFilePath);
|
|
98512
100286
|
const existingContent = await readFileContentOrNull(filePath) ?? "";
|
|
98513
100287
|
const config = parseVibeConfig(existingContent);
|
|
98514
|
-
const 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
|
+
});
|
|
98515
100300
|
const vibeOverride = rulesyncPermissions.getJson().vibe;
|
|
98516
100301
|
const tools = toVibeToolsRecord(config.tools);
|
|
98517
100302
|
const diskShellPatterns = new Map([VIBE_SHELL_CATEGORY, ...VIBE_SHELL_ALIAS_TOOL_NAMES].map((vibeToolName) => [vibeToolName, toStringArray$1(readVibeToolConfig({
|
|
@@ -98560,6 +100345,12 @@ var VibePermissions = class VibePermissions extends ToolPermissions {
|
|
|
98560
100345
|
logger
|
|
98561
100346
|
});
|
|
98562
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
|
+
});
|
|
98563
100354
|
for (const [category, rules] of tableCategories) {
|
|
98564
100355
|
const vibeToolNames = resolveNames(category);
|
|
98565
100356
|
if (vibeToolNames === void 0) {
|
|
@@ -98944,6 +100735,49 @@ function applyCategoryRulesToTool({ vibeToolName, category, rules, tools, enable
|
|
|
98944
100735
|
tools[vibeToolName] = nextTool;
|
|
98945
100736
|
}
|
|
98946
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
|
+
/**
|
|
98947
100781
|
* `enabled_tools` is an exclusive allowlist and therefore only ever
|
|
98948
100782
|
* rulesync-authored explicitly, through `vibe.enabled_tools`. When the
|
|
98949
100783
|
* override declares it (even empty), rulesync owns the whole list; when it
|
|
@@ -101406,6 +103240,9 @@ const toolPermissionsFactories = /* @__PURE__ */ new Map([
|
|
|
101406
103240
|
var PermissionsProcessor = class extends FeatureProcessor {
|
|
101407
103241
|
toolTarget;
|
|
101408
103242
|
global;
|
|
103243
|
+
sweepsThroughInRootLinks() {
|
|
103244
|
+
return this.global;
|
|
103245
|
+
}
|
|
101409
103246
|
constructor({ outputRoot = process.cwd(), inputRoots, toolTarget, global = false, dryRun = false, logger }) {
|
|
101410
103247
|
super({
|
|
101411
103248
|
outputRoot,
|
|
@@ -104091,6 +105928,6 @@ const CHECKS_IMPORT_STRATEGY = {
|
|
|
104091
105928
|
missingLabel: "check files",
|
|
104092
105929
|
createdLabel: "check files"
|
|
104093
105930
|
};
|
|
104094
|
-
export {
|
|
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 };
|
|
104095
105932
|
|
|
104096
|
-
//# sourceMappingURL=import-
|
|
105933
|
+
//# sourceMappingURL=import-UXidZnLu.js.map
|