Repository navigation
feat(rules): add keyword-rule matcher with config loading - #16
Merged
Merged
Conversation
Operator rules pin a canned answer to a question pattern. The matcher supports contains, exact and regex modes with priority ordering, loads from OPERATOR_RULES_JSON or OPERATOR_RULES_FILE, and skips invalid rules instead of breaking startup. RAGEngine.generate_response checks rules before retrieval and generation, so a matched question returns without a Pi job. Adds unit tests and operator docs. Part of #6
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.
What changed
Adds a deterministic operator-rule matcher so Wingman can return a pinned, approved answer for known questions instead of a generated one. Rules load from config, and the RAG ask path checks them before retrieval and generation.
Part of #6
Closes #15
How it was verified
mise run install- passed (backend via uv, frontend via bun, runtime deps)mise run test-backend- 47 passed, including 21 new tests inbackend/tests/test_rules.pymise run test-frontend- passed (the repo task currently reports no frontend tests yet)Proof
Backend started locally with
OPERATOR_RULES_JSON=[{"id":"vpn-reset","keywords":["reset vpn"],"response":"Use the IT portal to reset VPN access."}], a sqlite database and the Pi runtime pointed at a dead local port, so a matched answer can only come from the rule.Matched question returns the canned answer with the rule as its source:
Unmatched question leaves the rule path and enters normal retrieval (fails here only because Chroma is not running in this offline setup):
New tests, all passing: TestMatching (7), TestOrderingAndEnabled (3), TestConfigLoading (9), TestRagShortCircuit (2). The short-circuit tests assert retrieval and generation are never called for a matched question.
Reviewer notes
/api/askpath throughRAGEngine.generate_responsein this slice. Slack delivery still goes through the Pi Durable job flow, so wiring rules into the Slack handlers is a follow-up slice. That work would need a live Slack workspace to verify end to end, which this run must not use.OPERATOR_RULES_JSONandOPERATOR_RULES_FILE, documented in.env.exampleanddocs/operator-rules.md.uv.lockrefresh was reverted.