Model-layer alignment stops at the model. The action layer — where a tool call actually executes — needs its own gate. This is that gate: a tiny, dependency-free library that enforces a machine-readable Constitution before an agent acts. It's the exact policy logic EcoCloud runs server-side, extracted so any MCP server, agent runtime, or API gateway can drop it in.
Install
One file, no build step. Vendor it, or load it directly:
// one file · zero deps · Node · Workers · browser
enforce() returns { allow, violation, requiresApproval }. Deny → return the rule to the agent and log it. requiresApproval → route to a human queue. allow → run the tool call. Per-agent rules merge on top of the workspace's via mergeRules(ws, key) — union the forbidden lists, tighten the caps.
Try it — runs in your browser
The same kernel that's loaded on this page, evaluating live:
// click a button — verdicts computed by the kernel, not a server
Provable, not just claimed
Every verdict above is pinned by a golden conformance corpus that runs on every build, so the gate's behavior can't silently drift. 34 cases cover every rule (priority caps, forbidden terms, quiet hours, daily caps, forbidden assignees & tags, objective alignment, the confidence gate), the check-order precedence, the rule that a hard deny always beats the approval gate, and the per-key mergeRules tightening.
The corpus (constitution-corpus.json) and runner (run-constitution.js) are Apache-2.0 — fork them, add your own policy cases, run them in your CI. The same suite is wired into EcoCloud's npm test (1,093 deterministic assertions across the kernel library).
Constitution as Code
A constitution is a small JSON file — so manage it like code. flowdesk-const is a zero-dependency CLI (Apache-2.0) that validates, lints, diffs, and tests one, built on this same kernel + the canonical schema.
# schema-validate, then lint for footguns (empty lists, over-broad terms, no-op windows)
node flowdesk-const.js validate constitution.json
node flowdesk-const.js lint constitution.json
# diff two versions — a change that LOOSENS the policy exits 2 (block the merge for review)
node flowdesk-const.js diff old.json new.json
# removed 1 forbidden_terms → loosens# REQUIRES REVIEW — this change LOOSENS the policy (exit 2)# test — replay golden cases through the real kernel, assert the verdicts
node flowdesk-const.js test constitution.json cases.json
The point of diff: tightening a policy is safe to auto-apply, but loosening it must be reviewed by a human — so wire flowdesk-const diff into your PR check (exit 2 = a guard was weakened). Same idea as the in-product constitution version-control kernel, exposed as a CLI for your repo. New here? Start at the 5-minute quickstart.
Why a kernel, not an API
No round-trip, no dependency on us. The policy runs in your process, before the side effect. EcoCloud can be offline and your agents are still governed.
Same logic, everywhere. The library is what EcoCloud's own server runs, so a simulation, a gateway, and the live action all agree.
Open by design. Apache-2.0. Fork it, audit it, extend the rule set. Alignment infrastructure shouldn't be a black box.
This is a reference implementation, not a sandbox. The kernel decides allow/deny; your runtime still has to actually stop on a deny, write the audit row, and wire the kill-switch. EcoCloud provides those rails server-side — see the showcase.
// the governed loopsimulate→constitution→execute→signed→verifyES256 · audit-chained