Commit 310524d
committed
fix: scan rules from disk; dedup flat-md scanners; round-trip paths/tags
Rules in ~/.claude/rules/ and {project}/.claude/rules/ never appeared in
the UI because no scanner populated the `rules` table — it was only ever
written by in-UI create_rule. Every other behavioural primitive has both
global and project scanners; this closes the scope asymmetry.
Changes:
* utils/paths.rs: add rules_dir to ClaudePathsInternal.
* services/scanner.rs:
- Introduce SOURCE_AUTO_DETECTED constant and walk_md_dir helper.
- Migrate scan_global_commands, scan_global_agents, scan_project_commands,
and scan_project_agents to use the helper — behaviour unchanged.
- Add ParsedRule, parse_rule_file, parse_list_value (accepts both JSON-
array and legacy comma-separated forms), upsert_rule_from_file,
scan_global_rules, scan_project_rules. Populate is_symlink and
symlink_target (previously dead-lettered). Wire into run_startup_scan
and the per-project loop.
* services/rule_writer.rs: emit paths and tags as JSON arrays so they
round-trip through the DB reader (which already expects JSON). The
previous comma-joined form was lost to serde_json::from_str. Tags were
dropped entirely before; now they round-trip too.
* commands/rules.rs: delete_rule now also removes the backing .md file,
so a UI delete is not resurrected by the new scanner as 'auto-detected'.
Factor the logic behind delete_rule_inner(conn, id, home) for testing.
Not touched (different shapes, out of scope):
* scan_*_skills (directory-based with skill_files child table).
* scan_*_hooks (JSON inside settings.json).
* Vendor scanners (opencode/codex/copilot/cursor/gemini).
Tests:
* 18 new tests across the four files (walk_md_dir edge cases,
parse_rule_file, parse_list_value dual-form, scan_global_rules insert/
idempotent/backfill/symlink, scan_project_rules assignment,
rule_writer JSON emission for paths and tags, delete_rule_inner with
disk-present and disk-absent).
* Full suite: 2010 pass, 0 fail.1 parent e32d638 commit 310524d
5 files changed
Lines changed: 710 additions & 139 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
142 | 164 | | |
143 | 165 | | |
144 | 166 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
149 | 172 | | |
150 | 173 | | |
151 | 174 | | |
| |||
548 | 571 | | |
549 | 572 | | |
550 | 573 | | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
551 | 642 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
697 | 697 | | |
698 | 698 | | |
699 | 699 | | |
| 700 | + | |
700 | 701 | | |
701 | 702 | | |
702 | 703 | | |
| |||
720 | 721 | | |
721 | 722 | | |
722 | 723 | | |
| 724 | + | |
723 | 725 | | |
724 | 726 | | |
725 | 727 | | |
| |||
751 | 753 | | |
752 | 754 | | |
753 | 755 | | |
| 756 | + | |
754 | 757 | | |
755 | 758 | | |
756 | 759 | | |
| |||
780 | 783 | | |
781 | 784 | | |
782 | 785 | | |
| 786 | + | |
783 | 787 | | |
784 | 788 | | |
785 | 789 | | |
| |||
815 | 819 | | |
816 | 820 | | |
817 | 821 | | |
| 822 | + | |
818 | 823 | | |
819 | 824 | | |
820 | 825 | | |
| |||
854 | 859 | | |
855 | 860 | | |
856 | 861 | | |
| 862 | + | |
857 | 863 | | |
858 | 864 | | |
859 | 865 | | |
| |||
894 | 900 | | |
895 | 901 | | |
896 | 902 | | |
| 903 | + | |
897 | 904 | | |
898 | 905 | | |
899 | 906 | | |
| |||
933 | 940 | | |
934 | 941 | | |
935 | 942 | | |
| 943 | + | |
936 | 944 | | |
937 | 945 | | |
938 | 946 | | |
| |||
971 | 979 | | |
972 | 980 | | |
973 | 981 | | |
| 982 | + | |
974 | 983 | | |
975 | 984 | | |
976 | 985 | | |
| |||
1096 | 1105 | | |
1097 | 1106 | | |
1098 | 1107 | | |
| 1108 | + | |
1099 | 1109 | | |
1100 | 1110 | | |
1101 | 1111 | | |
| |||
1150 | 1160 | | |
1151 | 1161 | | |
1152 | 1162 | | |
| 1163 | + | |
1153 | 1164 | | |
1154 | 1165 | | |
1155 | 1166 | | |
| |||
1187 | 1198 | | |
1188 | 1199 | | |
1189 | 1200 | | |
| 1201 | + | |
1190 | 1202 | | |
1191 | 1203 | | |
1192 | 1204 | | |
| |||
1255 | 1267 | | |
1256 | 1268 | | |
1257 | 1269 | | |
| 1270 | + | |
1258 | 1271 | | |
1259 | 1272 | | |
1260 | 1273 | | |
| |||
1340 | 1353 | | |
1341 | 1354 | | |
1342 | 1355 | | |
| 1356 | + | |
1343 | 1357 | | |
1344 | 1358 | | |
1345 | 1359 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
19 | 28 | | |
20 | 29 | | |
21 | 30 | | |
| |||
138 | 147 | | |
139 | 148 | | |
140 | 149 | | |
141 | | - | |
| 150 | + | |
142 | 151 | | |
143 | 152 | | |
144 | 153 | | |
145 | 154 | | |
146 | 155 | | |
147 | | - | |
| 156 | + | |
148 | 157 | | |
149 | 158 | | |
150 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
151 | 168 | | |
152 | 169 | | |
153 | 170 | | |
| |||
156 | 173 | | |
157 | 174 | | |
158 | 175 | | |
| 176 | + | |
159 | 177 | | |
160 | 178 | | |
161 | 179 | | |
| |||
0 commit comments