# Contributing to agnix Thank you for contributing to agnix. ## Development Setup ```bash git clone https://github.com/agent-sh/agnix cd agnix cargo build cargo test ``` ## Code Style Before committing: ```bash bash scripts/preflight.sh # Before pushing: bash scripts/preflight.sh --full ``` See the [local development loop](README.md#local-development-loop) for checks, resource limits, optional hooks, and the testing-to-review handoff. ## Adding a New Rule 1. **Add to rules.json** - `knowledge-base/rules.json` is the source of truth 2. **Add to VALIDATION-RULES.md** - `knowledge-base/VALIDATION-RULES.md` for human docs 3. **Implement validator** - `crates/agnix-core/src/rules/` 4. **Add test fixtures** - `tests/fixtures/` 5. **Run parity tests** - CI enforces rules.json and VALIDATION-RULES.md stay in sync Maintain project instructions in `AGENTS.md` only. Each rule in `rules.json` must include complete `evidence` metadata. See [Rule Evidence Requirements](#rule-evidence-requirements) below for field details. Security-facing rules should also include `security` metadata. See [Security Rule Metadata](#security-rule-metadata). ## Rule Evidence Requirements Each rule in `knowledge-base/rules.json` must include an `evidence` object documenting its authoritative source. The evidence fields are: | Field | Type | Description | |-------|------|-------------| | `source_type` | enum | Classification of the source: `spec` (official specification), `vendor_docs` (vendor documentation), `vendor_code` (vendor source code), `paper` (academic research), `community` (community research such as agentsys) | | `source_urls` | string[] | One or more URLs pointing to the authoritative documentation, specification, or research paper that supports this rule | | `verified_on` | string | ISO 8601 date (YYYY-MM-DD) when the source was last verified to be current | | `applies_to` | object | Applicability constraints: `tool` (specific tool name, e.g., "claude-code"), `version_range` (semver range, e.g., ">=1.0.0"), `spec_revision` (spec version date). Empty object `{}` means the rule applies universally | | `normative_level` | enum | RFC 2119 level indicating rule strength: `MUST` (spec violation), `SHOULD` (strong recommendation), `BEST_PRACTICE` (advisory) | | `tests` | object | Test coverage tracking: `{ "unit": true/false, "fixtures": true/false, "e2e": true/false }` | See `knowledge-base/VALIDATION-RULES.md` for the full evidence schema reference with examples. ## Security Rule Metadata Rules that detect or prevent security-relevant misconfiguration must include a `security` object in `knowledge-base/rules.json`: | Field | Type | Description | |-------|------|-------------| | `cwe` | string[] | CWE IDs such as CWE ID 798 | | `owasp` | string[] | OWASP Top 10 IDs such as `A07:2021` | | `vulnerability_class` | string | Short class such as `hardcoded-secret`, `command-injection`, or `insecure-permissions` | | `subcategory` | enum | `vuln`, `audit`, or `secure-default` | | `confidence` | enum | `HIGH`, `MEDIUM`, or `LOW` | | `likelihood` | enum | `HIGH`, `MEDIUM`, or `LOW` | | `impact` | enum | `HIGH`, `MEDIUM`, or `LOW` | This metadata is exported through `agnix-rules` and SARIF taxonomies, so keep it in `rules.json` rather than adding SARIF-only tags. ## Rule Lifecycle Rules should prefer additive evolution over removal. Use these states: | Status | Meaning | |--------|---------| | `active` | Default when no lifecycle fields are present | | `deprecated` | Still emitted, but planned for removal or replacement | | `removed` | No longer emitted; keep a redirect in `knowledge-base/removed-rules.json` | When deprecating a rule, add `status`, `deprecated_since`, `replaced_by`, and `reason` fields to the rule entry in `knowledge-base/rules.json`, then document the change in `knowledge-base/VALIDATION-RULES.md` and `CHANGELOG.md`. When removing a rule, remove the active rule entry, add an entry to `knowledge-base/removed-rules.json`, update docs/changelog, and make sure `.agnix.toml` validation warns for stale `disabled_rules` or `[rules.severity]` references. If a replacement exists, list it in `replaced_by`. ## Rule ID Conventions Rule IDs follow the format `[PREFIX]-[NUMBER]` where the prefix indicates the rule family: | Prefix | Rules | Current IDs | |--------|-------|-------------| | `AGM-` | 6 | AGM-001 through AGM-002, AGM-004, AGM-007 through AGM-009 | | `AMP-` | 9 | AMP-001 through AMP-008, AMP-010 | | `AMP-SK-` | 3 | AMP-SK-001 through AMP-SK-003 | | `AS-` | 22 | AS-001 through AS-006, AS-008 through AS-009, AS-011 through AS-013, AS-015 through AS-017, AS-020 through AS-027 | | `CC-AG-` | 21 | CC-AG-001 through CC-AG-012, CC-AG-014 through CC-AG-015, CC-AG-017, CC-AG-019 through CC-AG-024 | | `CC-HK-` | 32 | CC-HK-001 through CC-HK-003, CC-HK-005 through CC-HK-016, CC-HK-018, CC-HK-020 through CC-HK-035 | | `CC-MCP-` | 5 | CC-MCP-001 through CC-MCP-005 | | `CC-MEM-` | 15 | CC-MEM-001 through CC-MEM-004, CC-MEM-010 through CC-MEM-012, CC-MEM-014 through CC-MEM-021 | | `CC-MP-` | 5 | CC-MP-001 through CC-MP-005 | | `CC-OS-` | 6 | CC-OS-001 through CC-OS-004, CC-OS-006 through CC-OS-007 | | `CC-PL-` | 23 | CC-PL-001 through CC-PL-023 | | `CC-SET-` | 35 | CC-SET-001 through CC-SET-013, CC-SET-016 through CC-SET-020, CC-SET-022 through CC-SET-023, CC-SET-025 through CC-SET-031, CC-SET-033 through CC-SET-040 | | `CC-SK-` | 28 | CC-SK-001 through CC-SK-002, CC-SK-004 through CC-SK-008, CC-SK-010, CC-SK-013 through CC-SK-025, CC-SK-027 through CC-SK-028, CC-SK-030 through CC-SK-034 | | `CDX-` | 4 | CDX-000, CDX-004 through CDX-006 | | `CDX-AG-` | 8 | CDX-AG-001 through CDX-AG-003, CDX-AG-005 through CDX-AG-006, CDX-AG-008 through CDX-AG-010 | | `CDX-APP-` | 3 | CDX-APP-001 through CDX-APP-003 | | `CDX-CFG-` | 34 | CDX-CFG-001 through CDX-CFG-012, CDX-CFG-014 through CDX-CFG-035 | | `CDX-DEP-` | 1 | CDX-DEP-001 | | `CDX-HK-` | 6 | CDX-HK-000 through CDX-HK-005 | | `CDX-PL-` | 19 | CDX-PL-001 through CDX-PL-019 | | `CDX-REQ-` | 5 | CDX-REQ-000 through CDX-REQ-004 | | `CDX-RL-` | 2 | CDX-RL-001 through CDX-RL-002 | | `CDX-SUB-` | 3 | CDX-SUB-001 through CDX-SUB-003 | | `CL-SK-` | 2 | CL-SK-001, CL-SK-004 | | `CLN-` | 14 | CLN-001 through CLN-006, CLN-009 through CLN-016 | | `COP-` | 33 | COP-001 through COP-015, COP-017 through COP-020, COP-025, COP-027 through COP-039 | | `CP-SK-` | 2 | CP-SK-001 through CP-SK-002 | | `CR-SK-` | 1 | CR-SK-001 | | `CUR-` | 39 | CUR-001 through CUR-037, CUR-039 through CUR-040 | | `CX-SK-` | 4 | CX-SK-001, CX-SK-004, CX-SK-006 through CX-SK-007 | | `GM-` | 26 | GM-001 through GM-006, GM-008 through GM-011, GM-013 through GM-028 | | `GM-AG-` | 6 | GM-AG-001 through GM-AG-006 | | `GM-CMD-` | 3 | GM-CMD-001 through GM-CMD-003 | | `KIRO-` | 16 | KIRO-001 through KIRO-011, KIRO-015 through KIRO-018, KIRO-026 | | `KR-AG-` | 29 | KR-AG-001 through KR-AG-006, KR-AG-008 through KR-AG-030 | | `KR-HK-` | 28 | KR-HK-001 through KR-HK-006, KR-HK-009 through KR-HK-030 | | `KR-IGN-` | 1 | KR-IGN-001 | | `KR-MCP-` | 15 | KR-MCP-001 through KR-MCP-015 | | `KR-PM-` | 12 | KR-PM-001 through KR-PM-012 | | `KR-PW-` | 18 | KR-PW-001 through KR-PW-004, KR-PW-006 through KR-PW-019 | | `KR-SET-` | 11 | KR-SET-001 through KR-SET-011 | | `KR-SK-` | 2 | KR-SK-001 through KR-SK-002 | | `KR-WF-` | 9 | KR-WF-001 through KR-WF-009 | | `MCP-` | 30 | MCP-001 through MCP-004, MCP-006 through MCP-024, MCP-027 through MCP-033 | | `OC-` | 8 | OC-001 through OC-004, OC-006 through OC-009 | | `OC-AG-` | 11 | OC-AG-001 through OC-AG-011 | | `OC-AGM-` | 2 | OC-AGM-002 through OC-AGM-003 | | `OC-CFG-` | 20 | OC-CFG-001 through OC-CFG-002, OC-CFG-004 through OC-CFG-015, OC-CFG-017 through OC-CFG-022 | | `OC-CMD-` | 3 | OC-CMD-001 through OC-CMD-003 | | `OC-DEP-` | 8 | OC-DEP-001 through OC-DEP-003, OC-DEP-005 through OC-DEP-009 | | `OC-LSP-` | 2 | OC-LSP-001 through OC-LSP-002 | | `OC-PM-` | 6 | OC-PM-002 through OC-PM-007 | | `OC-POL-` | 1 | OC-POL-001 | | `OC-SK-` | 2 | OC-SK-001 through OC-SK-002 | | `OC-TOOL-` | 1 | OC-TOOL-001 | | `OC-TUI-` | 3 | OC-TUI-001 through OC-TUI-003 | | `PE-` | 4 | PE-002, PE-004 through PE-006 | | `REF-` | 3 | REF-001 through REF-003 | | `VER-` | 1 | VER-001 | | `WS-` | 11 | WS-001 through WS-011 | | `WS-HK-` | 5 | WS-HK-001 through WS-HK-005 | | `WS-SK-` | 1 | WS-SK-001 | | `XML-` | 3 | XML-001 through XML-003 | | `XP-` | 7 | XP-001 through XP-006, XP-008 | | `XP-SK-` | 4 | XP-SK-001 through XP-SK-004 | To find the next available number for a prefix, check `knowledge-base/rules.json` for the highest existing number in that prefix group and increment by one. ## Implementing a Validator Step-by-step process for adding a new validation rule: 1. **Add the rule to `knowledge-base/rules.json`** - Include all required fields: `id`, `name`, `severity`, `category`, `message`, `detection`, `fix`, and complete `evidence` metadata. The `crates/agnix-rules/rules.json` file is automatically synchronized during the build process. 2. **Add documentation to `knowledge-base/VALIDATION-RULES.md`** - Document the rule following the existing format with detection logic, fix description, and source citation. CI parity tests will fail if the rule exists in one file but not the other. 3. **Implement the `Validator` trait** - Add validation logic in `crates/agnix-core/src/rules/`. Look at existing validators for patterns: - `xml_balance.rs` - simple single-file validator - `agents_md.rs` - project-level validator with cross-file analysis - `skill/mod.rs` and `hooks/mod.rs` - complex validators split into focused `helpers.rs` and `tests.rs` modules 4. **Register in `ValidatorRegistry`** - Add the validator factory to the appropriate category `ValidatorProvider` struct in `crates/agnix-core/src/registry.rs`. It will be included automatically via `ValidatorRegistry::with_defaults()`. External validators can use the `ValidatorProvider` trait instead. 5. **Add test fixtures** - Create test files in `tests/fixtures/` matching the validator's expected file type detection patterns. Fixtures should cover both valid and invalid configs. 6. **Run tests** - Verify everything passes: ```bash cargo test # Full test suite cargo test -p agnix-rules --test parity # Parity check cargo test -p agnix-core # Core validator tests ``` ## Testing Requirements All new rules must include: - **Unit tests** in the validator module (test individual rule detection and edge cases) - **Integration tests** via test fixtures in `tests/fixtures/` (test end-to-end validation) - **Parity tests** pass (rules.json matches VALIDATION-RULES.md; rules.json matches crates/agnix-rules/rules.json) - **Full test suite** passes before submitting a PR (`cargo test`) ## Tool Tier System agnix organizes tool support into owner-selected maintenance priorities. A tier does not imply that a validator already exists; the research inventory records implemented coverage and pending work separately. | Tier | Policy | Testing Requirement | |------|--------|---------------------| | **S** | Test always | Every CI run validates against these tools | | **A** | Test on major changes | Tested when changes affect tool-specific rules | | **B** | Test on significant changes | Spot-tested when affected | | **C** | Community-reported maintenance | Verify fixes for reported problems | | **D** | Nice-to-have maintenance | Preserve existing validation; check specification drift monthly and fix reported problems | Current assignments and coverage are documented in [`knowledge-base/RESEARCH-TRACKING.md`](./knowledge-base/RESEARCH-TRACKING.md). The machine-readable roster is `.github/tool-release-baselines.json`: `tools` contains active tiers, `retired_tools` holds historical compatibility baselines and `excluded_tools` lists dropped products. Retired entries are not polled. Existing Amp and Windsurf/Devin validators remain for compatibility, outside active support. Propose tier changes through a GitHub issue; the owner decides the roster. ## Community Feedback I welcome community input through several channels: - **GitHub Issues** - Use the issue templates for structured feedback: - [Bug Report](.github/ISSUE_TEMPLATE/bug_report.md) - Report validation errors - [Feature Request](.github/ISSUE_TEMPLATE/feature_request.md) - Suggest new capabilities - [Rule Contribution](.github/ISSUE_TEMPLATE/rule_contribution.md) - Propose new validation rules - [Tool Support Request](.github/ISSUE_TEMPLATE/tool_support_request.md) - Request support for new tools - **GitHub Discussions** - General questions, ideas, and community discussion ## Pull Request Process 1. **Update CHANGELOG.md** - Required for all PRs (skip with `[skip changelog]` in title) 2. **Add tests** - Every feature/fix must have tests 3. **Wait for CI and review** - Require successful `revuto-review` and hosted checks on the current head. If revuto is capped or unavailable (daily limit, round cap, quota), do not wait for it or re-trigger it: the author's self-review is enough, noted in the PR body 4. **Address review comments** - Resolve findings before merging through the PR; follow the current repository protection rules ## Backward-Compatibility Policy agnix follows a stability policy to protect downstream consumers (CLI, LSP, MCP, editor extensions) from accidental API breakage. ### Stability Tiers | Tier | Scope | Contract | |------|-------|----------| | **Public/Stable** | Re-exported types at `agnix_core` root (`LintConfig`, `Diagnostic`, `DiagnosticLevel`, `Fix`, `LintError`, `LintResult`, `ValidationResult`, `FileType`, `ValidatorRegistry`, `ValidatorFactory`, `Validator` trait, `FileSystem` trait, `MockFileSystem`, `RealFileSystem`, `FixResult`, `ConfigWarning`, `FilesConfig`, `generate_schema`) and all `agnix_rules` public items (`RULES_DATA`, `VALID_TOOLS`, `TOOL_RULE_PREFIXES`, `rule_count`, `get_rule_name`, `valid_tools`, `normalize_tool_name`, etc.) | Breaking changes require a minor version bump (pre-1.0) or major version bump (post-1.0) with advance notice in CHANGELOG.md | | **Public/Unstable** | Accessible public modules that may change between minor versions: `authoring`, `eval`, `i18n`, `validation` | May change with a minor version bump; consumers should pin exact versions if depending on these | | **Internal** | Private modules not accessible outside the crate: `parsers`, `rules`, `schemas`, `file_utils`, `regex_util`, `span_utils` | May change freely in any release | ### What Constitutes a Breaking Change The following changes to **Public/Stable** items are considered breaking: - Removing a public type, function, or constant - Changing a public function signature (parameter types, return type) - Changing a struct field type or removing a field - Removing an enum variant - Changing a trait method signature or adding a required method without a default ### What is Non-Breaking These changes are safe to make in any release: - Adding new enum variants (this may break exhaustive matches; consumers should use wildcard `_` arms to stay forward-compatible) - Adding new optional struct fields with `#[serde(default)]` - Adding new public functions, types, or modules - Adding new validators to `ValidatorRegistry::with_defaults()` - Adding new rules to `agnix_rules` - Adding new trait methods with default implementations ### Feature Flags agnix-core intentionally has no feature flags. It is a focused validation library with no optional heavyweight dependencies. Only the CLI crate (`agnix-cli`) has a `telemetry` feature flag for opt-in analytics. When to add feature flags in the future: - If a new dependency adds significant compile time or binary size - If a feature is truly optional and not needed by most consumers ### Pre-1.0 Caveat While agnix is below version 1.0, this policy is followed in good faith. Minor versions may occasionally contain breaking changes when necessary, but these will always be documented in CHANGELOG.md with migration instructions. ## Commit Messages Use conventional commits: - `feat:` - New feature - `fix:` - Bug fix - `docs:` - Documentation - `refactor:` - Code refactoring - `test:` - Tests - `chore:` - Maintenance Reference issues when applicable: `fix: resolve timeout issue (#123)` ## Contributing Translations agnix supports multiple languages. See [docs/TRANSLATING.md](docs/TRANSLATING.md) for: - Adding new locales - Translation guidelines - Testing translations ## Running Tests ```bash # All tests cargo test # Specific crate cargo test -p agnix-core # With output cargo test -- --nocapture ``` ### Security Tests ```bash # Security integration tests cargo test --test security_integration # Fuzz testing (requires nightly) cd crates/agnix-core cargo +nightly fuzz run fuzz_markdown -- -max_total_time=300 cargo +nightly fuzz run fuzz_frontmatter -- -max_total_time=300 cargo +nightly fuzz run fuzz_json -- -max_total_time=300 # Dependency audit cargo audit cargo deny check ``` ## Project Structure ``` crates/ agnix-rules/ # Rule definitions (generated) agnix-core/ # Validation engine agnix-cli/ # CLI binary agnix-lsp/ # Language server agnix-mcp/ # MCP server agnix-wasm/ # WebAssembly bindings editors/ neovim/ # Neovim extension vscode/ # VS Code extension jetbrains/ # JetBrains extension scaffold knowledge-base/ # Rules documentation scripts/ # Development automation scripts website/ # Docusaurus documentation website tests/fixtures/ # Test cases ``` ## Questions? Open an issue or start a discussion.