Skip to content
Search docs
Search the docs and jump to the section
Sign in

Executable boundary checks

pnpm check:boundaries runs the checker in tools/checks/run.ts. pnpm check runs it too.

Enforced boundaries

The policy is tools/checks/policy.ts.

  • Every package must have a policy; a new package without one fails.
  • A package may depend on and import only the Werker packages its policy lists (the table is in Architecture).
  • Third-party packages with an owner may only be declared or imported by that owner: pg by @werkerai/db, better-auth by @werkerai/auth, @earendil-works/pi-ai and @daytona/sdk by @werkerai/connections, nodemailer by @werkerai/connections, citty by @werkerai/cli, @earendil-works/pi-codemode by @werkerai/runtime and @werkerai/scripts, other @earendil-works/* packages by @werkerai/runtime, and tmcp and @tmcp/* by @werkerai/app.
  • .sql files may only live under packages/db/.
  • Production domain and rules modules cannot import Node built-ins. Test files are exempt.
  • Package imports must be declared by the importing package.
  • Imports must match the target package's public exports.
  • Relative imports cannot reach outside their package.
  • Application packages cannot be imported as package APIs, except where a policy's apps names one (apps/reels imports apps/app's exports).
  • Unknown @werkerai/* package imports are rejected.
  • Names: application-owned variables, functions, parameters and type or class members use snake_case (no UPPER_CASE constants); types, interfaces and classes use PascalCase. Object-literal keys and third-party names are left alone, and library exports are not given snake_case aliases. External contract keys an owned type must mirror are allowlisted in external_property_names (tools/checks/naming.ts). Code copied from upstream projects, listed in vendored_paths (tools/checks/policy.ts), keeps its upstream names: the shadcn-svelte primitives in packages/ui/src/components/ui/, packages/ui/src/hooks/, packages/ui/src/highlighter.ts and tools/oxlint/anti-slop/.
  • $effect is not used in apps/app/src/, apps/site/src/, apps/reels/src/ or packages/ui/src/: derive state with $derived, update it in event handlers, and set up DOM or library work with {@attach} or onMount (tools/checks/runes.ts).
  • In the same UI source directories, the navigation check flags invalidateAll in scripts and template expressions. SvelteKit uses refreshAll for both the function and the navigation option.
  • Nested ternaries: outside vendored_paths, a ternary cannot sit directly in another ternary's condition or branch, in scripts or Svelte template expressions. Use if/return, $derived.by, {#if} blocks or a lookup object (tools/checks/ternaries.ts).
  • Tools are defined with define_tool (packages/runtime/src/tools/define.ts), which limits a tool's name to those in the registry; nothing else in packages/runtime/src/ may name pi-durable's defineTool (tools/checks/registry.ts).

Size limits

tools/checks/size.ts measures every source file outside vendored_paths, except test files (*.test.ts, *.spec.ts). The limits are size_limits in tools/checks/policy.ts:

WhatLimit
A function, method or callback100 lines
A top-level try, if, loop or block100 lines
A .ts or .js file500 lines
A Svelte component, script and markup together400 lines
  • A function inside a long function is measured as well, and named outer.inner.
  • Lines include blank lines and comments.
  • size_exempt (tools/checks/policy.ts) lists files with no file-length limit, each with a reason: currently packages/domain/src/registry.ts. Their functions are still measured.
  • .sql files are not measured.

Code that was over a limit when the check was added is recorded in tools/checks/size-baseline.json, keyed by file path, or path#name for a function. The check fails when:

  • something not in the baseline is over its limit;
  • something in the baseline is longer than its recorded size;
  • something in the baseline is shorter than its recorded size, or is no longer over its limit. pnpm check:sizes:lower then lowers or removes the entry. That command never adds an entry or raises one.

So a recorded size only goes down. Two functions with the same name in one file share one entry, the longer of the two.

Folders

tools/checks/layout.ts: when five or more files in one folder share a first word (sandbox-types.ts, sandbox-files.ts, ...), the check fails and names the folder to make: the files move into sandbox/ and drop the prefix (sandbox/types.ts). The number is prefix_group_limit in tools/checks/policy.ts.

  • A file and its tests count as one.
  • Files named after the folder they are already in (components/run/run-view.svelte) are left alone.
  • SvelteKit route files (+page.svelte) and vendored_paths are not counted.

Two oxlint rules in the root vite.config.ts sit beside the size check: max-depth (blocks nested at most 4 deep) and max-params (at most 6 parameters). max-depth is off for three files whose long functions are in the baseline; the list is in vite.config.ts.

Implementation

The checker discovers source and package manifests from the filesystem, including new untracked files. It ignores dependencies and generated build output.

TypeScript's compiler API inspects imports, re-exports, import types, literal dynamic imports, and literal require calls. The Svelte compiler locates component script blocks before TypeScript parses them. Comments and strings resembling imports are not treated as imports.

Import checks are static: computed module names are not checked.

Tests and commands

pnpm check:boundaries
pnpm check:sizes:lower
pnpm test:boundaries
pnpm check
pnpm test:unit

Checker tests build temporary fixture repositories.

The registry

packages/domain/src/registry.ts lists every part the platform has: the kinds of record that can be created, what starts work, what an agent can be given, and the tools, capabilities and connection adapters behind them. Registry is that list as a page. Package tests fail when the code has a part the registry lacks:

  • a table or a column in packages/db/sql/ (packages/db/src/registry.test.ts);
  • a tool (define_tool, above), and the tools a service connection gives a run (packages/runtime/src/registry.test.ts);
  • a model or sandbox adapter (packages/connections/src/registry.test.ts);
  • a bindable capability (a type in packages/core/src/connections/connections.ts);
  • apps/site/src/content/docs/engineering/registry.md differing from the registry (packages/domain/src/registry-page.test.ts; pnpm docs:registry writes it).

They cannot see a new global from a library upgrade, an environment variable, or a change in behaviour that adds no table, column, tool, adapter or capability.

This page as markdown apps/site/src/content/docs/engineering/guardrails.md