5.6 KiB
5.6 KiB
AGENTS.md
This file provides guidance to coding agents collaborating on this repository.
Mission
Chase-rs is an efficient implementation of the chase algorithm in Rust for advanced reasoning engines. Priorities, in order:
- Correctness of reasoning (sound and complete chase).
- Termination guarantees (restricted chase for existential rules).
- Performance and scalability.
- Clear, maintainable, idiomatic Rust code.
Core Rules
- Use English for code, comments, docs, and tests.
- Keep all chase state inside well-defined structs; avoid global mutable state.
- Prefer small, focused changes over large refactoring.
- Add comments only when they clarify non-obvious behavior.
- Follow Rust idioms: use
Resultfor errors, iterators over manual loops, etc.
Quick examples:
- Good: add a new chase variant by implementing a trait or strategy pattern.
- Bad: add global configuration that affects all chase instances.
Repository Layout
src/: core implementation.src/chase/: chase algorithm modules.term.rs: terms (constants, nulls, variables).atom.rs: atoms (predicate applied to terms).instance.rs: database instance (set of facts).rule.rs: TGDs (tuple-generating dependencies).substitution.rs: variable bindings and unification.engine.rs: core chase algorithm.
tests/: integration, regression, and property-based tests.
Architecture Constraints
Instanceholds the database state (set of ground atoms).Rulerepresents tuple-generating dependencies (TGDs).- The chase engine is stateless; state is passed explicitly.
- New chase variants should be composable with existing infrastructure.
- Existential variables generate labeled nulls (
Term::Null).
Rust Conventions
- Target stable Rust (edition 2024, rust-version 1.92).
- Use
#[derive(...)]for common traits where appropriate. - Prefer
&stroverStringin function parameters when ownership isn't needed. - Use
impl Traitfor return types when the concrete type is an implementation detail. - Run
cargo clippyand address warnings before committing.
Required Validation
Run these checks for any non-trivial change:
cargo test(all unit and integration tests)cargo clippy(lint checks)cargo fmt --check(formatting)
For performance-sensitive changes:
- Add benchmarks if they don't exist
- Compare before/after performance
First Contribution Flow
Use this sequence for your first change:
- Read
src/chase/mod.rsand the relevant module files. - Implement the smallest possible code change.
- Add or update tests that fail before and pass after.
- Run
cargo test. - Run
cargo clippyand fix any warnings. - Update docs if public API behavior changed.
Example scopes that are good first tasks:
- Add tests for an edge case in unification.
- Implement a new utility method on
InstanceorAtom. - Add support for equality-generating dependencies (EGDs).
- Improve error handling with proper
Resulttypes.
Testing Expectations
- No chase logic change is complete without tests.
- Unit tests go in
#[cfg(test)] mod testswithin each module. - Integration tests go in
tests/integration_tests.rs. - Regression tests for bug fixes go in
tests/regression_tests.rs. - Property-based tests go in
tests/property_tests.rs. - Do not merge code that breaks existing tests.
Minimal unit-test checklist:
- Create an
Instancewith relevant facts. - Define rules using
RuleBuilder. - Run
chase(instance, &rules). - Assert on
result.terminated,result.instance, and derived facts.
Example test skeleton:
#[test]
fn test_example() {
let instance: Instance = vec![
Atom::new("Pred", vec![Term::constant("a")]),
].into_iter().collect();
let rule = RuleBuilder::new()
.when("Pred", vec![Term::var("X")])
.then("Derived", vec![Term::var("X")])
.build();
let result = chase(instance, &[rule]);
assert!(result.terminated);
assert_eq!(result.instance.facts_for_predicate("Derived").len(), 1);
}
Change Design Checklist
Before coding:
- Confirm whether the change affects chase semantics or termination.
- Identify affected tests.
- Consider impact on API stability.
Before submitting:
- Verify
cargo testpasses. - Verify
cargo clippyhas no warnings. - Ensure tests were added/updated where relevant.
Review Guidelines (P0/P1 Focus)
Review output should be concise and only include critical issues.
P0: must-fix defects (incorrect reasoning, non-termination, soundness bugs).P1: high-priority defects (likely functional bug, performance regression, API breakage).
Do not include:
- style-only nitpicks,
- praise/summary of what is already good,
- exhaustive restatement of the patch.
Use this review format:
Severity(P0/P1)File:lineIssueWhy it mattersMinimal fix direction
Practical Notes for Agents
- Prefer targeted edits over broad mechanical rewrites.
- If you detect contradictory repository conventions, follow existing code and update docs accordingly.
- When uncertain about correctness, add/extend tests first, then optimize.
- The chase algorithm has well-defined semantics; consult database theory literature if needed.
Commit and PR Hygiene
- Keep commits scoped to one logical change.
- PR descriptions should include:
- behavioral change summary,
- tests added/updated,
- performance impact (if applicable),
- API changes (if any).
Suggested PR checklist:
- Tests added/updated for behavior changes
cargo testpassescargo clippyhas no warningscargo fmtapplied