Skip to content

feat: add ctx check — architecture rules engine#6

Merged
saldestechnology merged 5 commits into
mainfrom
feat/check
Jul 9, 2026
Merged

feat: add ctx check — architecture rules engine#6
saldestechnology merged 5 commits into
mainfrom
feat/check

Conversation

@saldestechnology

Copy link
Copy Markdown
Collaborator

Summary

PR 2 of 7 in the Quality Intelligence Suite and its highest-value gate. Stacked on #2 (feat/quality-foundation) — will be retargeted to main once #2 merges; review only the top 4 commits until then.

  • New ctx check command evaluating architecture rules from .ctx/rules.toml against 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).
  • Dependencies = resolved cross-file calls/implements/extends edges plus imports: per-language import resolution (TS/JS relative probing, Rust crate/super/self module paths, Python dotted absolute+relative, Go package-dir suffix, Solidity relative) over the modules table — 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_dependents filters on changed source files so touching a frozen file doesn't re-report its pre-existing callers.
  • --list prints parsed rules + layer membership counts; --json emits one entry per violation with rule type, reason, and both endpoints (SymbolRef or {file} for import edges).
  • Exit codes: 0 clean / 1 violations / 2 config, index, or git error (invalid TOML, unknown layer, overlapping layers, missing index, bad ref). Full example rules file in --help.
  • Documented semantics: unlayered files are unconstrained; a layer may always depend on itself.

Test plan

  • 24 new tests: rules parse/validate matrix, per-language resolver table tests, all rule types on in-memory DBs, end-to-end TS fixture (violation → exit 1 naming the exact edge → fix + re-index → exit 0), two-commit --against fixture (pre-existing suppressed, new reported), error paths.
  • cargo test (211 green), clippy -D warnings, fmt --check, --no-default-features build — all clean.

🤖 Generated with Claude Code

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.
@saldestechnology
saldestechnology deleted the branch main July 9, 2026 15:38
@saldestechnology
saldestechnology changed the base branch from feat/quality-foundation to main July 9, 2026 15:40
@saldestechnology
saldestechnology merged commit fb29750 into main Jul 9, 2026
3 checks passed
@saldestechnology
saldestechnology deleted the feat/check branch July 9, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant