Skip to content
ThinkWatch
Start typing to search the docs.

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.

twcore · a complete, self-contained gateway binary
  1. cargo run -p twcore -- init # write a commented config.yaml
  2. cargo run -p twcore -- check # validate without starting
  3. 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

  1. Defined by external constraints tw-types · tw-protocol · tw-provider · tw-resil · tw-crypto Also used by the server edition
  2. Domain logic tw-engine · tw-pricing · tw-redact · tw-yaml · tw-secret
  3. Assembly tw-config · tw-store · tw-scan · tw-adopt · tw-observe Single-machine: SQLite, unix socket
  4. Data plane and control plane tw-gateway · tw-control Single-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.

View on GitHub