Architecture
How Veilgate is built, drawn out — the trust boundary, the one-direction dependency graph, and the two detection subsystems inside the core engine.
Veilgate is one framework-agnostic core engine wrapped in thin integrations. The drawings below show the three things the code is shaped around: a trust boundary that originals never cross, a dependency graph that points one way, and a core that runs two detection subsystems into a single decision.
The trust boundary
The core runs inside your boundary. It strips regex-detectable secrets locally, then asks Jev
to score the spans that are left — Jev (TypeSafe’s evaluator) sees that post-regex text, while
the built-in mock sees nothing and answers from fixtures. Only after the decision does the
core redact: the frontier cloud model you are protecting receives the placeholder payload and
nothing else, while a REROUTE_LOCAL span is handed to a trusted local model in the clear. On the
way back, the vault restores the originals for the user.
One direction of dependency
Dependencies run one way. Every package depends on veilgate through a workspace:* link, and
nothing depends on an integration — so an adapter can be added or dropped without touching the
engine, and the engine has no knowledge of any runtime it is wired into. The one extra edge is
the CLI, which also pulls in veilgate-policy to load its presets. Each adapter is small —
roughly 150–210 lines — doing only the glue: redact the inbound payload, forward the redacted
output, re-hydrate the reply.
Inside the core
Two detection subsystems run into one decision. The deterministic path (regex) settles high-confidence secrets locally, for free; whatever is left goes to the semantic path (Jev, or its mock) for a calibrated judgement. The policy engine turns those signals into one action per span, and the vault keeps every redaction reversible so re-hydration is exact.
Why it’s shaped this way
- Pure decide-and-transform. The core never calls your destination and never throws on a
block — it sets a
blockedflag and leaves the refusal to the caller, which keeps it fully testable. - Fail-closed. A Jev error never comes back as
ALLOW— the affected spans are forced to at least aREROUTE_LOCAL; a reroute with no local handler and a stream that can’t be inspected both refuse the request outright. Never a silent allow. - Config, not constants. Model id, price and thresholds are passed in, so a deployment tunes risk without forking the engine.
- Mock-first. The deterministic runtime ships with the core, so CI and local dev need no network and no key.
See The policy model for how overlapping rules resolve, or The pipeline for the per-stage flow a payload takes through the core.