|
| 1 | +# 🌟 Contribute to Refact.ai Agent |
| 2 | + |
| 3 | +Welcome to the Refact.ai project! We're excited to have you join our community. Whether you're a first-time contributor or a seasoned developer, here are some impactful ways to get involved. |
| 4 | + |
| 5 | + |
| 6 | +## 📚 Table of Contents |
| 7 | +- [❤️ Ways to Contribute](#%EF%B8%8F-ways-to-contribute) |
| 8 | + - [🐛 Report Bugs](#-report-bugs) |
| 9 | + - [Contributing To Code](#contributing-to-code) |
| 10 | + - [ What Can I Do](#what-can-i-do) |
| 11 | + - [Coding Standards](#coding-standards) |
| 12 | + - [Testing](#testing) |
| 13 | + - [Contact](#contact) |
| 14 | + |
| 15 | + |
| 16 | +### ❤️ Ways to Contribute |
| 17 | + |
| 18 | +* Fork the repository |
| 19 | +* Create a feature branch |
| 20 | +* Do the work |
| 21 | +* Create a pull request |
| 22 | +* Maintainers will review it |
| 23 | + |
| 24 | +### 🐛 Report Bugs |
| 25 | +Encountered an issue? Help us improve Refact.ai by reporting bugs in issue section, make sure you label the issue with correct tag [here](https://github.com/smallcloudai/refact-lsp/issues)! |
| 26 | + |
| 27 | +### 📖 Improving Documentation |
| 28 | +Help us make Refact.ai more accessible by contributing to our documentation, make sure you label the issue with correct tag! Create issues [here](https://github.com/smallcloudai/web_docs_refact_ai/issues). |
| 29 | + |
| 30 | +### Contributing To Code |
| 31 | + |
| 32 | +#### What Can I Do? |
| 33 | + |
| 34 | +Before you start, create an issue with a title that begins with `[idea] ...`. The field of AI and agents is vast, |
| 35 | +and not every idea will benefit the project, even if it is a good idea in itself. |
| 36 | + |
| 37 | +Another rule of thumb: Only implement a feature you can test thoroughly. |
| 38 | + |
| 39 | + |
| 40 | +#### Coding Standards |
| 41 | + |
| 42 | +Good practices for Rust are generally applicable to this project. There are a few points however: |
| 43 | + |
| 44 | +1. Naming. Use "Find in files..." to check if a name you give to your structs, fields, functions is too |
| 45 | +generic. If a name is already all over the project, be more specific. For example "IntegrationGitHub" is a good |
| 46 | +name, but "Integration" is not, even if it's in `github.rs` and files work as namespaces in Rust. It's |
| 47 | +still hard to navigate the project if you can't use search. |
| 48 | + |
| 49 | +2. Locks. For some reason, it's still hard for most people, and for current AI models, too. Refact is |
| 50 | +multi-threaded, locks are necessary. But locks need to be activated for the shortest time possible, this |
| 51 | +is how you use `Arc<AMutex<>>` to do it: |
| 52 | + |
| 53 | +```rust |
| 54 | +struct BigStruct { |
| 55 | + ... |
| 56 | + pub small_struct: Arc<AMutex<SmallStruct>>; |
| 57 | +} |
| 58 | + |
| 59 | +fn some_code(big_struct: Arc<AMutex<BigStruct>>) |
| 60 | +{ |
| 61 | + let small_struct = { |
| 62 | + let big_struct_locked = big_struct.lock().await; |
| 63 | + big_struct_locked.small_struct.clone() // cloning Arc is cheap |
| 64 | + // big_struct_locked is destroyed here because it goes out of scope |
| 65 | + }; |
| 66 | + // use small_struct without holding big_struct_locked |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +Another multi-threaded trick, move a member function outside of a class: |
| 71 | + |
| 72 | +```rust |
| 73 | +struct MyStruct { |
| 74 | + pub data1: i32, |
| 75 | + pub data2: i32, |
| 76 | +} |
| 77 | + |
| 78 | +impl MyStruct { |
| 79 | + pub fn lengthy_function1(&mut self) { } |
| 80 | +} |
| 81 | + |
| 82 | +fn some_code(my_struct: Arc<AMutex<SmallStruct>>) |
| 83 | +{ |
| 84 | + my_struct.lock().await.lengthy_function1(); |
| 85 | + // Whoops, lengthy_function has the whole structure locked for a long time, |
| 86 | + // and Rust won't not let you unlock it |
| 87 | +} |
| 88 | + |
| 89 | +pub fn lengthy_function2(s: Arc<AMutex<SmallStruct>>) |
| 90 | +{ |
| 91 | + let (data1, data2) = { |
| 92 | + let s_locked = s.lock().await; |
| 93 | + (s_locked.data1.clone(), s_locked.data2.clone()) |
| 94 | + } |
| 95 | + // Do lengthy stuff here without locks! |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +Avoid nested locks, avoid RwLock unless you know what you are doing. |
| 100 | + |
| 101 | + |
| 102 | +#### Testing |
| 103 | + |
| 104 | +It's a good idea to have tests in source files, and run them using `cargo test`, and we |
| 105 | +have CI in place to run it automatically. |
| 106 | +But not everything can be tested solely within Rust tests, for example a Rust test cannot run |
| 107 | +an AI model inside. |
| 108 | + |
| 109 | +So we have `tests/*.py` scripts that expect the `refact-lsp` process to be running on port 8001, |
| 110 | +and the project itself as a workspace dir: |
| 111 | + |
| 112 | + |
| 113 | +```bash |
| 114 | +cargo build && target/debug/refact-lsp --http-port 8001 --reset-memory --experimental --workspace-folder . --logs-stderr --vecdb --ast |
| 115 | +``` |
| 116 | + |
| 117 | +Running those tests is still manual. To make sure your work didn't break other features, |
| 118 | +run tests for things you might have broken. |
| 119 | + |
| 120 | + |
| 121 | +#### Contact |
| 122 | + |
| 123 | +If you have any questions or concerns, please contact the project maintainers on Discord: |
| 124 | +https://www.smallcloud.ai/discord |
0 commit comments