[TASK] Blueprint for compiling blueprints in docker
Overview
Adding a spec below.
The Blueprint Agent interface will want to remotely host docker containers for compiling code.
๐ง One-Shot Prompt: Build a Tangle Blueprint for Streaming Remote Rust Builds with P2P WebSocket Output
Design and implement a Tangle Blueprint that compiles full Rust projects submitted by users, and streams build logs and results over WebSocket to the original requestor. The build is executed in an isolated environment and should support full project structures (including workspaces).
The connection to the user is established via P2P session identity, allowing bidirectional communication for logs, result signaling, and future extensibility (e.g., test results, code audit feedback, etc.).
๐๏ธ Project Structure
rust-build-agent/
โโโ rust-build-agent-bin/
โ โโโ src/
โ โ โโโ main.rs # BlueprintRunner, job router, P2P setup
โ โโโ Cargo.toml
โโโ rust-build-agent-lib/
โ โโโ src/
โ โ โโโ lib.rs
โ โ โโโ context.rs
โ โ โโโ jobs/
โ โ โ โโโ compile_project.rs # Main job handler
โ โ โ โโโ test_project.rs # (Optional) runs `cargo test`
โ โ โ โโโ lint_project.rs # (Optional) runs `cargo clippy`
โ โ โโโ network/
โ โ โ โโโ websocket_dispatcher.rs
โ โ โ โโโ peer_session.rs
โ โ โ โโโ identity.rs
โ โ โโโ utils/
โ โ โโโ sandbox.rs # Tempdir, process isolation, CPU/mem caps
โ โ โโโ zip.rs # For unpacking project sources
โ โ โโโ stream.rs # Line-by-line stdout streaming
โ โโโ tests/
โ โโโ compile_fixture.rs
โโโ contracts/
โ โโโ BuildAgentServiceManager.sol # (Optional) enforces job input format/payment
๐ฉ Blueprint Job: compile_rust_project (JOB_ID_COMPILE)
Inputs (TangleArgs3)
TangleArgs3<
String, // zip_uri: HTTPS or IPFS URI to zipped Rust project
String, // session_id: UUID string tied to P2P/WebSocket stream
Optional<String> // build_target (e.g. "release", "check", "clippy")
>
Execution
-
Download and unzip project archive
-
Validate it's a valid Rust crate or workspace
-
Spawn cargo build process in tempdir with resource caps
-
For each line of output from
stderr/stdout, send WebSocket message to session ID -
On success or error:
-
Emit final message
{ "status": "success" | "error", "duration_ms": 1345 } -
Include truncated binary hash if successful (
sha256sum target/release/*)
-
WebSocket Message Format
{
"session_id": "abc123-session",
"type": "log",
"line": "Compiling xyz v0.1.0 (/app/xyz)"
}
Final message:
{
"session_id": "abc123-session",
"type": "end",
"status": "success",
"duration_ms": 1420,
"binary_hash": "6a1e...f3"
}
๐ WebSocket Transport via Peer Identity
-
Each job includes a
session_idlinked to a P2P/WebSocket stream -
Operator uses
RoundBasedNetworkAdapterorlibp2pdirectly to forward messages to client -
Client must already have subscribed via browser/websocket relay infra to
session_id -
Operator sends stream:
-
stdoutandstderras they happen -
endevent with final result -
errorevent if build panics
-
๐ Optional Additional Jobs
| Job ID | Name | Description |
|---|---|---|
| 1 | test_project | Run cargo test, stream results |
| 2 | lint_project | Run cargo clippy or fmt |
| 3 | audit_project | Run cargo audit, report vulnerabilities |
| 4 | check_project | Run cargo check for syntax validation |
Each job shares same pattern:
-
Accept zip URI and session ID
-
Stream output in real time
-
Enforce build time/memory quota
๐ก๏ธ Isolation & Sandboxing
Use tokio::process::Command with:
-
tempdircrate for file isolation -
Resource limits:
-
ulimitfor memory and CPU -
Optional
firejail,nsjail, or Docker-lite env for extra security
-
-
Auto-cleanup after job completes
๐งช Testing Strategy
Include integration test that:
-
Submits a known valid
zip_uri -
Spins up a mock WebSocket client for
session_id -
Asserts:
-
stdoutlines are streamed -
Compilation completes
-
Final success event sent
-
-
Include one test with failing crate (invalid Rust)
๐ง Completion Criteria
This blueprint is complete when:
-
It downloads, unpacks, and compiles Rust code from a zip
-
It streams logs live over session-specific P2P/WebSocket
-
It sends a final event with success/failure and duration
-
Optional jobs are structured and modular
-
It is safe, isolated, concurrent, and resilient
Build time must be as fast as possible:
-
Use release target only if requested
-
Cache toolchains if sandbox allows
-
Consider parallel job queue for multiple requests
This is a full remote Rust CI agent for the Tangle ecosystem.
- Each instance is a docker container
- Code lives there and you can edit it remotely (Github codespaces, etc.)