Repository navigation
fix(antigravity): write permission targets Antigravity can match - #3315
Conversation
…atch Antigravity reads a `command(...)` target as a literal token prefix, or as a regex when it starts with `regex:`. Both Antigravity generators copied canonical globs through verbatim, so `command(rm -rf *)` matched nothing and a deny ported from Claude Code blocked nothing. A pattern ending in one ` *` now becomes the literal prefix (`npm run *` -> `command(npm run)`). Any other pattern, an exact command included, becomes an anchored `regex:^...$`. Import reverses both, and a `regex:` rule rulesync cannot read as a glob is kept as written.
Antigravity file targets are paths and URL targets are domains; neither is
a glob. Both generators copied canonical patterns through verbatim, so
`read: { "**/*.env": "deny" }` became `read_file(**/*.env)`, a literal path
that matches nothing, and the deny blocked nothing.
The entry builder now lives in antigravity-targets.ts, shared by the CLI
and IDE generators. `dir/**` becomes `dir`, a plain path is kept, and `*`
or `**` is the bare action. A URL or `domain:` pattern becomes its
hostname, with a warning when an allow drops a path. Any other glob is
skipped with a warning that says a deny is not enforced.
The e2e expectations still held the old verbatim command globs from the
previous commit; they are updated too.
A probe against agy showed how it reads a command target. It splits the command and the target on whitespace and matches them one word at a time, and extra words at the end of the command still match. Each regex: word is anchored to its word, so `.*` never spans a space. The previous translation assumed one regex over the whole line: `^git push .* --force$` never matches `git push origin main --force`, and `^git status$` also denies `git status --short`. Literal words now become a plain target. An exact command has no spelling, so `git status` becomes `command(git status)`, and an allow or ask warns that it also matches more words. A glob inside a word becomes a per-word regex (`npm run test:*` -> `regex:^npm$ ^run$ ^test:.*$`). A `*` with another word after it can stand for several words, which agy cannot say, so the rule is skipped with a warning; for a deny, it says the rule is not enforced. Import reads per-word regexes back into globs.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Several edge cases still under-enforce denies or broaden imported rules.
Review effort: Balanced
Findings: 3
Open (3)
What changed in this PR
Corrects Antigravity permission generation by translating canonical globs into targets its permission engine can match.
Changes:
- Adds shared command, path, and URL target conversion.
- Integrates conversion and reverse import into CLI and IDE adapters.
- Expands unit, E2E, and reference documentation coverage.
| File | Description |
|---|---|
src/features/permissions/antigravity-targets.ts |
Builds shared Antigravity targets. |
src/features/permissions/antigravity-targets.test.ts |
Tests path, URL, and command targets. |
src/features/permissions/antigravity-command-patterns.ts |
Converts command globs and regex targets. |
src/features/permissions/antigravity-cli-permissions.ts |
Integrates translation into CLI import/export. |
src/features/permissions/antigravity-cli-permissions.test.ts |
Tests CLI conversion behavior. |
src/features/permissions/antigravity-ide-permissions.ts |
Integrates translation into IDE import/export. |
src/features/permissions/antigravity-ide-permissions.test.ts |
Tests IDE conversion behavior. |
src/e2e/e2e-permissions.spec.ts |
Updates Antigravity E2E expectations. |
docs/reference/file-formats.md |
Documents Antigravity matching semantics. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…at ? and # From the Copilot review on dyoshikawa#3315: - A bracket range endpoint was written into the regex unescaped, so `[\-z]` became `-` or `z` instead of `\` through `z`. Endpoints are now escaped like members, and a range that runs backwards (an invalid regex) is skipped with a warning. - `/**` left an empty directory and was skipped; it now becomes `read_file(/)`. - A URL's host ended only at `/`, so `https://example.com?key=*` was read as a bad hostname and skipped. It now ends at `?` and `#` too.
…es, warn on subdomains From a Gemini review of dyoshikawa#3315: - `docker * *` needs two more words, but one `*` word was dropped, so the rule matched `docker run`. Every `*` word is now a regex word; only `<words> *` stays a plain prefix. Import no longer adds a `*` after a `.*` word, so `regex:echo rx .*` reads back as `echo rx *`, which does match `echo rx foo`. - agy compiles each word of a `regex:` target on its own, so `regex:^ls( -la)?$` splits into `^ls(` and `-la)?$`, neither valid. Such a rule is now skipped with a warning instead of passed through. - A domain target covers its subdomains, so an allow or ask written without `*.` now warns that it does.
From the second Copilot review on dyoshikawa#3315: - The match-all check ran after `./` was stripped, so `./*` (the root's own files) became the bare action, matching every path, and `./` became `read_file()`. The check now runs on the pattern as written. `./`, `.` and `./**` become `read_file(.)`, and `./*` is skipped like `src/*`. - Pass-through regex words were checked as JavaScript, but agy compiles them as Go RE2. JavaScript-only syntax (lookahead, lookbehind, backreferences) is now refused, and RE2-only spellings (`(?P<name>`, `(?i)`, `(?-i)`, `\A`, `\z`, `[[:alpha:]]`) are rewritten before the check, so valid RE2 rules are no longer skipped.
From the third Copilot review on dyoshikawa#3315, and a Gemini review of the fix: - The regex check compiled in JavaScript, which accepts what Go RE2 refuses. It now refuses lookaround, any letter escape Go does not know (`\k`, `\c`, `\u`, `\U`, `\C`, a lone `\E`), repeats over 1000 and unknown POSIX classes, and reads `\Q...\E` as literal text. Each case was checked against Go 1.27's regexp. - `?` and a negated class can match a space, so `git?status` and `git[!x]status` also match `git status`, which agy sees as two words. Such a step is now skipped unless it is the last one. A negated class only counts as space-free when it excludes the space itself (`[!\t]` does not). A class that lists whitespace is always skipped, since the space would split the regex word. - `{a,b}` alternatives were written literally; they are now skipped. - Import kept `\{` and `\}` as plain braces, and read a lone `.` as `?`; both now keep the rule a regex, since a glob reads them more broadly.
…tion From the fourth Copilot review on dyoshikawa#3315 and open Gemini reviews of the whole change; each regex case was checked against Go 1.27's regexp. Commands: - A `*` with anything after it in its word (`rm *.env`) can span words: the glob also matches `rm -f foo.env`, which `^rm$ ^.*\.env$` misses. Such a pattern is now skipped; a `*` is kept only at the end of its word. - Whitespace is checked across all characters Go splits on (including U+0085), for class ranges like `[\t-\r]` and negated classes alike, and is written as `\x{..}` so `\x{2003}` is not read as `\x20` then `03`. - The RE2 check reads POSIX classes only inside a bracket (`[:foobar:]` is an ordinary class), validates `\x` and `\p` escapes and Unicode class names, does not mistake `\x{2003}` for a repeat, and does not read the Q in `\\Q` as quoting. Import: - A regex word with `.*` before its end (`^.*\.env$`) or a `\\` stays a regex, since the glob would mean more. - A plain target holding `*`, `?`, `[` or `{` is literal in Antigravity, so it imports as an escaped regex (`command(rm -rf *)` matches a `*` word). URLs: - `*.example.com` now warns an allow too: the target also covers `example.com` itself. - `https://*` (with no path) becomes the bare `read_url` instead of being skipped, so a deny on every https URL is enforced.
|
I thought this PR was going to be an easy one. |
…n the RE2 check From the fifth Copilot review on dyoshikawa#3315 and open Gemini reviews; each regex case was checked against Go 1.27's regexp. - Words are split on Go's `unicode.IsSpace` set, not JavaScript's `\s`: U+FEFF stays inside a word and U+0085 splits one. - Only `{a,b}` alternatives and `{1..3}` ranges count as brace glob syntax, so a literal path such as `state/{current}/data` is no longer skipped. - The RE2 check refuses what Go refuses and JavaScript accepted: any unknown name in `[:...:]` inside a class (`[[:FOO:]]`), `\A`, `\z`, `\b` or `\B` inside a class, `\x{...}` past U+10FFFF, and an empty regex. Braces inside a class (`[a{1001}]`) are no longer read as a repeat count. - A plain target holding `\` imports as an escaped regex, since a glob reads `\b` as an escaped `b`.
Resolve the src/generated/docs-content.ts conflict by regenerating it from the merged docs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Y4MwhqMc6s4ct5MzMReGJj
There was a problem hiding this comment.
🟡 Changes recommended
Importing command(*) widens permissions, and escaped-backslash repeats can bypass RE2 validation.
2 open findings
2 resolved since last review
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
| const pattern = | ||
| toolName === "command" && target !== "*" ? fromAntigravityCommandTarget(target) : target; |
| const pattern = | ||
| ideAction === "command" && target !== "*" ? fromAntigravityCommandTarget(target) : target; |
# Conflicts: # src/generated/docs-content.ts
There was a problem hiding this comment.
🟡 Changes recommended
Several URL, Windows-path, and regex edge cases can still produce missing or incorrectly widened permissions.
6 open findings
Account for backslash escape parity before regex quantifiers · New Preserve empty external regex targets · New Preserve literal command(*) during CLI import Preserve literal command(*) during IDE import Handle backslash separators in Windows directory glob normalization · New Strip wildcard URL schemes before extracting hosts · New
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
| const plain = blankClasses(source.replace(/\\[xpP]\{[^}]*\}/g, "e")); | ||
| for (const [, low = "", high = ""] of plain.matchAll(/(?<!\\)\{(\d+)(?:,(\d*))?\}/g)) { | ||
| if (Number(low) > RE2_MAX_REPEAT || Number(high) > RE2_MAX_REPEAT) { |
| function regexToGlob(source: string): string | undefined { | ||
| const globs: string[] = []; | ||
| for (const word of splitWords(source)) { | ||
| const glob = regexWordToGlob(word); | ||
| if (glob === undefined) { | ||
| return undefined; | ||
| } | ||
| globs.push(glob); | ||
| } |
| // A trailing glob that means "everything under this directory". | ||
| const DIRECTORY_CONTENTS_SUFFIX = /\/\*\*(?:\/\*)?$/; |
| if (withoutPrefix === "*") { | ||
| return { target: "*" }; | ||
| } | ||
| const withoutScheme = withoutPrefix.replace(/^[a-z][a-z0-9+.-]*:\/\//i, ""); |
# Conflicts: # src/generated/docs-content.ts
There was a problem hiding this comment.
🟡 Changes recommended
RE2 validation can still emit invalid deny expressions, potentially leaving commands unenforced.
7 open findings
Preserve empty external regex targets Account for backslash escape parity before regex quantifiers Preserve literal command(*) during CLI import Preserve literal command(*) during IDE import Preserve blanket command deny when narrower rule is unrepresentable · New Strip wildcard URL schemes before extracting hosts Handle backslash separators in Windows directory glob normalization
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
| const settings = JSON.parse(permissions.getFileContent()) as SettingsJson; | ||
| // `*` there can stand for several words; a regex word matches only one. | ||
| expect(settings.permissions?.deny).toEqual(["command(git push)"]); |
|
@cacarico Thank you! |


Fixes #3314.
Antigravity targets are not globs:
commandis matched word by word (plain words, or one anchoredregex:per word),read_file/write_filetake a path, andread_urltakes a domain. Both Antigravity generators copied canonical patterns through verbatim, so"rm -rf *": "deny"becamecommand(rm -rf *)and blocked nothing. The issue has the live agy probe that settled the matching rules.Summary
antigravity-targets.ts) for the CLI and IDE generators.antigravity-command-patterns.ts):npm run *→command(npm run).git status→command(git status), and an allow or ask warns that it now matches more.npm run test:*→command(regex:^npm$ ^run$ ^test:.*$).*with another word after it (git push * --force,git commit-* --amend) can stand for several words, which a word-by-word match can't say. It is skipped with a warning; for a deny the warning says it is not enforced. Same for a[...]class that matches a space.regex:...pass through.src/**→read_file(src), a plain path is kept,*/**→ the bare action. Other globs (**/*.env) are skipped with a warning.domain:pattern → its hostname. An allow or ask with a path warns that it covers the whole domain.Xreads asX *, and a per-word regex that only uses.,.*and escapes reads back as its glob.file-formats.mddescribe the matching for both targets.Testing
pnpm cicheck: 14,136 tests passedpnpm exec vitest run --config vitest.e2e.config.ts src/e2e/e2e-permissions.spec.ts -t antigravity: 4 passedThe diff is about 860 added lines, over the 400-line guideline; more than half of that is tests.