Apache-2.0v0.1zero dependenciesNode · Workers · browser

The Constitution Kernel.

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
VENDOR · LOAD · ENFORCE kernel.js1 file · 0 deps require / scriptUMD global enforce()same logic as server

⬇ flowdesk-constitution-kernel.js · the rule schema is documented in the Constitution spec v0.1.

Enforce before you execute

// one call, three verdicts: allow · approve · deny
CHECK · DECIDE · ACT enforce()rules · action · confidence deny · log the rule → human approval execute

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.

$ node conformance/run-constitution.js constitution-kernel v0.1: 34/34 cases correct

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

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 loopsimulateconstitutionexecutesignedverifyES256 · audit-chained