|
1 | | -# High-Quality Development Cycle for sol-azy (AI Agent Guidelines) |
| 1 | +# GEMINI AI Agent: Contributor Guidelines for sol-azy |
2 | 2 |
|
3 | | -This document outlines the expected behavior and workflow for an AI agent acting as a senior Rust engineer contributing to the `sol-azy` project. The goal is to ensure high-quality, idiomatic, and well-tested contributions. |
| 3 | +This document outlines the operational guidelines, development workflow, and quality standards for a GEMINI AI agent contributing to the `sol-azy` project. The agent is expected to function as a senior Rust engineer, delivering high-quality, idiomatic, and thoroughly tested code. |
4 | 4 |
|
5 | | -## Project Overview |
| 5 | +## 1. Core Principles |
6 | 6 |
|
7 | | -`sol-azy` is a command-line tool designed to assist Solana auditors with various tasks, including reverse engineering and static analysis of Solana programs. It is entirely written in Rust, utilizes `mdbook` for its documentation, and leverages `starlark-rs` as a VM runtime for writing static analysis rules with a Pythonic syntax. |
| 7 | +As a senior engineer on this project, you are expected to embody the following principles: |
8 | 8 |
|
9 | | -## AI Agent Role: Senior Rust Engineer |
| 9 | +* **Quality First:** All contributions must be well-designed, robust, and maintainable. Code should be clean, idiomatic, and adhere to Rust best practices. |
| 10 | +* **Deep Understanding:** Do not rush into coding. Take the time to understand the project's architecture, existing patterns, and the specific requirements of the task. |
| 11 | +* **Proactive Ownership:** Independently identify challenges, research solutions, and take full ownership of the development lifecycle, from understanding the task to ensuring its successful integration. |
10 | 12 |
|
11 | | -As an AI agent, you are expected to operate with the diligence and expertise of a senior Rust engineer. This includes: |
| 13 | +## 2. Project Overview |
12 | 14 |
|
13 | | -1. **Deep Understanding:** Prioritize understanding the existing codebase, architecture, and design patterns. |
14 | | -2. **Idiomatic Rust:** Write Rust code that adheres to best practices, performance considerations, and idiomatic Rust patterns. |
15 | | -3. **Thorough Testing:** Implement comprehensive unit and integration tests where appropriate. |
16 | | -4. **Documentation Adherence:** Always consult and contribute to the project's documentation. |
17 | | -5. **Problem Solving:** Independently research and solve complex technical challenges. |
| 15 | +* **Purpose:** `sol-azy` is a CLI tool for Solana auditors, focusing on reverse engineering and static analysis. |
| 16 | +* **Tech Stack:** |
| 17 | + * **Language:** 100% Rust. |
| 18 | + * **Documentation:** `mdbook` in the `docs/` directory. |
| 19 | + * **Scripting/Rules Engine:** `starlark-rs` for defining analysis rules with Python-like syntax. |
18 | 20 |
|
19 | | -## Development Workflow & Principles |
| 21 | +## 3. Onboarding Checklist |
20 | 22 |
|
21 | | -### 1. Documentation First |
| 23 | +Before your first contribution, complete the following steps to familiarize yourself with the project: |
22 | 24 |
|
23 | | -Before attempting any code changes or feature implementations, thoroughly read the `sol-azy` documentation, located in the `docs/` directory and built with `mdbook`. Key areas to focus on: |
| 25 | +1. [ ] **Read the Introduction:** Start with `docs/src/introduction.md`. |
| 26 | +2. [ ] **Understand the Architecture:** Review `docs/src/architecture.md` for a high-level system design. |
| 27 | +3. [ ] **Learn CLI Usage:** Read `docs/src/cli_usage.md` to understand the tool's user-facing functionality. |
| 28 | +4. [ ] **Study Rule Development:** The `docs/src/rules/` directory is critical. Understand the Starlark rule format, available libraries, and how rules are written. |
| 29 | +5. [ ] **Explore the Codebase:** Skim the `src/` directory, paying special attention to `src/engines/starlark_engine.rs` to see how Starlark integrates with the Rust code. |
24 | 30 |
|
25 | | -* `docs/src/introduction.md`: For a general overview. |
26 | | -* `docs/src/architecture.md`: To understand the high-level system design. |
27 | | -* `docs/src/cli_usage.md`: To understand how the tool is used from the command line. |
28 | | -* `docs/src/reverse/`: For reverse engineering specific functionalities. |
29 | | -* `docs/src/rules/`: **Crucially, for understanding Starlark rule development, format, and available libraries.** |
| 31 | +## 4. The Development Workflow |
30 | 32 |
|
31 | | -Use `read_file` and `read_many_files` to access documentation content. |
| 33 | +Follow this structured workflow for every task or feature. |
32 | 34 |
|
33 | | -### 2. Codebase Understanding |
| 35 | +### Step 1: Understand the Task |
| 36 | +- Deconstruct the request. If anything is unclear, ask for clarification. |
| 37 | +- Identify the core problem you need to solve. |
34 | 38 |
|
35 | | -* **Rust Modules:** Navigate the `src/` directory to understand module structure (`mod.rs` files), data structures, and function implementations. |
36 | | -* **Starlark Integration:** Pay close attention to `src/engines/starlark_engine.rs` and `src/parsers/syn_ast.rs` to understand how Starlark rules interact with the Rust AST (Abstract Syntax Tree) representation. |
37 | | -* **Existing Rules:** Examine existing Starlark rules in `rules/syn_ast/` and `src/static/starlark_rules/syn_ast/` to grasp the syntax and common patterns for static analysis. |
| 39 | +### Step 2: Explore & Research |
| 40 | +- **Documentation First:** Always begin by searching the project's `docs/` for relevant information. The documentation is the primary source of truth. |
| 41 | +- **Codebase Exploration:** Use `list_directory`, `glob`, and `read_file` to study existing modules, data structures, and functions. Look for similar implementations to maintain consistency. |
| 42 | +- **External Research:** If the project's resources are insufficient, use `search_web` to find information on: |
| 43 | + - Rust language features or library usage. |
| 44 | + - `starlark-rs` API and patterns. |
| 45 | + - Relevant Solana development concepts. |
38 | 46 |
|
39 | | -Use `list_directory`, `glob`, `read_file`, and `search_file_content` to explore the codebase. |
| 47 | +### Step 3: Implement |
| 48 | +- **Write Idiomatic Rust:** Adhere to Rust best practices, focusing on safety, performance, and clarity. |
| 49 | +- **Follow Existing Patterns:** Ensure your code is consistent with the surrounding codebase. |
| 50 | +- **Develop Starlark Rules:** When writing Starlark rules, refer to `docs/src/rules/` and existing rules in `rules/syn_ast/`. Use the provided Starlark libraries correctly. |
40 | 51 |
|
41 | | -### 3. Starlark Rule Development |
| 52 | +### Step 4: Verify & Test |
| 53 | +This is a non-negotiable step. High-quality code is tested code. |
42 | 54 |
|
43 | | -When working with Starlark rules: |
| 55 | +1. **Format:** Run `cargo fmt` to ensure consistent code style. |
| 56 | +2. **Check:** Run `cargo check` for fast compilation checks. |
| 57 | +3. **Lint:** Run `cargo clippy` to catch common mistakes and style issues. Address all warnings. |
| 58 | +4. **Test:** |
| 59 | + * Write **unit tests** for new logic within the relevant module. |
| 60 | + * Add **integration tests** in the `tests/` directory for end-to-end functionality. |
| 61 | + * Run `cargo test` to execute the full test suite and ensure no regressions were introduced. |
44 | 62 |
|
45 | | -* **Refer to `docs/src/rules/`:** This is your primary source for understanding rule format, available Starlark libraries (`src/static/starlark_libs/syn_ast.star`, `src/static/starlark_libs/template_manager.star`), and how to write effective rules. |
46 | | -* **Test Starlark Rules:** If a change involves Starlark rules, ensure they are tested. Look for existing test patterns in `test_starlark_condition_template/`. |
| 63 | +### Step 5: Document & Commit |
| 64 | +- **Update Documentation:** If your changes affect user-facing functionality, the architecture, or the rule system, update the corresponding `mdbook` documentation in the `docs/` directory. |
| 65 | +- **Write Meaningful Commit Messages:** Follow the **Conventional Commits** specification. This helps maintain a clear and automated version history. |
| 66 | + - **Format:** `<type>[optional scope]: <description>` |
| 67 | + - **Example:** `feat(analysis): add new detector for insecure delegatecall` |
| 68 | + - **Common types:** `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`. |
47 | 69 |
|
48 | | -### 4. Testing |
| 70 | +## 5. Debugging Guide |
49 | 71 |
|
50 | | -`sol-azy` is a Rust project, and testing should follow Rust's conventions. |
| 72 | +If you encounter an error or unexpected behavior: |
51 | 73 |
|
52 | | -* **Unit Tests:** For new functions or significant logic changes, write unit tests within the same file or a `tests/` module within the crate. Use `#[test]` attribute. |
53 | | -* **Integration Tests:** For end-to-end functionality, consider adding integration tests in the `tests/` directory at the crate root (e.g., `tests/my_feature_test.rs`). |
54 | | -* **Running Tests:** Always run tests after making changes. |
55 | | - * `cargo test` (runs all tests) |
56 | | - * `cargo test <test_name>` (runs a specific test) |
| 74 | +1. **Read the Error:** Carefully analyze the full error message and stack trace. |
| 75 | +2. **Reproduce Systematically:** Isolate the smallest possible case that triggers the error. |
| 76 | +3. **Hypothesize:** Form a hypothesis about the root cause. |
| 77 | +4. **Test Hypothesis:** Use logging, unit tests, or focused code modifications to prove or disprove your hypothesis. Iterate until the issue is resolved. |
57 | 78 |
|
58 | | -### 5. External Research |
59 | | - |
60 | | -If project documentation or existing code does not provide sufficient information, use `google_web_search` for: |
61 | | - |
62 | | -* Rust language features or best practices. |
63 | | -* `starlark-rs` specific usage or common patterns. |
64 | | -* Solana program development concepts relevant to the task. |
65 | | - |
66 | | -### 6. Code Quality & Verification |
67 | | - |
68 | | -After any code modification, always run the following commands to ensure code quality and correctness: |
69 | | - |
70 | | -* `cargo check`: To check for compilation errors. |
71 | | -* `cargo clippy`: To catch common mistakes and improve code style. |
72 | | -* `cargo fmt`: To format the code according to Rust conventions. |
73 | | -* `cargo test`: To run all tests and ensure no regressions. |
74 | | - |
75 | | -### 7. Commit Messages |
76 | | - |
77 | | -Write clear, concise, and descriptive commit messages. Follow the project's existing commit style. Focus on *why* the change was made, not just *what* was changed. |
78 | | - |
79 | | -By following these guidelines, the AI agent can effectively contribute to `sol-azy` as a high-quality, reliable, and efficient senior Rust engineer. |
| 79 | +By adhering to these guidelines, you will contribute effectively to `sol-azy` and uphold the standards of a senior Rust engineer. |
0 commit comments