Repository navigation
fix(cli): honor --project/--exclude on every reporting command, and anchor absolute-path patterns - #1285
Conversation
The README says these flags work on every command. They did not: only report, overview, web, status, today, month and export declared them, so sessions, models, compare, audit, optimize, yield and spend either rejected the flag outright or silently reported the whole corpus. Each command already funnels through parseAllSessions, so the filter is applied at that single point with the shared filterProjectsByName. yield and spend parse inside computeYield / computeSpendFlow, which now take the patterns as optional arguments and default to filtering nothing. README now states the matching rule instead of claiming "all commands".
ozymandiashh
left a comment
There was a problem hiding this comment.
The plumbing half is right: all seven commands declare both flags, filtered at the one point each funnels through parseAllSessions, and the set matches the body. Suites, tsc and npm run build are green on the branch and on a merge with current main. Not mergeable yet, for one blocking reason and two disclosure gaps.
Blocking: the anchored rule was applied to filterProjectsByName only. src/usage-aggregator.ts:379-386 carries dayProjectMatches, documented as "Mirrors parser.filterProjectsByName exactly ... so a filter selects the same projects whether it is resolved against a fresh parse or against the day cache". It still lowercases and substring-matches. buildDurableOverviewFromNormalizedIndex (lines 535-546) and buildDurablePeriod (645, 707-725) call both matchers on the same opts.project, so today's live days anchor while every cached day substring-matches, inside one headline total. Reproduced on the tests/project-filter-durable-totals.test.ts harness with a carried day split across /Users/gone/app ($30) and /Users/gone/app-kit ($70):
--exclude /Users/gone/appon the carried day: expected 70, got 0 (sibling swallowed).--exclude /users/gone/app: expected 100, got 0 (case variant still excludes).
That regresses report, overview, status, today, month, export, dash and menubar, and breaks the headline-vs-By-Project reconciliation that suite exists to pin. Fix: route the cached path through matchesProjectPattern (it already takes { project, projectPath? }), drop the pre-lowercasing at 535-536 and 707-708, update the comment at 379-381, and add the sibling + case-variant cases to that suite.
Disclose: rooted POSIX patterns are now case-sensitive (/users/me/vault no longer matches /Users/me/vault; your own test pins it). That may be the right rule given #1260, but it's a second behavior change and neither the body nor the README mentions it.
Decision on the deferred question: keep the strict rule (a rooted pattern that is not a real prefix matches nothing), but a rooted pattern that matches zero projects should warn on stderr instead of failing silently. Wrong totals that look right are the worst outcome here.
Also: the new tests are unit tests of filterProjectsByName only, and the yield suites stub the filter to identity, so dropping the argument on any command would still pass. One integration case per command group please.
|
Thanks, the cached-day copy was a real miss. All four points are addressed, and the branch is three commits now, one idea each. Blocking, fixed. The rule is one closure (
Both fail against the old rule and pass against this one. Disclosure, added. The README now states that an absolute POSIX path is case-sensitive, that a Windows drive or UNC path folds case, and that a leading Your decision, implemented. The strict rule stays, and a rooted pattern that matches nothing warns on stderr, exit status untouched: Each pattern is judged on its own against the unfiltered list, so an earlier Integration coverage, added. Full suite green: 4426 passing, |
09f0139 to
be6a711
Compare
filterProjectsByName matched every pattern as a raw substring, so --exclude /a/my-company also removed the sibling /a/my-company-kit, and no pattern the caller could type expressed "this project and not its neighbours". A rooted pattern (POSIX, Windows drive, UNC) now keys through normalizeAbsProjectPathKey, the helper getagentseal#1271 added for project identity, and matches the way isProxiedPath matches proxyPaths: equal to the project path, or a prefix of it on a path-segment boundary. Going through that helper keeps one identity rule in the parser: identified Windows paths casefold, POSIX case stays identity, and a Codex-style stripped absolute path ("root/vault") keys the same as the pattern "/root/vault" the user types. A pattern that is not rooted stays the loose substring people type on the command line, so --project my-company keeps covering my-company-kit and worktrees. The rule lives in one closure (makeProjectFilter) applied to the live parse and to the carry-forward day cache alike. The cache path had its own copy, lowercasing and substring-matching, so a filtered headline anchored today's live days while matching every cached day loosely: on a carried day split across /Users/gone/app ($30) and /Users/gone/app-kit ($70), --exclude /Users/gone/app returned 0 instead of 70, and --exclude /users/gone/app excluded both instead of neither. Both shapes are in tests/project-filter-durable-totals.test.ts, the suite that exists to pin that a filter selects the same projects whether it is resolved against a fresh parse or against the cache. The README gains the rules that were not written down: an absolute POSIX path is case-sensitive while a Windows drive or UNC path folds case, and a leading ~ is the shell's to expand.
A rooted pattern selects one project or nothing, so a typo does not fail: it reports a total over a set nobody asked for, which reads exactly like a correct answer. The run now says so on stderr, and the exit status is untouched. unmatchedRootedPatterns() tries each pattern on its own against the UNFILTERED project list, which is what keeps it honest. Judged inside filterProjectsByName instead, an earlier --project would mask a later one selecting the same project, and an --exclude would be tested against what --project had already removed. The message is period-scoped, since a range-scoped parse is what was checked, and the durable path passes the carried days' project identities alongside the live parse, so a pattern naming only an expired-source project stays silent. Nothing is reported under `serve`. That path routes process.stderr.write into the progress-frame emitter (runCaptured), so a warning would reach the desktop app as a scan-progress line. The tests spawn the real CLI over a seeded corpus of two path siblings: sessions for the commands that filter at the call site, spend and yield for the two that take the patterns as arguments and filter inside, so dropping the argument anywhere fails the suite. They also pin the shapes that must stay silent: a pattern that selects something, a loose word, a second --project overlapping the first, and an --exclude naming a project --project had already removed.
46829b7 to
648fa40
Compare
ozymandiashh
left a comment
There was a problem hiding this comment.
Re-reviewed 648fa40 merged onto current main: tsc and npm run build clean, full suite 3878 passed / 0 failed, test:locks 36/36. All four points are delivered and I mutation-checked each: reintroducing the substring rule inside sumMatchingProjects fails exactly the two new durable tests; dropping the patterns on sessions or the arguments on computeYield fails the new CLI suite. Compiling the filter once in makeProjectFilter is a better shape than what I asked for, given how often the day cache runs it.
One new blocker, small and localized, in the warning:
- It fires into the Ink dashboard.
reportUnmatchedProjectPatternsonly guardsprocess.argv[2] === 'serve', butsrc/dashboard.tsx:390callsbuildDurablePeriodwith the filter, socodeburn report --project /typo(and barecodeburn, sincereportis the default command) writes a raw line over the rendered TUI. The repo already has the mechanism for this:setInteractiveScanUI, whichparser.ts:3229uses for the same reason. Route the warning through it. - The
serveguard is fragile.main.tsdeclares program-level--verboseand--timezone, socodeburn --verbose serveshiftsargv[2]and the warning becomes a progress frame inrunCaptured, andreportedthen outlives the request. Nothing passes--projecttoservetoday, but the Projects pane follow-up will. Key it off the actual command, not the argv position.
Non-blocking: indentation at src/main.ts:2241-2242, a type declared above its import in the new module, and the expired-source-only warning path has no test. Fix the two above and this is good to go.
A quoted '~/work/app' reaches the CLI unexpanded, and a pattern typed into a field has no shell behind it at all. It was neither rooted nor a substring of any stored path, so it selected nothing and said nothing. The README made it worse by telling people to quote it. A leading ~ is now expanded against the home directory and anchored like any absolute path, so the quoted form selects the same project as the one the shell would have expanded, and a wrong one is reported. Two more from reading the hot path: the compiled filter only pays for the project path key when some pattern is rooted and can read it, which the day cache runs per project, per day, per provider slice; and unmatchedRootedPatterns now calls matchesProjectPattern instead of open-coding it.
Three defects in the unmatched-pattern warning, all reported against a path that is in fact correct. `report`, `overview` and `status` judged a pattern against the live parse plus the day cache, while `sessions`, `models`, `audit`, `compare`, `optimize`, `yield` and `spend` judged it against the live parse alone. On a project whose transcripts have expired, `overview --project <path>` bills it while `sessions --project <path>` called the path wrong. The check now falls back to the day cache, and only for what the live parse missed, so the normal path reads no cache at all. The warning also reached two places that must never see it. An Ink screen owns the terminal, so it now honours the same `setInteractiveScanUI` latch the parser checks before printing scan progress: `report --project /typo` no longer writes over the dashboard. And `serve` routes every stderr write into the progress-frame emitter, so `runStdioServe` calls `suppressProjectFilterWarnings()` at startup rather than the module reading argv, which a leading `--verbose` would have shifted. SERVE_OPTIONS gains --project/--exclude for the seven commands that just declared them, as the comment above it requires. Without that a filtered request falls back to a cold spawn instead of the resident.
|
Both blockers are fixed in 740ec55 and d8dfd72, pushed on top so the delta since your review is readable. The Ink screen. Routed through the mechanism you pointed at: the warning now honours the same The serve guard. It no longer reads argv: The three non-blocking items are done: the indentation at the 740ec55 is separate: a quoted
One hole I left alone, tell me if you want it here or as a follow-up: Full suite 4431 passing, |
ozymandiashh
left a comment
There was a problem hiding this comment.
Re-reviewed d8dfd72 merged onto current main: tsc and npm run build clean, full suite 3883 passed / 0 failed, test:locks 36/36. Both blockers are fixed, and the structural fix is better than what I asked for: buildDurablePeriod no longer warns at all and the command layer resolves patterns once against knownProjects, so the Ink leak is gone by construction. Ran the real TUI with a typo'd pattern: stderr empty, dashboard renders, --format json still warns with valid JSON.
You are right about codeburn --verbose serve --stdio; the serve dispatch happens before Commander parses, so my repro could not have leaked. The argv key was still the wrong mechanism and suppressProjectFilterWarnings() is the right one.
Good catch on the fourth defect (overview vs sessions disagreeing on an expired-source path). Mutation-checked the fallback both ways: disabling it fails one test, making the cache read throw fails only the four unmatched-pattern tests and nothing on the normal path. Tilde expansion in compile() rather than at the CLI boundary is correct for the same live-vs-cache reason.
Two non-blocking notes for later: unmatchedRootedPatterns recompiles per entry (typo path only), and compare --format json counting self-corrections machine-wide is pre-existing for --provider too; worth a tracking issue. Approving; CI is now approved to run on this branch.
The CLI half of #1276, split out as you asked. The desktop Projects pane follows as a second PR on top of this branch.
What is in here
1. The seven commands that dropped the flags now honor them.
sessions,models,compare,audit,optimize,yieldandspenddeclare--project/--exclude, and the filter is applied at the one point they all funnel through (parseAllSessions).yieldandspendparse insidecomputeYield/computeSpendFlow, so those take the patterns as optional arguments.2. An absolute-path pattern is anchored to a path-segment boundary. Built on
normalizeAbsProjectPathKey/foldIdentifiedWindowsPathfrom #1271, as you asked, rather than a second copy of theisProxiedPathlogic. Both the pattern and the project path go through the same helper, so one identity rule holds for both:/a/Vaultand/a/vaultare two projects)root/vault) keys the same as the/root/vaulta user types/names no project instead of falling through to a substring that matches every pathA pattern that is not rooted stays the loose substring people actually type:
--project my-companystill coversmy-company-kitand worktrees, and a fragment likealice/projectsstill matches inside a longer path.The same rule reaches the carry-forward day cache:
dayProjectMatchesinsrc/usage-aggregator.tsused to carry its own lowercasing substring copy, so a filtered headline anchored today's live days and substring-matched every cached day inside one total. It now callsmatchesProjectPattern, and the callers stop pre-lowercasing.Disclosure: this makes rooted POSIX patterns case-sensitive.
--exclude /users/me/vaultno longer matches/Users/me/vault, because pattern and project path now go through the identity rule from #1271, where POSIX case is identity. A Windows drive or UNC pattern still folds case. The README says so now.3b. A rooted pattern that names no project warns on stderr. A rooted pattern selects one project or nothing, so a typo does not fail — it reports a total over a set the caller did not mean, which looks like a correct answer:
Each pattern is judged on its own against the unfiltered project list, so an earlier
--projectcannot mask a later one that selects the same project, and an--excludeis not tested against what--projectalready removed. The message is period-scoped because a range-scoped parse is what was checked, and the durable path passes the carried days' project identities alongside the live parse, so a path naming only an expired-source project stays silent. Nothing is reported underserve, where stderr is routed into the progress-frame emitter. A loose word never warns. Exit status is unchanged.One behavior change, resolved in review
A rooted pattern that is not a real path from the root used to substring-match and now matches nothing:
--exclude /Web/clientsselects no project, where before it excluded every project whose path contained that fragment. Anchoring cannot keep both meanings. Per review, the strict rule stays and the silence is what got fixed — see 3b above.Tests
tests/parser-filter.test.tscovers the sibling case in both directions, Windows casefolding against POSIX identity, the stripped-absolute path, trailing slashes and backslashes, and the slash-only pattern.tests/project-filter-durable-totals.test.tsadds the two carried-day shapes where a second copy of the rule diverges from the anchored one inside a single headline.tests/cli-project-filter-commands.test.tsspawns the real CLI over two path siblings:sessionsfor the commands that filter at the call site,spendandyieldfor the two that take the patterns as arguments, plus the warning and the cases that must stay silent. Dropping the argument from any of those three fails the suite.Full suite green: 4425 passing,
tscclean.What the second PR needs from you
status --scope combinedrejects--project/--exclude, since paired devices report their usage unfiltered. In the pane I made the filter win: Combined is unavailable while a project filter is set, because dropping the filter instead would put the hidden projects back inside the combined total, which is the one thing the pane exists to prevent. If you would rather the combined view stayed available and simply ignored the filter, that is a one-line change before I open it.