|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Contributions welcome. Read [RUST_STYLE_GUIDE.md](RUST_STYLE_GUIDE.md) before writing any code, and [AGENTS.md](AGENTS.md) for the full implementation guide. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +- **Rust** 1.85+ with `rustfmt` and `clippy` |
| 10 | +- **protoc** (protobuf compiler) |
| 11 | +- **bun** (for frontend/interface work) |
| 12 | +- **just** (`brew install just` or `cargo install just --locked`) |
| 13 | + |
| 14 | +Optional: [Nix flakes](https://nixos.org/) for isolated dev environments (`nix develop` gives you everything). |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## Getting Started |
| 19 | + |
| 20 | +1. Fork the repo and create a feature branch |
| 21 | +2. Run `./scripts/install-git-hooks.sh` (installs a pre-commit hook that runs `cargo fmt`) |
| 22 | +3. `cargo build` to verify the backend compiles |
| 23 | +4. For frontend work: `cd interface && bun install` |
| 24 | +5. Make your changes |
| 25 | +6. Run `just preflight && just gate-pr` |
| 26 | +7. Submit a PR |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 30 | +## PR Gate |
| 31 | + |
| 32 | +Every PR must pass `just gate-pr` before merge. This mirrors CI and checks: |
| 33 | + |
| 34 | +1. **Migration safety** — new migrations only, never edit existing ones |
| 35 | +2. **Formatting** — `cargo fmt --all -- --check` |
| 36 | +3. **Compile** — `cargo check --all-targets` |
| 37 | +4. **Lints** — `cargo clippy --all-targets -Dwarnings` |
| 38 | +5. **Tests** — `cargo test --lib` |
| 39 | +6. **Integration compile** — `cargo test --tests --no-run` |
| 40 | + |
| 41 | +Use `just gate-pr --fast` to skip clippy and integration compile during iteration. |
| 42 | + |
| 43 | +The frontend CI (`interface-ci.yml`) runs `bun ci` and `bunx tsc --noEmit` on interface changes. |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## Project Structure |
| 48 | + |
| 49 | +Single binary crate (no workspace). Key directories: |
| 50 | + |
| 51 | +``` |
| 52 | +src/ |
| 53 | +├── main.rs — CLI entry, config, startup |
| 54 | +├── lib.rs — re-exports |
| 55 | +├── config.rs — config loading/validation |
| 56 | +├── error.rs — top-level Error enum |
| 57 | +├── llm/ — LlmManager, model routing, providers |
| 58 | +├── agent/ — Channel, Branch, Worker, Compactor, Cortex |
| 59 | +├── hooks/ — SpacebotHook, CortexHook |
| 60 | +├── tools/ — reply, branch, spawn_worker, memory_*, etc. |
| 61 | +├── memory/ — MemoryStore, hybrid search, graph ops |
| 62 | +├── messaging/ — Discord, Telegram, Slack, webhook adapters |
| 63 | +├── conversation/ — history persistence, context assembly |
| 64 | +├── cron/ — scheduler, CRUD |
| 65 | +├── identity/ — SOUL.md, IDENTITY.md, USER.md loading |
| 66 | +├── secrets/ — encrypted credentials (AES-256-GCM) |
| 67 | +├── settings/ — key-value settings |
| 68 | +└── db/ — SQLite migrations, connection setup |
| 69 | +
|
| 70 | +interface/ — Dashboard UI (Vite + React + TypeScript) |
| 71 | +prompts/ — LLM prompts as markdown (not Rust strings) |
| 72 | +docs/ — Documentation site (MDX) |
| 73 | +desktop/ — Tauri desktop app |
| 74 | +scripts/ — Dev tooling (hooks, gates, builds) |
| 75 | +``` |
| 76 | + |
| 77 | +Module roots use `src/module.rs`, **not** `src/module/mod.rs`. |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## Rust Conventions |
| 82 | + |
| 83 | +The full guide is in [RUST_STYLE_GUIDE.md](RUST_STYLE_GUIDE.md). Key points: |
| 84 | + |
| 85 | +**Imports** — three tiers separated by blank lines: (1) crate-local, (2) external crates, (3) std. |
| 86 | + |
| 87 | +**Error handling** — domain errors per module, wrapped by top-level `Error` enum via `#[from]`. Use `?` and `.context()`. Never silently discard with `let _ =`. |
| 88 | + |
| 89 | +**Async** — native RPITIT for async traits (not `#[async_trait]`). `tokio::spawn` for concurrent work. Clone before moving into async blocks. |
| 90 | + |
| 91 | +**Logging** — `tracing` crate, never `println!`. Structured key-value fields. `#[tracing::instrument]` for spans. |
| 92 | + |
| 93 | +**Lints** (enforced in Cargo.toml): `dbg_macro = "forbid"`, `todo = "forbid"`, `unimplemented = "forbid"`. |
| 94 | + |
| 95 | +**Testing** — `#[cfg(test)]` at end of file. `#[tokio::test]` for async. `.unwrap()` is fine in tests only. |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## Frontend (Interface) |
| 100 | + |
| 101 | +Use **bun** exclusively — never npm, pnpm, or yarn. |
| 102 | + |
| 103 | +```bash |
| 104 | +cd interface |
| 105 | +bun install # install deps |
| 106 | +bun run dev # dev server |
| 107 | +bun run build # production build |
| 108 | +``` |
| 109 | + |
| 110 | +### SpaceUI Packages |
| 111 | + |
| 112 | +The dashboard uses `@spacedrive/*` packages published to npm from the [spaceui](https://github.com/spacedriveapp/spaceui) monorepo: |
| 113 | + |
| 114 | +- `@spacedrive/primitives` — base UI components |
| 115 | +- `@spacedrive/ai` — AI chat components |
| 116 | +- `@spacedrive/forms` — form components |
| 117 | +- `@spacedrive/explorer` — file explorer components |
| 118 | +- `@spacedrive/tokens` — design tokens |
| 119 | + |
| 120 | +`package.json` points to npm versions (e.g. `"^0.2.0"`). CI pulls from the registry. For local development, `bun link` overrides them with your local copies. |
| 121 | + |
| 122 | +**Local SpaceUI development:** |
| 123 | + |
| 124 | +Clone the spaceui repo adjacent to this one, then run the link command: |
| 125 | + |
| 126 | +```bash |
| 127 | +git clone https://github.com/spacedriveapp/spaceui ../spaceui |
| 128 | +just spaceui-link |
| 129 | +``` |
| 130 | + |
| 131 | +This builds SpaceUI, registers all packages as global links, and connects them to `interface/`. Use `bun run watch` in the SpaceUI repo for automatic rebuilds. |
| 132 | + |
| 133 | +To unlink and restore npm versions: `just spaceui-unlink`. |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +## Useful Commands |
| 138 | + |
| 139 | +```bash |
| 140 | +just preflight # validate git/remote state |
| 141 | +just gate-pr # full PR gate (mirrors CI) |
| 142 | +just gate-pr --fast # skip clippy + integration compile |
| 143 | +just typegen # generate TypeScript API types |
| 144 | +just check-typegen # verify types match |
| 145 | +just build-opencode-embed # build OpenCode embed bundle |
| 146 | +just bundle-sidecar # build Tauri sidecar |
| 147 | +just desktop-dev # run desktop app in dev mode |
| 148 | +just update-frontend-hash # update Nix hash after frontend dep changes |
| 149 | +``` |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +## Migrations |
| 154 | + |
| 155 | +SQLite migrations are **immutable**. Never edit an existing migration file. Always create a new timestamped migration for schema changes. |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +## Architecture |
| 160 | + |
| 161 | +See [ARCHITECTURE.md](ARCHITECTURE.md) for the full design. The short version: five process types, each with one job. |
| 162 | + |
| 163 | +- **Channels** — user-facing LLM, stays responsive, never blocks on work |
| 164 | +- **Branches** — fork channel context to think, return conclusion, get deleted |
| 165 | +- **Workers** — independent task execution with focused tools, no conversation context |
| 166 | +- **Compactor** — programmatic context monitor, triggers compaction before channels fill up |
| 167 | +- **Cortex** — system observer, generates memory bulletins, supervises processes |
| 168 | + |
| 169 | +Key rule: **never block the channel**. Branch to think, spawn workers to act. |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +## Release Process |
| 174 | + |
| 175 | +Releases are triggered by git tags (`v*`). The CI workflow: |
| 176 | + |
| 177 | +1. Verifies `Cargo.toml` version matches the tag |
| 178 | +2. Builds multi-platform binaries (x86_64/aarch64, Linux/macOS) |
| 179 | +3. Builds Docker images (amd64/arm64) |
| 180 | +4. Creates a GitHub release with binaries |
| 181 | +5. Updates the Homebrew tap |
| 182 | + |
| 183 | +--- |
| 184 | + |
| 185 | +## License |
| 186 | + |
| 187 | +FSL-1.1-ALv2 ([Functional Source License](https://fsl.software/)), converting to Apache 2.0 after two years. |
0 commit comments