How It Works
The system uses compile-time type extraction to discover all operations and generate client code during the build process. This eliminates the traditional API boundary.Define Operations
Operations are either Actions (write) or Queries (read):Register and Generate
Register the operation with a single macro:- Extracts type information using Specta
- Generates Swift and TypeScript type definitions
- Creates native API methods for each client
Use Generated Clients
Swift:Operation Types
Actions
Actions modify state and typically return job receipts or updated entities:Validation and Confirmation
Actions support a validation phase that can request user confirmation before execution. This enables safe, interactive operations with clear user feedback.ValidationResult
Thevalidate() method returns one of two results:
Example: File Copy with Conflict Resolution
CLI Integration
The CLI handles confirmations interactively:The
validate() method takes &self (a reference), while execute() takes self (consumes the action). This ensures validation doesn’t modify state, while execution can take ownership to transform the action into its result.Queries
Queries retrieve data without side effects:Type System
All standard Rust types are supported through Specta:The
Type derive is required for all types used in operations. This enables
Specta to extract type information for client generation.Wire Protocol
Operations use a consistent wire protocol:- Actions:
action:{category}.{operation}.input.v{version} - Queries:
query:{scope}.{operation}.v{version}
action:files.copy.inputquery:library.stats
Adding Operations
1. Create Input/Output Types
2. Implement the Operation
For a query:3. Register It
4. Build and Use
After building, the operation is available in all clients automatically.iOS Integration
The iOS app embeds the Rust core and communicates through FFI:Code Generation Details
Build Process
The build script runs duringcargo build:
Type Extraction
A binary extracts all registered operations:Registration Internals
The registration macros use inventory for compile-time collection:Best Practices
Operation Design
Keep operations focused with clear inputs and outputs. Use appropriate scopes (Library vs Core) based on whether the operation needs library context.When to Use Validation Confirmations
Use the confirmation pattern for operations that:- Have Destructive Side Effects: Deleting files, overwriting data, or making irreversible changes
- Encounter Conflicts: File name collisions, duplicate entries, or conflicting states
- Need User Decisions: Multiple valid approaches where user preference matters
- Risk Data Loss: Operations that could result in unexpected data loss
- File copy/move when destination exists
- Deleting non-empty directories
- Overwriting modified files
- Removing locations with indexed content
- Irreversible format conversions
Type Design
Flatten structures when possible and use Rust enums for variants. Document fields as comments flow through to generated code.Error Handling
Define specific error types for each operation:Performance
For large result sets, consider pagination or streaming:Advanced Features
Batch Operations
Operation Metadata
Actions can define metadata for UI presentation:Confirmation is handled dynamically through the
validate() method, not as static metadata. This allows context-aware confirmations based on the actual operation state.