forked from project-codeguard/rules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathantigravity.py
More file actions
74 lines (56 loc) · 2.34 KB
/
antigravity.py
File metadata and controls
74 lines (56 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Copyright 2025 Cisco Systems, Inc. and its affiliates
#
# SPDX-License-Identifier: Apache-2.0
"""
Antigravity Format Implementation
Generates .md rule files for Google Antigravity with YAML frontmatter.
"""
from formats.base import BaseFormat, ProcessedRule
class AntigravityFormat(BaseFormat):
"""
Google Antigravity format implementation (.md rule files).
Antigravity uses .md files with YAML frontmatter containing:
- trigger: 'always_on' or 'glob' (activation type)
- globs: (if trigger is 'glob') File matching patterns
- description: Rule description
- version: Rule version
Rules use activation types (Always On or Glob) to determine when
they apply, similar to Windsurf's implementation.
See: https://antigravity.google/docs/rules-workflows
"""
def get_format_name(self) -> str:
"""Return Antigravity format identifier."""
return "antigravity"
def get_file_extension(self) -> str:
"""Return Antigravity format file extension."""
return ".md"
def get_output_subpath(self) -> str:
"""Return Antigravity output subdirectory."""
return ".agent/rules"
def generate(self, rule: ProcessedRule, globs: str) -> str:
"""
Generate Antigravity .md format with YAML frontmatter.
Args:
rule: The processed rule to format
globs: Glob patterns for file matching
Returns:
Formatted .md content with trigger, globs, description, and version
Note:
Antigravity rules use activation types:
- 'always_on': Rule applies to all files (when alwaysApply is true)
- 'glob': Rule applies to files matching glob patterns (language-specific)
"""
yaml_lines = []
# Use trigger: always_on for rules that should always apply
if rule.always_apply:
yaml_lines.append("trigger: always_on")
else:
yaml_lines.append("trigger: glob")
yaml_lines.append(f"globs: {globs}")
# Add description (required by Antigravity spec)
desc = self._format_yaml_field("description", rule.description)
if desc:
yaml_lines.append(desc)
# Add version
yaml_lines.append(f"version: {self.version}")
return self._build_yaml_frontmatter(yaml_lines, rule.content)