Quick Start
Prerequisites
Rust 1.78+
Install via rustup.rs
macOS 13.0+
Currently required for Phase 1 development
Clone and Build
./target/release/agent-desktop (under 15MB optimized).
Common Commands
Running the Binary
After building, test with:Grant Accessibility permission before running: System Settings > Privacy & Security > Accessibility → add your terminal app.
Project Structure
Workspace Members
| Crate | Path | Purpose |
|---|---|---|
agent-desktop-core | crates/core/ | Platform-agnostic logic, PlatformAdapter trait |
agent-desktop-macos | crates/macos/ | macOS implementation (Phase 1) |
agent-desktop-windows | crates/windows/ | Windows stub (Phase 2) |
agent-desktop-linux | crates/linux/ | Linux stub (Phase 2) |
agent-desktop (binary) | src/ | CLI entry point, dispatch, JSON envelope |
Shared Dependencies
Workspace-level dependencies in rootCargo.toml:
Coding Standards
File Rules
- One struct/enum per file for domain types
- One command per file under
commands/ - No inline comments — code must be self-documenting
- Only doc-comments (
///) on public items when name alone is insufficient - No God objects — max 7 fields per struct, max 5 params per function
Naming Conventions
| Element | Convention | Example |
|---|---|---|
| Crate names | agent-desktop-{name} | agent-desktop-core |
| Module files | snake_case, singular | snapshot.rs |
| Structs | PascalCase, descriptive noun | SnapshotEngine |
| Traits | PascalCase, adjective | PlatformAdapter |
| Enums | PascalCase, variants PascalCase | Action::Click |
| Functions | snake_case, verb-first | build_tree() |
| Constants | SCREAMING_SNAKE_CASE | MAX_TREE_DEPTH |
| CLI flags | kebab-case | --max-depth |
| Ref IDs | @e{n} sequential | @e1, @e14 |
Error Handling
Zero unwrap()
All
Results propagated with ? or matched explicitly. Panics are test-only.Structured Errors
Every error has:
ErrorCode, message, suggestion, platform_detail0— success1— structured error (JSON on stdout)2— argument/parse error
Adding a New Command
(Optional) Add Action variant
If the command needs a new
Action type, add to crates/core/src/action.rs:No existing files are modified beyond these registration points. This is enforced via code review.
Testing Strategy
Unit Tests (Core)
Tests incrates/core/src/:
AccessibilityNodeser/de roundtrips- Ref allocator only assigns interactive roles
SnapshotEnginefiltering logic- Error serialization format
MockAdapterfor isolated testing
Platform Tests (macOS)
Tests incrates/macos/src/:
- Tree traversal correctness
- Role mapping coverage
- Action execution
- Permission detection
Golden Fixtures
tests/fixtures/ contains real snapshots from Finder, TextEdit, etc. for regression testing:
Integration Tests (macOS CI)
tests/integration/ runs full command scenarios:
- Snapshot Finder → non-empty tree with refs
- Click button in test app → verify action succeeded
- Type text into TextEdit via ref → verify content changed
- Clipboard get/set roundtrip
- Permission denied scenario → correct error code
Linting & Formatting
Clippy Rules
Project uses strict linting (clippy.toml):
Formatting
Standard Rust formatting:Dependency Verification
CI enforces dependency inversion:macos, windows, or linux, the build fails.
Build Profiles
Debug (Default)
Fast compilation, large binary, no optimizations:Release
Optimized for size (under 15MB target):Platform Crate Guidelines
Folder Placement
All platform crates follow identical structure:- Tree reading →
tree/ - Element interaction →
actions/ - Raw OS input →
input/ - App lifecycle →
system/
Safety Rules (macOS)
ForAXElement wrapper:
- Inner field must be
pub(crate)notpub Clonemust callCFRetainDropmust callCFRelease- No direct pointer extraction to prevent double-free
CI Requirements
GitHub Actions runs on every PR:Git Workflow
Conventional Commits
All commits must use a type prefix:feat:— new feature (triggers minor version bump)fix:— bug fix (triggers patch version bump)feat!:orBREAKING CHANGE:— breaking change (major bump)docs:— documentation onlyrefactor:— code change that neither fixes nor addschore:— maintenance tasks, dependenciesci:— CI/CD changestest:— adding or fixing tests
type: concise imperative description (lowercase type, no capital after colon)
Examples:
Focus on “why” not “what”. The diff shows what changed; the message explains why.
Performance Tips
macOS Tree Traversal
Batch Attributes
Use
AXUIElementCopyMultipleAttributeValues for 3-5x speedup vs. individual callsMax Depth
Default
--max-depth 10 prevents infinite loops. Adjust if needed.Ancestor Paths
Use ancestor-path sets, not global visited sets (macOS reuses pointers)
Interactive-Only
Use
-i flag to skip static elements and reduce tree size by ~70%Debugging
Enable Tracing
error, warn, info, debug, trace
Inspect JSON Output
Check RefMap
Ref storage:Contributing
Next Steps
Architecture
Understand the workspace structure and design patterns
Troubleshooting
Common issues and solutions