Skip to content

fix(antigravity): write permission targets Antigravity can match - #3315

Merged
dyoshikawa merged 12 commits into
dyoshikawa:mainfrom
cacarico:fix/antigravity-permission-targets
Oct 8, 2026
Merged

dyoshikawa merged 12 commits into
dyoshikawa:mainfrom
cacarico:fix/antigravity-permission-targets

Conversation

@cacarico

@cacarico cacarico commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #3314.

Antigravity targets are not globs: command is matched word by word (plain words, or one anchored regex: per word), read_file / write_file take a path, and read_url takes a domain. Both Antigravity generators copied canonical patterns through verbatim, so "rm -rf *": "deny" became command(rm -rf *) and blocked nothing. The issue has the live agy probe that settled the matching rules.

Summary

  • One shared entry builder (antigravity-targets.ts) for the CLI and IDE generators.
  • Commands (antigravity-command-patterns.ts):
    • Literal words become a plain target: npm run * → command(npm run).
    • An exact command can't be expressed, since agy lets extra words follow. git status → command(git status), and an allow or ask warns that it now matches more.
    • A glob inside a word becomes a per-word regex: npm run test:* → command(regex:^npm$ ^run$ ^test:.*$).
    • A * 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.
    • Patterns already written as regex:... pass through.
  • Files: src/** → read_file(src), a plain path is kept, * / ** → the bare action. Other globs (**/*.env) are skipped with a warning.
  • URLs: a URL or domain: pattern → its hostname. An allow or ask with a path warns that it covers the whole domain.
  • Import reverses this: a plain target X reads as X *, and a per-word regex that only uses ., .* and escapes reads back as its glob.
  • Docs in file-formats.md describe the matching for both targets.

Testing

The diff is about 860 added lines, over the 400-line guideline; more than half of that is tests.

…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.
Copilot AI balanced review requested due to automatic review settings October 5, 2026 22:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Several edge cases still under-enforce denies or broaden imported rules.

Review effort: Balanced
Findings: 3 Medium severity

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.
Copilot AI balanced review requested due to automatic review settings October 5, 2026 22:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Command translation mismatches and workspace-relative path widening can produce ineffective or overbroad permissions.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (3)

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.
Copilot AI balanced review requested due to automatic review settings October 5, 2026 23:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Some bracket, brace, and invalid RE2 patterns can still produce misleading or widened permission rules.

Review effort: Balanced
Findings: 2 High severity · 2 Medium severity

Open (4)
Resolved since last review (2)

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.
Copilot AI balanced review requested due to automatic review settings October 6, 2026 07:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Several command conversions can under-enforce denies or widen imported rules, and URL wildcard allows omit a required widening warning.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
Resolved since last review (4)

…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.
Copilot AI balanced review requested due to automatic review settings October 6, 2026 09:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Several regex and whitespace edge cases can still emit mismatched or unenforced permissions.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
Resolved since last review (2)

@cacarico
cacarico marked this pull request as draft October 6, 2026 09:32
@cacarico

cacarico commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

I thought this PR was going to be an easy one.
Regrets...

…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`.
@cacarico
cacarico marked this pull request as ready for review October 6, 2026 15:34
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
Copilot AI balanced review requested due to automatic review settings October 8, 2026 02:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment on lines +442 to +443
const pattern =
toolName === "command" && target !== "*" ? fromAntigravityCommandTarget(target) : target;
Comment on lines +304 to +305
const pattern =
ideAction === "command" && target !== "*" ? fromAntigravityCommandTarget(target) : target;
# Conflicts:
#	src/generated/docs-content.ts
Copilot AI balanced review requested due to automatic review settings October 8, 2026 03:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Several URL, Windows-path, and regex edge cases can still produce missing or incorrectly widened permissions.

6 open findings

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment on lines +263 to +265
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) {
Comment on lines +513 to +521
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);
}
Comment on lines +32 to +33
// 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
Copilot AI balanced review requested due to automatic review settings October 8, 2026 03:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

RE2 validation can still emit invalid deny expressions, potentially leaving commands unenforced.

7 open findings

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment on lines +147 to +149
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)"]);
@dyoshikawa
dyoshikawa merged commit 8908384 into dyoshikawa:main Oct 8, 2026
5 checks passed
@dyoshikawa

Copy link
Copy Markdown
Owner

@cacarico Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

antigravity permissions: glob patterns like command(rm -rf *) never match in Antigravity

3 participants