Skip to content

fix(antigravity): write subproject rules to the root .agents/rules as glob rules - #3995

Merged
dyoshikawa merged 6 commits into
mainfrom
resolve-issue-2666-antigravity-nested-rules
Nov 26, 2026
Merged

dyoshikawa merged 6 commits into
mainfrom
resolve-issue-2666-antigravity-nested-rules

Conversation

@dyoshikawa

@dyoshikawa dyoshikawa commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

The Antigravity rules docs now say rules load from the workspace folder and its parent folders up to the repository root, and that "Antigravity doesn't load rules from subfolders below the workspace folder". Since #3385, antigravity-ide and antigravity-cli wrote rules with agentsmd.subprojectPath to <subprojectPath>/.agents/rules/. Antigravity ignores those files when the repository root is opened, which is the normal case. This PR folds them into the project-root .agents/rules/ as glob rules limited to the subproject.

Changes

  • src/features/rules/antigravity-rule.ts: new scopeAntigravityFrontmatterToSubproject and toSubprojectRuleFileName. resolveAntigravitySubprojectPath now normalizes the path (separators, leading ./, trailing /).
    • glob rules keep their trigger, and every glob is prefixed with **/<subprojectPath>/ (src/**/*.ts → **/packages/api/src/**/*.ts). Negated globs (!…) and a leading ./ are handled. The list is split only on commas outside brace groups (splitBraceAwareList), so *.{ts,tsx} stays one glob. Globs next to an explicit subprojectPath are always prefixed. When the subproject is derived from globs (deriveSubprojectPathFromGlobs / "auto"), the globs already start with it, so they only get the leading **/.
    • always_on (including the inferred default) becomes trigger: glob with globs: "**/<subprojectPath>/**".
    • model_decision, manual and unknown triggers keep their trigger. A once-per-run warning says the rule now applies to the whole project.
  • antigravity-ide-rule.ts / antigravity-cli-rule.ts: both targets write the scoped rule to .agents/rules/<kebab(subprojectPath + rule path)>.md with identical content. The legacy nested scan is still used for import, so the next generate moves old nested rules to the root.
  • Docs: the Antigravity rules note in docs/reference/file-formats.md (and the regenerated docs-content.ts), plus the rulesync-feature-research Antigravity map row.
  • Tests: generate placement and content, glob prefixing cases, stored-trigger handling, the warning, legacy import and migration, a generate → import → generate round-trip, and IDE/CLI parity.

Design decisions

  • Root glob rules, not .agents/rules.json. This keeps feat(antigravity): write directory-scoped rules to nested .agents/rules/ #3385's meaning ("applies to files under the subproject") and does not merge into a file users may own. The root .agents/rules/ loads whether the workspace is the repository root or a subfolder.
  • Globs are anchored with a leading **/. The rules page does not say what directory globs are resolved against. The only other evidence is a Google AI forum thread: a bare tmp/tmp.md did not match while **/tmp.md did, and the reply says patterns are matched against the resolved file path. **/packages/api/... matches whatever the base is: a full path, a repository-relative path, or a rule loaded from a parent folder of a workspace opened inside the repository. The trade-off is that it would also match another directory path ending in packages/api, which seems acceptable. This side effect is documented.
  • Kebab-case file names (packages/api + frontend/codeStyle.md → packages-api-frontend-code-style.md). This differs from the triage's packages-api-codeStyle.md: the IDE kebab-cases root non-root rule names on generate and the CLI keeps them, so only a kebab-case name stays the same after import → generate for both targets. The subproject in the name avoids collisions across subprojects. Names can still collide (packages/api + style.md vs a root packages-api-style.md); the existing processor warning reports it (the last one wins), and this is documented.
  • Import does not infer subprojectPath back. A root file is imported as an ordinary rule (targets: ["*"]) whose globs keep the **/<subprojectPath>/ prefix. Regenerating writes byte-identical files; this was checked by a unit test and a scratch CLI generate → import → generate. deriveSubprojectPathFromGlobs does not pick the prefix up again, because the globs start with a wildcard.
  • Legacy nested files are not deleted. rulesync only deletes what it targets. They are still imported (the migration path), and the docs tell users to delete them by hand.
  • antigravity-plugin is unchanged: it keeps every rule in its own rules/.

Skipped items (from #2666)

All of these are blocked on undocumented or not-yet-canonical upstream surfaces. Watch only:

  • Sidecars (sidecar.json): a new feature dimension with no canonical counterpart.
  • The unsandboxed deprecation, and .geminiignore → .antigravityignore: there is no ignore docs page (/docs/ignore returns 404).
  • Remote MCP servers with non-empty command/args/env: the refusal is undocumented.
  • Plugin context providers, plugin auth.json, the "new workflows system", the Agent Plugins 1.0.0 spec, and MCP tools.<name>.eager: undocumented, or with no canonical counterpart.

The other items in this issue were fixed earlier (#3465, #3546, #3584, #3647, #3713, #3813, f72b12d). New upstream changes get a fresh issue from research-tool-updates.

Closes #2666

🤖 Generated with Claude Code

https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4

dyoshikawa and others added 6 commits November 26, 2026 17:16
… glob rules

Antigravity now loads rules only from the workspace folder and its parents
up to the repository root, never from subfolders below the workspace, so
rules written to <subprojectPath>/.agents/rules/ were silently ignored when
the repository root was opened. antigravity-ide and antigravity-cli now
write a subproject-scoped rule to the project-root .agents/rules/ with its
globs prefixed by **/<subprojectPath>/ (always_on becomes a glob rule over
the subproject; model_decision/manual keep their trigger with a warning).
Legacy nested files are still imported and moved on the next generate.

Refs #2666

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…ubprojects

Split a subproject rule's globs only on commas outside brace groups, so
`src/**/*.{ts,tsx}` is no longer cut apart. Globs next to an explicit
subprojectPath are now always prefixed; only globs of a subproject derived
from them are anchored without a second prefix. Document the `**/` anchor's
side effect and file-name collisions.

Refs #2666

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…tigravity-nested-rules

# Conflicts:
#	src/generated/docs-content.ts
…on import

Old generate wrote a subproject derived from globs to
<subprojectPath>/.agents/rules/ with project-root-relative globs. The
import sets subprojectPath explicitly, so the next generate prefixed the
subproject twice. Strip a leading <subprojectPath>/ on legacy import.

Refs #2666

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…tigravity-nested-rules

# Conflicts:
#	src/generated/docs-content.ts
…tigravity-nested-rules

# Conflicts:
#	src/generated/docs-content.ts
@dyoshikawa
dyoshikawa merged commit 591ce6d into main Nov 26, 2026
10 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-2666-antigravity-nested-rules branch November 26, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant