flockd

module
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2026 License: Apache-2.0

README ΒΆ

⬑ Teraflock β€” flockd

Turn idle GPUs into an inference mesh. flockd is the open-source node daemon for Teraflock: install it on a Mac, a gaming PC, or a homelab box, and your idle silicon serves open-weight LLM inference β€” earning credits you can spend on the network's OpenAI-compatible API or redeem for cash.

  • πŸ–₯ One binary, three OSes. Go daemon + CLI/TUI. llama.cpp (Metal, CUDA, ROCm, Vulkan, CPU) runs as a supervised subprocess.
  • πŸ›‘ Your machine comes first. Serves only when idle (configurable), never on battery by default, thermal guards, and instant-yield: touch the keyboard and in-flight work drains or cancels within 2 seconds. Guaranteed by tests, not vibes.
  • πŸ” Nothing to hide. Apache-2.0, no request persistence, one outbound mTLS connection, hash-verified models and runtimes. Read docs/privacy.md for exactly what the daemon can and cannot see β€” including the honest part about what node operators could theoretically observe.
  • πŸ’° Earnings you can watch tick. tera dashboard (terminal) and a built-in web dashboard at localhost:7777.

Status: Phase 0. The single-node vertical slice works end to end (see the roadmap below). The hosted coordinator/mesh is under construction β€” today the daemon runs standalone.

Install

macOS / Linux:

brew install teraflock/tap/tera                   # macOS (cask)
curl -fsSL https://teraflock.ai/install.sh | sh   # Linux, or anything else

We publish a Homebrew cask, which Homebrew supports only on macOS β€” on Linux use install.sh, or the .deb / .rpm on the release.

Windows: grab the zip from the latest release (winget install Teraflock.tera coming later).

Beta note: binaries are checksummed but not yet code-signed/notarized. Joining the mesh needs an invite from teraflock.ai β€” then tera login, tera up, tera dashboard.

Build from source today:

git clone https://github.com/teraflock/proto ../proto   # sibling checkout (see Development)
go build ./cmd/flockd ./cmd/tera

Quickstart (standalone, no account needed)

Run the daemon with the in-process fake coordinator and the deterministic mock model β€” the whole serving path (governor, tunnel, telemetry, API) is real:

flockd --standalone --runtime=mock

Point any OpenAI SDK at it:

export OPENAI_BASE_URL=http://localhost:7777/v1
export OPENAI_API_KEY=anything   # loopback is keyless by default

Python:

from openai import OpenAI
client = OpenAI()  # reads OPENAI_BASE_URL / OPENAI_API_KEY

stream = client.chat.completions.create(
    model="mock-8b-instruct",
    messages=[{"role": "user", "content": "hello, mesh"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

Node:

import OpenAI from "openai";
const client = new OpenAI();

const stream = await client.chat.completions.create({
  model: "mock-8b-instruct",
  messages: [{ role: "user", content: "hello, mesh" }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

/v1/completions and /v1/embeddings work too. To serve a real model, point the daemon at a llama-server binary and a model catalog:

# ~/.teraflock/config.toml
[runtime]
kind = "llamacpp"
llama_server_path = "/opt/homebrew/bin/llama-server"

[models]
manifest_path = "/path/to/catalog.yaml"   # teraflock/models format
default = "llama-3.1-8b-instruct-q4_k_m"

Then watch it work:

tera dashboard        # gorgeous terminal dashboard: tok/s sparkline, earnings ticker
tera dashboard --web  # browser dashboard (prints the auth token to paste)
tera status           # one-shot status
tera limits --serve idle-only   # resource policy
scripts/smoke.sh      # the whole Phase 0 exit criterion as a script

Joining the mesh (Phase 1, soon)

tera login   # browser handoff, claims this node to your account
tera up      # install + start the service (launchd / systemd --user)

Until the hosted coordinator ships, tera login stores your claim code and the daemon serves locally only.

Resource governance promises

The whole project dies if the daemon ever makes your machine feel slow, so these are hard rules, enforced by the governor and its test suite:

promise mechanism
never serve while you're using the machine serve = idle-only (default), input-idle detection
get out of the way fast instant-yield: in-flight requests drain-or-cancel within yield_grace (2s default)
never drain your battery serve_on_battery = false by default
never cook your laptop max_temp_celsius pause threshold
you set the schedule serve = scheduled + windows like 22:00-08:00
clean exit tera uninstall --purge removes everything

Architecture

OpenAI SDKs ──▢ localhost:7777/v1 ─┐
tera CLI/TUI ─▢ /api/v1 ───────────┼─▢ engine ─▢ governor ─▢ runtime (llama-server subprocess / mock)
web dashboard β–Ά / (go:embed) β”€β”€β”€β”€β”€β”€β”˜        β–²
coordinator ◀── mTLS tunnel (outbound only) β”˜   (in-process fake coordinator in --standalone)

More in docs/architecture.md. Protocol contracts live in teraflock/proto (flock.tunnel.v1, flock.types.v1).

Development

flockd expects the proto repo as a sibling checkout (there's a replace github.com/teraflock/proto => ../proto in go.mod):

teraflock/
β”œβ”€β”€ proto/    git clone https://github.com/teraflock/proto
└── flockd/    this repo
go build ./... && go vet ./... && go test ./...   # everything
scripts/smoke.sh                                  # end-to-end standalone check
cd web && npm install && npm run build            # rebuild the dashboard

Note: web/dist/ is committed on purpose so go build works from a fresh clone without Node installed (it's embedded via go:embed). Rebuild it when you touch web/src.

Task runner (just build|test|lint|smoke) and CI config are in the repo; just lint installs and runs revive (same tool CI enforces).

Roadmap

  • Phase 0 β€” single-node vertical slice. Hardware detection, supervised runtime, model manager, governor with instant-yield, OpenAI endpoint on localhost, TUI + web dashboards, fake coordinator. Exit criterion met: OPENAI_BASE_URL=http://localhost:7777/v1 works with the OpenAI SDKs (scripts/smoke.sh).
  • Phase 1 β€” mesh MVP. Real coordinator, enrollment, QUIC tunnel, heterogeneous nodes behind the hosted gateway.
  • Phase 2 β€” money. Ledger, prepaid credits, earnings accrual + escrow.
  • Phase 3 β€” trust. Fingerprint challenges (the daemon side already answers them), canary sampling, reputation, slashing.
  • Phase 4 β€” product. Batch API, hosted console, redemption, signed auto-update.

What's implemented vs stubbed, in detail: docs/HANDOFF.md.

License

Apache-2.0. The daemon runs on machines we don't control; you deserve to read every line of what it does.

Directories ΒΆ

Path Synopsis
cmd
flockd command
Command flockd is the Teraflock node daemon: hardware detection, model management, a supervised llama.cpp runtime, resource governance, the loopback OpenAI-compatible API, and the coordinator tunnel (in-process fake coordinator in --standalone / Phase 0 mode).
Command flockd is the Teraflock node daemon: hardware detection, model management, a supervised llama.cpp runtime, resource governance, the loopback OpenAI-compatible API, and the coordinator tunnel (in-process fake coordinator in --standalone / Phase 0 mode).
tera command
Command tera is the operator CLI/TUI for the Teraflock node daemon.
Command tera is the operator CLI/TUI for the Teraflock node daemon.
internal
activity
Package activity is the daemon's short operator-facing history: what happened to the model store and the runtimes, by whom (the mesh, the operator, or the daemon's own housekeeping), and why.
Package activity is the daemon's short operator-facing history: what happened to the model store and the runtimes, by whom (the mesh, the operator, or the daemon's own housekeeping), and why.
assign
Package assign executes the coordinator's ModelAssignment pushes on the operator's terms (SPEC Β§4.1, Β§4.4; plan 05).
Package assign executes the coordinator's ModelAssignment pushes on the operator's terms (SPEC Β§4.1, Β§4.4; plan 05).
clock
Package clock abstracts time for deterministic tests (governor yield latency, backoff, rolling stats).
Package clock abstracts time for deterministic tests (governor yield latency, backoff, rolling stats).
config
Package config loads flockd configuration from defaults, an optional TOML file, and FLOCKD_-prefixed environment variables (koanf).
Package config loads flockd configuration from defaults, an optional TOML file, and FLOCKD_-prefixed environment variables (koanf).
engine
Package engine routes completion requests to loaded runtime Instances, applying governor admission and telemetry accounting.
Package engine routes completion requests to loaded runtime Instances, applying governor admission and telemetry accounting.
enroll
Package enroll manages node identity (Ed25519 keypair that never leaves the device), CSR generation, the Enroll RPC, credential storage, and the `tera login` PKCE-style browser handoff (SPEC Β§4.1, Β§6).
Package enroll manages node identity (Ed25519 keypair that never leaves the device), CSR generation, the Enroll RPC, credential storage, and the `tera login` PKCE-style browser handoff (SPEC Β§4.1, Β§6).
events
Package events is the daemon's in-process event bus: governor state changes, model download progress, and model lifecycle changes fan out to SSE subscribers (web dash, desktop app, TUI).
Package events is the daemon's in-process event bus: governor state changes, model download progress, and model lifecycle changes fan out to SSE subscribers (web dash, desktop app, TUI).
governor
Package governor is the resource-governance policy engine (SPEC Β§4.1, Β§10).
Package governor is the resource-governance policy engine (SPEC Β§4.1, Β§10).
hardware
Package hardware detects the node's compute capability and produces the typesv1.CapabilityProfile sent at enrollment and in heartbeats.
Package hardware detects the node's compute capability and produces the typesv1.CapabilityProfile sent at enrollment and in heartbeats.
localapi
Package localapi is the daemon's loopback HTTP surface on localhost:7777: the OpenAI-compatible /v1 endpoints (Phase 0 exit criterion) and the management /api/v1 REST+SSE API that the CLI, TUI and embedded web dashboard all consume (SPEC Β§A1.2: one source of truth).
Package localapi is the daemon's loopback HTTP surface on localhost:7777: the OpenAI-compatible /v1 endpoints (Phase 0 exit criterion) and the management /api/v1 REST+SSE API that the CLI, TUI and embedded web dashboard all consume (SPEC Β§A1.2: one source of truth).
localapi/gen
Package gen provides primitives to interact with the openapi HTTP API.
Package gen provides primitives to interact with the openapi HTTP API.
logging
Package logging provides slog setup plus an in-memory ring buffer handler backing GET /api/v1/logs.
Package logging provides slog setup plus an in-memory ring buffer handler backing GET /api/v1/logs.
memory
Package memory is the daemon's model-memory accounting: the budget loaded models may use, the footprint estimate for a model before it is loaded, and the measured physical footprint of a running runtime process.
Package memory is the daemon's model-memory accounting: the budget loaded models may use, the footprint estimate for a model before it is loaded, and the measured physical footprint of a running runtime process.
modelops
Package modelops is the daemon's on-demand model operations service: catalog browsing, operator-triggered downloads (with cancel), and runtime load/unload/default switching.
Package modelops is the daemon's on-demand model operations service: catalog browsing, operator-triggered downloads (with cancel), and runtime load/unload/default switching.
models
Package models manages the local model cache: catalog manifests (teraflock/models format), resumable GGUF downloads with SHA256 verification, and LRU eviction under the operator's disk budget.
Package models manages the local model cache: catalog manifests (teraflock/models format), resumable GGUF downloads with SHA256 verification, and LRU eviction under the operator's disk budget.
runtime
Package runtime defines the inference Runtime interface (SPEC Β§A1.3) and its adapters.
Package runtime defines the inference Runtime interface (SPEC Β§A1.3) and its adapters.
runtime/llamacpp
Package llamacpp adapts a supervised llama-server subprocess to the runtime.Runtime interface (SPEC Β§A1.3: subprocess, never cgo).
Package llamacpp adapts a supervised llama-server subprocess to the runtime.Runtime interface (SPEC Β§A1.3: subprocess, never cgo).
svc
Package svc installs and controls flockd as an OS service: launchd (macOS), systemd (Linux) and Windows SCM (stub).
Package svc installs and controls flockd as an OS service: launchd (macOS), systemd (Linux) and Windows SCM (stub).
telemetry
Package telemetry assembles heartbeats and keeps rolling performance stats (tok/s, request counters) shared by the tunnel, local API and TUI.
Package telemetry assembles heartbeats and keeps rolling performance stats (tok/s, request counters) shared by the tunnel, local API and TUI.
tunnel
Package tunnel implements the node side of flock.tunnel.v1.TunnelService: the persistent, node-initiated session over which the coordinator pushes dispatches, challenges and model assignments (SPEC Β§3: nodes dial out, never listen).
Package tunnel implements the node side of flock.tunnel.v1.TunnelService: the persistent, node-initiated session over which the coordinator pushes dispatches, challenges and model assignments (SPEC Β§3: nodes dial out, never listen).
tunnel/fakecoord
Package fakecoord is an in-process fake coordinator implementing flock.tunnel.v1.TunnelService over bufconn (SPEC Β§A2.2 key seam).
Package fakecoord is an in-process fake coordinator implementing flock.tunnel.v1.TunnelService over bufconn (SPEC Β§A2.2 key seam).
update
Package update checks the mesh's version feed for a newer flockd release.
Package update checks the mesh's version feed for a newer flockd release.
Package web embeds the built local dashboard (web/dist) into the daemon binary.
Package web embeds the built local dashboard (web/dist) into the daemon binary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL