Commit 2e6ced9
feat(cli): mempalace mined + purge --source-file (#7)
* feat(cli): mempalace mined + purge --source-file
Adds two ergonomic gaps in the mining-management surface JP asked for:
1. **mempalace purge --source-file <path>** — extends the existing
purge command with a third filter alongside --wing and --room.
Single-filter or combined ($and) usage works the same way wing/room
do; the filter accepts a metadata.source_file exact-match. End-to-
end test exercises a real palace and confirms only the matching
drawers are deleted, leaving siblings intact.
2. **mempalace mined** — companion to `mempalace status`, but groups
by wing × source_file rather than wing × room. Answers "which
files have I mined into this wing?" so an operator can pick
targets for the new --source-file purge. Skips drawers without a
source_file metadata key (diary entries, kg drawers, etc.).
Honors --wing and --limit (default 50 sources per wing, --limit 0
to show all). Uses the same paginated col.get() pattern as
miner.status() to handle 100K+ drawer palaces without tripping
sqlite's max-variable limit.
Together these close the "removing manually mined data" half of JP's
ask. The "automining when files change" half is queued for a separate
file-watcher daemon PR.
Pre-existing `mempalace mine <dir>` already covers "adding" (and
re-mines on mtime change via bulk_check_mined dedup), so no command
needed for refresh.
Tests: 8 new test cases (3 for purge --source-file with mock + real
palace; 3 for cmd_mined including end-to-end groupBy + wing filter +
no-palace error path; 2 updated to add the new arg to the test
namespace builder). Full suite: 1564 passed, 1 skipped, lint clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(cli): address Copilot review on #4
Four findings from Copilot's review pass on the mining-management CLI:
1. **--wing filter pushed into the query** (Copilot cli.py:800).
Previously cmd_mined fetched every drawer in the palace and filtered
in Python, doing O(total) work even for "mempalace mined --wing X"
on a 150K-drawer palace where X has 12K. Pre-fetch IDs via
col.get(where=...) to size the loop, then pass where= on each
batch get(). On the canonical palace, --wing filters now scan
~10x less data.
2. **Reject negative --limit at parse time** (Copilot cli.py:818).
argparse type=int silently accepted -1, producing nonsensical
"... -2 more" output. Add a typed _nonneg_int validator that
raises ArgumentTypeError on negatives. argparse turns that into
a clean exit code 2 with usage error message.
3. **Update module __doc__** (Copilot cli.py:1495). main() uses the
module docstring as the help epilog. The hard-coded command list
stopped at "status" — added "mined" and "purge --source-file"
so `mempalace --help` reflects the new commands.
4. **Dispatch test for `mempalace mined`** (Copilot cli.py:1542).
Sibling commands have main()-level dispatch tests; mined didn't.
A typo or registration regression would have slipped through unit
coverage. Added test_main_mined_dispatches and a paired
test_main_mined_rejects_negative_limit (verifies #2).
Tests: 68 cli tests pass; full suite green at 1566 passed, 1 skipped.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 69768fc commit 2e6ced9
2 files changed
Lines changed: 312 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
677 | 679 | | |
678 | 680 | | |
679 | 681 | | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
688 | 693 | | |
| 694 | + | |
689 | 695 | | |
690 | 696 | | |
691 | 697 | | |
| |||
711 | 717 | | |
712 | 718 | | |
713 | 719 | | |
| 720 | + | |
| 721 | + | |
714 | 722 | | |
715 | 723 | | |
716 | 724 | | |
| |||
741 | 749 | | |
742 | 750 | | |
743 | 751 | | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
744 | 837 | | |
745 | 838 | | |
746 | 839 | | |
| |||
1398 | 1491 | | |
1399 | 1492 | | |
1400 | 1493 | | |
1401 | | - | |
| 1494 | + | |
1402 | 1495 | | |
1403 | 1496 | | |
1404 | 1497 | | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
1405 | 1502 | | |
1406 | 1503 | | |
1407 | 1504 | | |
1408 | 1505 | | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
1409 | 1531 | | |
1410 | 1532 | | |
1411 | 1533 | | |
| |||
1444 | 1566 | | |
1445 | 1567 | | |
1446 | 1568 | | |
| 1569 | + | |
1447 | 1570 | | |
1448 | 1571 | | |
1449 | 1572 | | |
| |||
0 commit comments