Author's bio: ππ Hi, I'm CryptoPatrick! I'm currently enrolled as an Undergraduate student in Mathematics, at Chalmers & the University of Gothenburg, Sweden. If you have any questions or need more info, then please join my Discord Channel: AiMath
π Important Notices
- Twitter API Required: Requires Twitter API v2 Bearer Token for production use
- Storage: Uses Twitter threads as remote storage, SQLite for local indexing
- Experimental: v0.1 is a proof-of-concept suitable for research and creative projects
- Public by Default: All data is visible on Twitter (encryption coming in v0.2)
π€ What is xfiles
xfiles is a Rust library that treats Twitter as a public, append-only, log-structured filesystem. Tweets become "files", replies become "commits", and a local SQLite index keeps traversal fast.
Why? For transparent AI agents, public verifiability, distributed state, and creative experiments where Twitter serves as a globally verifiable shared memory bus.
Core Concept
Tweet (root) β File
Reply β Commit
Thread β Version history
SQLite β Local index/cache
Use Cases
- AI Agent Memory: Agents persist state to Twitter for transparency and recovery
- Multi-Agent Collaboration: Agents coordinate through shared Twitter threads
- Public Audit Trails: All operations are publicly visible and timestamped
- Distributed State: No single party controls the substrate
- Creative Experiments: Explore novel uses of social platforms as infrastructure
π· Features
xfiles provides a complete filesystem abstraction over Twitter with persistent local caching:
π§ Core Functionality
- Tweet as File Root: Each file starts with a root tweet
- Reply as Commit: Updates are posted as replies, forming a version chain
- Append-Only DAG: Git-like directed acyclic graph for version history
- SQLite Indexing: Fast local queries without hitting Twitter API
π Filesystem Operations
- File Creation:
open(path, Create)posts a root tweet - Reading:
read()fetches content from Twitter (cached locally) - Writing:
write(content)posts reply commits - History:
history(path)retrieves full commit chain - Listing:
list(dir)shows all files in a directory - Existence Checks:
exists(path)queries local index
π¦ Twitter Integration
- Twitter API v2: Full integration with modern Twitter API
- Bearer Token Auth: Simple authentication with Bearer Tokens
- Rate Limiting: Automatic backoff and retry logic
- Chunking: Transparent splitting of content >280 characters
- Error Handling: Robust error handling for API failures
πΎ Persistence
- SQLite Storage: Reliable file-based persistence
- Commit Tracking: DAG of all commits with timestamps
- Path Mapping: Files map to Twitter thread roots
- Content Caching: Avoid redundant API calls
- Session Continuity: Resume operations across restarts
π Architecture
- π Overall Architecture
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User Application (Agent/CLI/Backend) β
β Single call: fs.open().write() β
ββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββ
β XFS Component β
β β’ Open files (create root tweets) β
β β’ Read content (fetch from Twitter) β
β β’ Write updates (post reply tweets) β
β β’ List files (query SQLite index) β
β β’ Track history (traverse DAG) β
ββββββββββββββββ¬βββββββββββββββββββββββββββ¬βββββββββββββββββ
β β
βββββββββΌβββββββββ ββββββββββΌββββββββββ
β Twitter Adapterβ β SQLite Store β
β β’ API calls β β β’ Commit index β
β β’ Rate limit β β β’ File mapping β
β β’ Chunking β β β’ Cache layer β
ββββββββββ¬ββββββββ ββββββββββββββββββββ
β
βββββββββΌβββββββββ
β Twitter API β
β β’ GET tweet β
β β’ POST tweet β
β β’ GET replies β
ββββββββββββββββββ
User β XFS β SQLite Index + Twitter API β Remote Storage
- π Data Flow Diagram
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β file.write("Agent state v2") β
ββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
ββββββββββΌβββββββββ
β 1. Compute β
β Hash β
β (blake3) β
βββββββββββ¬ββββββββ
β
β content hash
βΌ
ββββββββββββββββββββββ
β 2. Chunk β
β Content β
β (if >280 chars) β
βββββββββββ¬βββββββββββ
β
β chunks[]
βΌ
ββββββββββββββββββββββ
β 3. Post Reply β
β to Twitter β
β (TwitterAdapter) β
βββββββββββ¬βββββββββββ
β
β tweet_id
βΌ
ββββββββββββββββββββββ
β 4. Create Commit β
β β’ id = tweet_id β
β β’ parent = head β
β β’ hash, timestamp β
βββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββ
β 5. Store Commit β
β in SQLite β
β β’ Update index β
β β’ Mark as head β
β β’ Cache content β
ββββββββββββββββββββββ
- πΎ Storage Layer Architecture
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β XFS β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Public API β β
β β β’ open(path, mode) β XFile β β
β β β’ list(dir) β Vec<String> β β
β β β’ history(path) β Vec<Commit> β β
β β β’ exists(path) β bool β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ
β β XFile Operations ββ
β β β’ read() β Vec<u8> ββ
β β β’ write(content) β Result<()> ββ
β β β’ delete() β Result<()> ββ
β ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βββββββββββββββββββΌβββββββββββββββββββββ
β SQLite Database (file.db) β
β βββββββββββββββββββββββββββββββββββ β
β β files β β
β β - path (PK) β β
β β - root_tweet_id β β
β β - created_at β β
β βββββββββββββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββ β
β β commits β β
β β - tweet_id (PK) β β
β β - parent_id (JSON array) β β
β β - timestamp β β
β β - author β β
β β - hash (blake3) β β
β β - mime β β
β β - size β β
β β - head (boolean) β β
β βββββββββββββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββ β
β β chunks β β
β β - tweet_id (PK) β β
β β - parent_commit (FK) β β
β β - idx (chunk order) β β
β β - size, hash β β
β βββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββ
- β³ Commit Lifecycle
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User calls file.write(content) β
βββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 1. Chunk Content β
β β’ Split into 280-byte chunks if needed β
β β’ Compute blake3 hash of full content β
βββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 2. Post to Twitter API β
β β’ Post first chunk as reply to current head β
β β’ Post remaining chunks as reply chain β
β β’ Receive tweet_id for each chunk β
βββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 3. Create Commit Object β
β β’ id = first chunk tweet_id β
β β’ parents = [current_head] β
β β’ hash = content hash β
β β’ timestamp = now() β
β β’ author = username β
βββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 4. Persist to SQLite β
β β’ INSERT INTO commits β
β β’ UPDATE files SET head β
β β’ Cache content for fast reads β
βββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 5. Publicly Visible on Twitter β
β β’ Tweet URL: https://twitter.com/i/web/status/{id} β
β β’ Timestamped by Twitter β
β β’ Immutable and auditable β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π How to Use
Installation
Add xfiles to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
Or install with cargo:
Twitter API Setup
Before using xfiles with real Twitter, you need API credentials:
- Go to https://developer.twitter.com/en/portal/dashboard
- Create a project and app
- Generate Bearer Token under "Keys and tokens"
- See docs/TWITTER_SETUP.md for detailed instructions
Basic Example (Mock Adapter)
use *;
use Arc;
async
Real Twitter API Example
use *;
async
Advanced Usage
use *;
async
π§ͺ Examples
The repository includes several examples demonstrating different features:
# Mock adapter example (no Twitter API needed)
# Real Twitter API example (requires credentials)
Example Output
=== xfiles Basic Example ===
1. Creating a new file...
β Created file: memory.txt
2. Writing to file...
β Wrote initial content
3. Reading file content...
Content: Day 1: Agent initialized
4. Writing multiple updates...
β Created commit chain
5. Reading latest version...
Latest: Day 3: Successfully stored memory
6. Getting file history...
Total commits: 4
Commit 1: mock_tweet_1 (2026-01-16 12:28:15 UTC)
Commit 2: mock_tweet_2 (2026-01-16 12:28:15 UTC)
Commit 3: mock_tweet_3 (2026-01-16 12:28:15 UTC)
Commit 4: mock_tweet_4 (2026-01-16 12:28:15 UTC)
π§ͺ Testing
Run the test suite:
# Run all tests (uses mock adapter)
# Run specific test suite
# Run with output
All tests use the MockAdapter, so no Twitter API credentials are needed for testing.
π Documentation
Comprehensive documentation is available:
- API Documentation - Full API reference
- Twitter Setup Guide - Get Twitter API credentials and setup
- Contributing Guide - Development guidelines and workflow
Key Concepts
- Files: Mapped to Twitter thread roots, tracked in SQLite
- Commits: Each write creates a new tweet reply
- DAG: Git-like directed acyclic graph for version history
- Chunking: Content >280 chars automatically split across multiple tweets
- Caching: SQLite caches content to minimize API calls
Performance Notes
- Reads: Cached in SQLite (no API call on cache hit)
- Writes: Rate-limited by Twitter API (300 tweets/15min)
- Chunking: Transparent for content > 280 chars
- Rate Limiting: Automatic exponential backoff
Twitter API v2 Free Tier limits:
- 50 tweet reads / 15 min
- 300 tweet posts / 15 min
π Author
CryptoPatrick
Keybase Verification: https://keybase.io/cryptopatrick/sigs/8epNh5h2FtIX1UNNmf8YQ-k33M8J-Md4LnAN
π£ Support
Leave a β if you think this project is cool.
π License
This project is licensed under MIT. See LICENSE for details.
Inspired by:
- Git (DAG commits, history)
- IPFS (content-addressed chunks)
- CRDTs (distributed updates)
- Blockchains (timestamped logs)
Made with β for transparent AI agents