Skip to content

refactor(arch): inline RulesEngine pass-through into Pipeline classify - #10

Merged
br4vesirrobin merged 3 commits into
mainfrom
improve-arch/inline-rules-engine
Jul 7, 2026
Merged

refactor(arch): inline RulesEngine pass-through into Pipeline classify#10
br4vesirrobin merged 3 commits into
mainfrom
improve-arch/inline-rules-engine

Conversation

@br4vesirrobin

Copy link
Copy Markdown
Contributor

Summary

src/kontor_cli/rules_engine.py (77 lines) was a shallow pass-through: RulesEngine.classify() only sequenced the three rule loaders (YAML DSL > Python > NL) with logging glue, and get_nl_context() forwarded a single call to nl_rules.nl_rules_context(). Its interface was as complex as its implementation — every caller already had to know the three rule formats, their priority, and the LLM fallback.

It fails the deletion test in the good direction, so this PR deletes it:

  • Locality: the full classify sequence (YAML -> Python -> NL -> LLM fallback) is now visible in one place, Pipeline.classify_with_rules() / Pipeline._classify(), next to the orchestration that consumes it (folder policy, moves, triage).
  • Leverage: the rule loaders in kontor_cli.rules are called directly, so tests mock/stub them (or the single classify_with_rules seam) without an intermediary object.
  • No behavior change: identical priority order, identical log messages, identical CLI output; the classify command now goes through the Pipeline.

Changes

  • Pipeline.__init__ loads the three rule sources; classify_with_rules() holds the moved evaluation sequence; _llm_classify() takes NL context straight from nl_rules.nl_rules_context(); rules_engine.py deleted.
  • kontor-cli classify uses Pipeline.classify_with_rules().
  • Tests migrated 1:1 (245 passed on main, 245 passed here): rules_engine_test.py -> rules_test.py (loader tests unchanged), the priority-order test moved to pipeline_test.py::TestClassifyWithRules, coverage_gaps_test.py RulesEngine gaps now exercise the Pipeline, cli_test.py patches kontor_cli.cli.Pipeline.
  • Drive-by: ruff format applied to md_to_docx.py/md_to_docx_test.py (pre-existing format --check failures on main), separate commit.

Governance

  • Spec: docs/specifications/ACTIVE/inline-rules-engine-classify.md
  • Intake: .ai/work-intake/inline-rules-engine-classify.md
  • Handoff: .ai/handoff/northstar-inline-rules-engine-classify.md (autobahn prereq-check passes)

Verification

  • uv run pytest tests/unit/ -v — 245 passed
  • uv run ruff check src/ tests/ — clean
  • uv run ruff format --check src/ tests/ — clean
  • uv run mypy src/ --ignore-missing-imports — no issues

🤖 Generated with Claude Code

https://claude.ai/code/session_017p6obt6Ua7nB96YTG2XFKf

br4vesirrobin and others added 3 commits July 7, 2026 06:28
ruff format --check was failing on main for these two files adopted in
d6ecf06; formatting them here so the local gate is fully green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017p6obt6Ua7nB96YTG2XFKf
…engine-classify

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017p6obt6Ua7nB96YTG2XFKf
rules_engine.py was a shallow pass-through: classify() only sequenced
the three rule loaders (YAML DSL > Python > NL) with logging glue, and
get_nl_context() forwarded a single call. Deleting it concentrates the
classify sequence in the Pipeline, where the surrounding orchestration
(LLM fallback, folder policy, moves) already lives:

- Pipeline loads the three rule sources in __init__ and evaluates them
  in classify_with_rules(); log messages and priority are unchanged
- NL prompt context comes straight from nl_rules.nl_rules_context()
- the classify CLI command uses the Pipeline instead of a private
  RulesEngine; loaders/stubs are now mockable directly in tests
- rules_engine_test.py becomes rules_test.py (loader tests unchanged);
  the priority-order test moved to pipeline_test.py

No behavior change. Spec: docs/specifications/ACTIVE/inline-rules-engine-classify.md

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017p6obt6Ua7nB96YTG2XFKf
@br4vesirrobin
br4vesirrobin force-pushed the improve-arch/inline-rules-engine branch from 2825d16 to ee021ce Compare July 7, 2026 04:28
@br4vesirrobin
br4vesirrobin merged commit 9c6a5b2 into main Jul 7, 2026
11 checks passed
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