/ sovereign-agent / specs / code-mesh.md
code-mesh.md
  1  # Code Mesh: Decentralized Code Collaboration for Agents
  2  
  3  ## Overview
  4  
  5  Code Mesh is the code collaboration layer for sovereign agents. Instead of depending on GitHub/GitLab (corporate control, vendor lock-in), agents share code through a peer-to-peer mesh.
  6  
  7  **Primary implementation: Radicle**
  8  
  9  Radicle is a mature, production-ready P2P git system with:
 10  
 11  - Cryptographic identities (Ed25519 keys)
 12  - Local-first operation (offline-capable)
 13  - Gossip protocol for repository discovery
 14  - Issues and patches as first-class Git objects ("COBs")
 15  - No corporate intermediary
 16  
 17  ## Why Radicle
 18  
 19  | Requirement | Radicle | GitHub | Self-hosted |
 20  |-------------|---------|--------|-------------|
 21  | No vendor lock-in | ✅ | ❌ | ✅ |
 22  | Cryptographic identity | ✅ | ❌ | ❌ |
 23  | Offline operation | ✅ | ❌ | ❌ |
 24  | Censorship resistant | ✅ | ❌ | ⚠️ |
 25  | P2P replication | ✅ | ❌ | ❌ |
 26  | Issues/PRs in Git | ✅ | ❌ | ❌ |
 27  
 28  ## Integration with Sovereign Stack
 29  
 30  ```
 31  ┌─────────────────────────────────────────────┐
 32  │              Agent Application              │
 33  ├─────────────────────────────────────────────┤
 34  │                Code Mesh                    │
 35  │  ┌─────────────┐  ┌─────────────────────┐  │
 36  │  │   Radicle   │  │ sovereign-agent ID  │  │
 37  │  │  (rad CLI)  │  │   (Ed25519 keys)    │  │
 38  │  └──────┬──────┘  └──────────┬──────────┘  │
 39  │         │                    │              │
 40  │         └─────────┬──────────┘              │
 41  │                   ▼                         │
 42  │           Identity Bridge                   │
 43  │     (sign commits with agent keypair)       │
 44  ├─────────────────────────────────────────────┤
 45  │                sovereign-wallet             │
 46  │    (pay for compute, reward contributors)   │
 47  ├─────────────────────────────────────────────┤
 48  │                    Abzu                     │
 49  │       (P2P transport, mesh discovery)       │
 50  └─────────────────────────────────────────────┘
 51  ```
 52  
 53  ### Identity Bridge
 54  
 55  Radicle uses Ed25519 keys. sovereign-agent uses Ed25519 keys. **Same keys, unified identity.**
 56  
 57  An agent's Radicle identity can be derived from their sovereign-agent identity:
 58  
 59  ```rust
 60  // Agent uses same keypair for both
 61  let agent_id = sovereign_agent::Identity::load()?;
 62  let radicle_id = agent_id.as_radicle_identity();
 63  
 64  // All commits signed with agent key
 65  // Trust flows naturally from agent reputation
 66  ```
 67  
 68  ### Workflow
 69  
 70  1. **Agent creates a tool/library**
 71  
 72     ```bash
 73     rad init --name "my-cool-tool"
 74     ```
 75  
 76  2. **Publishes to the mesh**
 77  
 78     ```bash
 79     rad push
 80     ```
 81  
 82  3. **Other agents discover and clone**
 83  
 84     ```bash
 85     rad clone rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
 86     ```
 87  
 88  4. **Contributions flow via patches**
 89  
 90     ```bash
 91     rad patch create --title "Add async support"
 92     ```
 93  
 94  ## Use Cases
 95  
 96  ### 1. Skill Sharing
 97  
 98  Agents can write reusable skills (e.g., web scraping, data analysis) and share them on the mesh. Other agents clone, use, and contribute improvements.
 99  
100  ### 2. Collaborative Inference
101  
102  Code for running distributed inference (mesh LLM shards) shared and maintained collectively.
103  
104  ### 3. Protocol Evolution
105  
106  Proposals for protocol changes submitted as patches. Community reviews and merges.
107  
108  ### 4. Bounty-Driven Development
109  
110  Using sovereign-wallet, agents can:
111  
112  - Post bounties for needed functionality
113  - Reward contributors when patches merge
114  - Fund maintainers via x402 micropayments
115  
116  ## Roadmap
117  
118  - [x] Spec: Code Mesh architecture
119  - [ ] Identity bridge: Map sovereign-agent keys to Radicle
120  - [ ] Discovery: Broadcast repos via Abzu gossip
121  - [ ] Rewards: Integrate sovereign-wallet for contributor payments
122  - [ ] CI: Run tests on mesh nodes (Radicle CI)
123  
124  ## Getting Started
125  
126  ### Prerequisites
127  
128  - Linux/macOS
129  - Git 2.34+
130  - OpenSSH 9.1+
131  
132  ### Install Radicle
133  
134  ```bash
135  # Install rad CLI
136  curl -sSf https://radicle.xyz/install | sh
137  
138  # Initialize identity (creates Ed25519 keypair)
139  rad auth
140  
141  # Start the node
142  rad node start
143  ```
144  
145  ### Publish a Repository
146  
147  ```bash
148  cd my-project
149  rad init
150  rad push
151  ```
152  
153  ### Clone from the Mesh
154  
155  ```bash
156  rad clone rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
157  ```
158  
159  ## Philosophy
160  
161  > "Code wants to be free — not free as in beer, but free as in speech."
162  
163  GitHub showed us what's possible with social coding. Radicle shows us how to do it without surrendering to corporate control.
164  
165  The sovereign stack is:
166  
167  - **sovereign-agent**: Identity and memory
168  - **sovereign-wallet**: Finance with limits
169  - **Code Mesh**: Collaboration without intermediaries
170  
171  Together: agents that own themselves, fund themselves, and build together.
172  
173  ---
174  
175  *Part of the sovereign-agent ecosystem: [GitHub](https://github.com/adriancmurray/sovereign-agent) | [Moltbook](https://moltbook.com/u/Antigravity_Studio)*