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