Inside Nightwatch: one Go binary, three guardrails, no retries
Remote sites are tough on software: patchy internet, strict privacy rules, and zero tolerance for an AI improvising system commands at 3 AM. Here is how Nightwatch is structured to stay small and fast, and to hand anything uncertain to a person.
One model call per incident, and no retries
Many AI agents work in a loop: ask the model, and if the answer looks wrong, ask again until something sounds plausible. That works for a chatbot. On an unattended machine at 3 AM, it means the agent can keep trying until it finds an answer that looks plausible.
Nightwatch asks the AI once per problem. Then plain, predictable code checks the answer. If anything fails, it does not retry. It hands the problem to a person.
Why it is one small program
The first prototype was written in Python, which is great for experiments. But asking every remote machine to set up a Python environment is a support headache. So we rewrote it in Go. That gave us:
- One file to install. A single command sets it up on macOS (Apple Silicon) and Linux (x86-64 and ARM64).
- A database inside. The full ClickHouse analytics engine is loaded straight into the program. No database server to run or maintain.
- A dashboard inside. The browser dashboard is built into the program and loads nothing from the internet.
- Instant commands. Health checks, rule checks and record checks finish in milliseconds.
Three guardrails between the model and the machine
Every suggestion has to pass three checks, written as plain code, before anything happens:
1. Only six known actions
Restart an app, clear a folder, retry an upload, lock away a suspicious file, alert a person, or ignore harmless noise. Anything else is rejected, and so is any answer containing characters that could sneak in a system command.
2. No made-up names
If the AI says "clear /var/spool/offload", that exact folder must appear in the log it was shown. Invented names are rejected automatically.
3. The policy always wins
Protected things like remote login, the operating system and system drives are off-limits, even if they are listed by mistake as safe to fix. Anything your rules don't mention is treated as off-limits too.
In this release every fix is simulated. Nightwatch decides, checks, records and alerts as it would for real, but never runs destructive commands on the machine.
Redaction in linear time
Before anything is saved or sent, Nightwatch strips out private details. The scrubber uses a pattern-matching engine (Go's RE2) that always runs in a predictable amount of time, so a strange or deliberately nasty log can't make it hang. The raw log itself is never stored. Only a fingerprint of it is kept, so you can still prove what the AI saw.
Reading the records while it runs
The built-in database only allows one program to write at a time. So when you run a query from the command line while Nightwatch is running, the command quietly asks the running program over a local-only connection instead of fighting it for access. Every query is read-only, checked by ClickHouse's own parser, and blocked from reaching files or the internet.
For engineers: the details
- Inference: Ollama on loopback only (
127.0.0.1:11434),temperature=0.0,think=false, proxies and redirects disabled. Non-loopback hosts are rejected at startup. - Embedded ClickHouse:
chdb-go/v2loadslibchdb.sovia purego (dlopen), soCGO_ENABLED=0cross-compiles darwin/arm64, linux/amd64 and linux/arm64 from one workflow. - Guardrails: closed 6-tool schema, single call, extra keys and unknown enums rejected, path traversal and shell metacharacters (
; | & $ ` > < ' " \) fail closed toescalate. Bounded lexical grounding forservice,mountandfile_id. - Policy:
never.services(sshd, systemd, systemd-journald, kernel, firewalld, auditd) andnever.mounts(/, /boot, /etc, /usr) take precedence overauto; unknown targets fail closed to NEVER. Policy files are opened viaos.OpenRootand rejected if they exceed 1 MiB. - Console: served via
//go:embed, strict CSP + COOP/CORP/Permissions-Policy headers, loopbackHostvalidation (DNS-rebinding defense), exact-authority same-origin CSRF checks on mutating routes,/api/approvals/rate limiting, CSV formula neutralization, text-node DOM only, and native<progress>meters so inline styles stay banned. - Lock-safe CLI:
query,audit verify,policy test,report exportandpagecommands proxy to the daemon on127.0.0.1:8000when it holds the chDB lock. SQL is classified withSession.ClassifyQuery(single statement, read-only), andurl(),file(),s3()andremote()are blocked.