The stack behind Nightwatch
Nightwatch started as a hackathon project with one rule: only use a partner tool where it solves a real problem of running machines at remote sites. Here is what each one does in the shipped agent.
distil labs
Turned small, untrained models into specialists that score 90 to 97.5%.
Base modelsGemma 4 & Qwen
Open models from Google DeepMind and Alibaba, slimmed down to fit on the machine.
Audit storeClickHouse
A full analytics database running inside the app. No server needed.
SMS & voiceVonage
Approval codes, short alerts and phone calls. The only thing that ever leaves the site.
Security scanningAikido
Security scans on every change, and findings that shaped the design.
distil labs: model training
The problem. A big cloud AI would break both of our promises: it needs internet, and it would see your logs. A small AI on the machine keeps both promises but gets the answer wrong (2.5% right, untrained).
What distil labs did. It let us measure how well the big "teacher" AIs did on our task (Claude Opus 5.5, Qwen3.8-2.4T and GLM 5.3), grow 36 hand-written examples into 1,513 checked practice incidents, and train four small "student" models to answer like the teachers. Three rounds, $7.28 in total.
The result. Four models from 610 MB to 3.46 GB, scoring 90% to 97.5% on a secret exam, and the 1.35 GB one matching Claude Opus 5.5 on our check set. Read the full training story →
Gemma 4 and Qwen: base models
The students are built on open models: Gemma 4 E2B from Google DeepMind for the default, and Qwen3 / Qwen3.5 from Alibaba for the smaller sizes. Gemma 4 can also see and hear, which we don't need, so we removed those parts. That alone shrank it from 8.12 GB to 3.46 GB without losing a single point of accuracy.
| Size | Built on | On disk | Exam score | Typical answer time |
|---|---|---|---|---|
| Default | Gemma 4 E2B | 3.46 GB | 97.5% | 0.20 s |
| Balanced | Qwen3.5 2B | 1.35 GB | 95.0% | 0.33 s |
| Small | Qwen3.5 0.8B | 774 MB | 92.5% | 0.21 s |
| Tiny | Qwen3 0.6B | 610 MB | 90.0% | 0.10 s |
ClickHouse: the audit store
The problem. Operators want a morning summary, a way to test new rules against last night, a record nobody can tamper with, and the freedom to ask their own questions in SQL. But nobody wants to run and babysit a database server on a small remote machine.
What ClickHouse does. Through chDB, the full ClickHouse engine runs inside Nightwatch. No server, no setup. That gives us real analytics features on a laptop-sized box:
- Organised by month, so queries stay fast as the record grows.
- Hourly summaries kept for 90 days, calculated automatically as decisions come in and tidied away when they expire.
- A tamper-evident chain: each record carries a fingerprint of the one before it.
nightwatch audit verifychecks the whole chain in one go. - Privacy counts, not private data: it stores how many emails or IDs were scrubbed, never the details themselves.
Vonage: SMS and voice
Vonage is off until you switch it on, and it only ever sends. Nightwatch opens no inbound connections, so nothing on the internet can reach in. It handles three jobs:
1. One-time code approval
A risky action, like locking away a suspicious file, is put on hold. The on-call engineer gets a six-digit code by text (or taps "call me instead"), enters it in the dashboard, and only then does the action go ahead. Deny it or approve it another way, and the pending code is cancelled so no late phone call fires.
2. SMS alerts with no log text
Alerts follow fixed templates under 160 characters, with no log content and no personal details. They queue on the machine when the internet is down, never send twice even after a crash, max out at 6 an hour, and hold low-priority news during quiet hours.
3. Voice call if unacknowledged
If a critical alert isn't acknowledged within five minutes (you choose the time), Nightwatch calls the on-call phone and reads the message aloud. Acknowledge it in the dashboard or with one command, and the call is cancelled.
Aikido: security scanning
Security wasn't bolted on at the end. Aikido scanned every change through MCP, GitHub PR checks and Deep Review for code weaknesses, leaked secrets, end-of-life runtimes and risky CI permissions, and its findings directly shaped the shipped agent:
- Zero-injection dashboard and CSV exports. Pages are built with text nodes only, no inline scripts or styles, strict CSP + COOP/CORP headers, loopback
Hostand exact-authority same-origin CSRF checks, approval rate limiting, and formula-neutralized CSV exports. - Hardened database queries and file access. Audit writes use allowlisted prefixes and ClickHouse epoch-millisecond bounds (
fromUnixTimestamp64Milli); policy and key reads use Go'sos.OpenRootconfinement with fail-closed size caps, while rotated log reads use the same confinement and explicit rotation errors. - Durable outbound alerts and supply-chain locks. Deep Review drove "reserve before sending" SMS outbox state and pending Verify cancellation; CI pins Go
1.27.4, full commit SHAs for every GitHub Action withpermissions: {}andpersist-credentials: false, and SHA-256 checksums forlibchdbandgitleaks.
Our AI coding setup
We build Nightwatch with AI coding assistants connected to three MCP servers: Aikido for SAST/secrets/dependency scans (0 findings across all 51 scanned files), Vonage's documentation for exact API details, and a read-only view of the ClickHouse audit store. Local safety hooks block commits to main, run gitleaks and offline aikido-local-scanner pre-commit-scan, and keep Go code formatted.
For engineers: the details
- distil labs:
distilCLI, teacher evaluation, synthetic expansion, PEFT LoRA distillation; adapters merged and exported to text-only GGUF with llama.cpp. - ClickHouse (chDB):
triageisMergeTree()partitioned bytoYYYYMM(ts)withLowCardinality(String)enums andMap(LowCardinality(String), UInt32)PII counts.mv_triage_rollups_hourlyfeeds anAggregatingMergeTree()(countState,sumState,quantilesState(0.5, 0.95),sumMapState) withTTL hour_bucket + INTERVAL 90 DAY. Six built-in read-only SQL presets cover 24h rollups,quantilesMerge/sumMapMergehourly MVs, PII breakdown, recent records, in-SQLlagInFrameSHA-256 chain checks, and outbox SLA. - Vonage: Verify v2 (
POST /v2/verify,/next_workflow,DELETE /v2/verify/{id}); GSM-7 single-segment templates; durable outbox in ClickHouse with sending reservations, exponential backoff, 6/hour cap and quiet hours; Voice APIPOST /v1/callswith an NCCO talk action and an RS256 JWT signed with stdlibcrypto/rsa, falling back to Verify voice when only key and secret are set. - Aikido and MCP:
@aikidosec/mcp(0 SAST/OSS findings across 51 files), native GitHubAikido Security: check code&Deep ReviewPR gating, offlineaikido-local-scanner pre-commit-scan(scripts/aikido-secrets-hook.sh),documentation-mcp.vonage.dev/mcp, andmcp-clickhousewithCHDB_ENABLED=true; hooksbranch-guard.sh,secret-guard.sh(gitleaks) andgofmt-hook.sh.