feat: add ctx check — architecture rules engine#6
Merged
Conversation
Serde model for .ctx/rules.toml (layers plus forbidden / allowed_dependents / limit / no_new_dependents rule groups), glob compilation with validation (unknown layers, layer overlap, file_symbols scope), and pure rule evaluation over a file-level dependency set so the engine is unit-testable without a database.
get_cross_file_edges() returns resolved calls/implements/extends/uses edges whose endpoints live in different files; get_file_imports() reads per-file ImportInfo from the modules table; get_import_edges() surfaces Go-style file-level import edges.
Builds a file-level dependency set from the index (resolved symbol edges plus per-language import resolution for TS/JS, Rust, Python, Go, and Solidity), evaluates .ctx/rules.toml, and reports violations grouped by rule with a machine-readable --json mode. --against REF scopes violations to files changed since REF; --list prints the parsed rules and layer membership counts. Exits 0 clean / 1 violations / 2 operational error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR 2 of 7 in the Quality Intelligence Suite and its highest-value gate. Stacked on #2 (
feat/quality-foundation) — will be retargeted tomainonce #2 merges; review only the top 4 commits until then.ctx checkcommand evaluating architecture rules from.ctx/rules.tomlagainst the existing index: layers (path globs), forbidden layer dependencies, allowed_dependents, structural limits (fan_in/fan_out/complexity/file_symbols per symbol or file, with excludes), and no_new_dependents (frozen modules).calls/implements/extendsedges plus imports: per-language import resolution (TS/JS relative probing, Rustcrate/super/selfmodule paths, Python dotted absolute+relative, Go package-dir suffix, Solidity relative) over themodulestable — plus Go's parser-emitted import edges, which the other languages don't have.--against <REF>: only violations touching files changed vs REF (documented v1 approximation);no_new_dependentsfilters on changed source files so touching a frozen file doesn't re-report its pre-existing callers.--listprints parsed rules + layer membership counts;--jsonemits one entry per violation with rule type, reason, and both endpoints (SymbolRef or{file}for import edges).--help.Test plan
--againstfixture (pre-existing suppressed, new reported), error paths.cargo test(211 green),clippy -D warnings,fmt --check,--no-default-featuresbuild — all clean.🤖 Generated with Claude Code