ThinkWatch Core · Shared engine
Shared core of the ThinkWatch gateways
Routing, forwarding, observability, cost accounting, and data-plane guards, provided as MIT-licensed Rust crates. Used by ThinkWatch Lite and by the server edition.
-
cargo run -p twcore -- init# write a commented config.yaml -
cargo run -p twcore -- check# validate without starting -
cargo run -p twcore -- serve# start the gateway and control plane
Capabilities
Rule-based routing
Rules match on model, client, context length, or the presence of tools, and can switch upstream, rewrite parameters, or reject the request.
Mid-stream failover
Before the first byte is sent, upstreams can be switched transparently. After streaming has started, the failure is reported.
Cost visibility
Token usage and cache hits are priced against a snapshot table. Usage that cannot be priced is labelled unknown.
Outbound redaction
Secrets are replaced with placeholders before they reach a relay, and restored when the model echoes them.
Inbound inspection
Tool calls from an upstream are checked against rules; a dangerous call can be terminated mid-frame.
Crate layers
- Defined by external constraints
tw-types · tw-protocol · tw-provider · tw-resil · tw-cryptoAlso used by the server edition - Domain logic
tw-engine · tw-pricing · tw-redact · tw-yaml · tw-secret - Assembly
tw-config · tw-store · tw-scan · tw-adopt · tw-observeSingle-machine: SQLite, unix socket - Data plane and control plane
tw-gateway · tw-controlSingle-machine: SQLite, unix socket
The bottom two layers form the single-machine implementation and are intentionally not shared. Single-machine SQLite and multi-tenant Postgres differ too much for one abstraction to serve both.
Development
Testing
The smoke script exercises every path on the real binary from a clean state. HOME and THINKWATCH_HOME point to a temporary directory that is deleted on completion.
-
cargo test --workspace# unit and integration tests -
scripts/smoke.sh# every path on the real binary
MIT License
Building on, embedding, and redistributing the crates are permitted.