feat: scope learned rules by path_glob — filter before Actor context and personal-rules injection#293
Merged
Merged
Conversation
…and personal-rules injection (#280) - Added _filter_learned_rules_by_files() to map_step_runner.py: rules with paths: frontmatter are only included in build_context_block() when the subtask affected_files match at least one path glob. Rules without paths: are always included (unconditional). - Added _format_learned_rules_block() to format applicable rules as a compact <learned_rules> XML block inside <map_context>. - Added _parse_rule_paths() + _paths_match_file() + _extract_target_file() to workflow-context-injector.py: personal rules from .map/personal/rules/learned/ are now filtered by paths: frontmatter against the current tool target file (Edit/Write/MultiEdit). Files without paths: are always loaded; Bash commands skip filtering. - Aligns MAP with Claude Code .claude/rules/ path-scoped behavior and the industry-standard hierarchical rule loading pattern (Stripe, Anthropic, IBM). Saves context budget by not loading irrelevant rules. Closes #280
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
Path-scoped filtering for learned rules — rules with
paths:frontmatter are now only loaded when the agent is working on matching files. This saves context budget and prevents irrelevant rules from leaking into unrelated modules.1.
build_context_block()inmap_step_runner.py_filter_learned_rules_by_files()— rules withpaths:frontmatter are only included when the subtaskaffected_filesmatch at least one path glob. Rules withoutpaths:are always included (unconditional)._format_learned_rules_block()— compact<learned_rules>XML block injected into<map_context>for Actor consumption.affected_files→ all rules included (cannot safely exclude without file context).2.
workflow-context-injector.py(personal rules)_parse_rule_paths()+_paths_match_file()+_extract_target_file()— personal rules from.map/personal/rules/learned/are filtered bypaths:frontmatter against the current tool target file (Edit/Write/MultiEdit).paths:) are always loaded. Bash commands skip filtering (cannot reliably determine target files).Why
Aligns MAP with Claude Code
.claude/rules/path-scoped behavior and the industry-standard hierarchical rule loading pattern (Stripe, Anthropic, IBM).How tested
make check: pyright 0, ruff clean, mypy clean, hook lint clean, render check passesCloses #280
🤖 Generated with Claude Code