Skip to content

Live Demo: Rules Catalog

These are real entries from IntentWeave’s own .iw/rules.yaml — the same file that powers iw intent check in this repo’s CI. Two structural rules enforce package layer isolation (import graph); three behavioral rules use inline Mermaid sequence diagrams to assert the CARI build pipeline calls its stages in order. Violation counts and the sample evidence below are from the most recent iw intent check --domain all run.

5 of 15 rules shown 5 live violations live self-check · 2026-07-11
HIGH STRUCTURAL ERROR arch-core-is-foundation ✓ clean

@intentweave/core is the foundation layer. It must not import from any higher-level package (analyzer, index, cli, server-core, server-open). A violation creates a dependency cycle that makes the platform un-treeshakeable and prevents independent use of core types.

Forbidden Import Patterns
Pattern Scope
@intentweave/analyzer packages/core/**
@intentweave/index packages/core/**
@intentweave/cli packages/core/**
@intentweave/server-core packages/core/**
@intentweave/server-open packages/core/**
HIGH STRUCTURAL ERROR arch-no-upward-index ✓ clean

@intentweave/index (CARI Evidence Engine) must not import from @intentweave/cli. The index is a library layer below the CLI. An upward import would create a cycle and prevent use of @intentweave/index in contexts outside the CLI (MCP servers, plugins, CI scripts).

Forbidden Import Patterns
Pattern Scope
@intentweave/cli packages/index/src/**
HIGH BEHAVIORAL ERROR bdd-build-pipeline-required-stages ⚠ 1 violation

The CARI build pipeline (buildFromPaths in facade.ts) must run all four required stages in order: AST extraction (runAxStage), IDF scoring (computeIdf), annotation matching (annotate), and SQLite write (buildIndex). Skipping any stage breaks the index: - No runAxStage: no symbols, no call graph, empty index - No computeIdf: all terms score equally, annotations are noisy - No annotate: doc mentions never linked to code symbols - No buildIndex: pipeline runs but nothing is persisted Verified via Phase 4 call graph (0.95 confidence / error) when call data is present; falls back to import graph (0.70 / warn) otherwise.

Mermaid Render
buildFromPaths runAxStage extract AST symbols + call edges #1
buildFromPaths computeIdf compute per-term IDF scores #2
buildFromPaths annotate match doc mentions to code symbols #3
buildFromPaths buildIndex write completed index to SQLite #4
Live violation (confidence 0.95)
packages/index/src/facade.ts
[mermaid:must_call] "buildFromPaths" never calls "computeIdf" (confidence 0.95, call graph). Sequence diagram requires: "buildFromPaths ->> computeIdf: compute per-term IDF scores"
HIGH BEHAVIORAL ERROR bdd-writer-complete-pipeline ⚠ 4 violations

The index writer (buildIndex in writer.ts) must run its full write sequence on every build: schema init, symbols, annotations, imports, and the Phase 4 call graph. Critical invariants: - initSchema first: missing tables corrupt subsequent writes - writeSymbols: foundation for all CARI queries - writeAnnotations: without them, retrieve/connections return nothing - writeCalls: Phase 4 behavioral checks require call edges (must_call) Verified via Phase 4 call graph (0.95 confidence / error) when call data is present; falls back to import graph (0.70 / warn) otherwise.

Mermaid Render
buildIndex initSchema create tables if not exist #1
buildIndex writeSymbols persist extracted code symbols #2
buildIndex writeAnnotations persist doc-to-symbol annotation links #3
buildIndex writeImports persist import graph edges #4
buildIndex writeCalls persist call graph edges (Phase 4) #5
Live violation (confidence 0.95)
packages/index/src/writer.ts
[mermaid:must_call] "buildIndex" never calls "writeSymbols" (confidence 0.95, call graph). Sequence diagram requires: "buildIndex ->> writeSymbols: persist extracted code symbols"
HIGH BEHAVIORAL WARN bdd-rules-check-db-lifecycle ✓ clean

The intent check entry-point (rulesCheck in queries/rulesCheck.ts) must open the SQLite database via openIndex() before calling rulesCheckFromDb(). openIndex() configures WAL mode, busy_timeout, and read pragmas. Bypassing it risks reading a locked DB or leaving WAL files open. Verified via Phase 4 call graph (0.95 confidence) when call data is present; falls back to import graph check (0.70) otherwise.

Mermaid Render
rulesCheck openIndex open DB with WAL mode + read pragmas #1
rulesCheck rulesCheckFromDb run structural + behavioral + documentary checks #2
  1. Structural rules (type: import_pattern) are checked against the import graph CARI already builds during iw index build — zero LLM calls, sub-second.
  2. Behavioral rules express intent as an inline Mermaid sequenceDiagram. CARI parses it with a zero-dependency regex extractor (no @mermaid-js/parser, no DOM) and checks each edge against the symbol_calls table (Phase 4 call graph, 0.95 confidence) — or falls back to the import graph (0.70 confidence, warn) when call-graph data isn’t available yet.
  3. Every violation carries a detail string that names the exact caller/callee pair and file — the same evidence surfaced in iw intent check, the Insights Book’s Rules Catalog chapter, and the cari_rules_check MCP tool.
# .iw/rules.yaml — behavioral rule, checked via the call graph
- id: bdd-writer-complete-pipeline
domain: behavioral
severity: high
mode: error
source:
type: mermaid_inline
mermaid: |
sequenceDiagram
buildIndex->>initSchema: create tables if not exist
buildIndex->>writeSymbols: persist extracted code symbols
buildIndex->>writeAnnotations: persist doc-to-symbol annotation links
buildIndex->>writeImports: persist import graph edges
buildIndex->>writeCalls: persist call graph edges (Phase 4)
forbidden: []
Terminal window
# Reproduce this locally, on your own rules.yaml
iw intent check --domain all --format json

See the full Semantic Rule Checking reference for every rule type, or the Insights Book for the complete catalog of all 15 rules in this repo, with filters by domain and severity.