Skip to content

fix(discover): sanitize absolute -p paths before matching project dirs#2889

Open
AZERDSQ131 wants to merge 1 commit into
rtk-ai:developfrom
AZERDSQ131:fix/discover-absolute-path-filter
Open

fix(discover): sanitize absolute -p paths before matching project dirs#2889
AZERDSQ131 wants to merge 1 commit into
rtk-ai:developfrom
AZERDSQ131:fix/discover-absolute-path-filter

Conversation

@AZERDSQ131

Copy link
Copy Markdown

Closes #2834

rtk discover -p <absolute path> always reports 0 sessions and prints the success message "No missed savings found. RTK usage looks good!" — a false all-clear — while the same project filtered by a name substring reports many sessions with substantial missed savings.

Repro (from the issue):

$ rtk discover --since 7 | grep Scanned
Scanned: 16 sessions (last 7 days), ~1400 Bash commands        # cwd mode: OK
$ rtk discover -p my-app --since 7 | grep Scanned
Scanned: 16 sessions (last 7 days), ~1400 Bash commands        # name substring: OK
$ rtk discover -p /home/user/projects/my-app --since 7 | grep Scanned
Scanned: 0 sessions (last 7 days), 0 Bash commands             # absolute path: silently nothing

Root cause: Claude Code stores transcripts under sanitized project directory names where path separators become dashes (~/.claude/projects/-home-user-projects-my-app/, via ClaudeProvider::encode_project_path). src/discover/mod.rs's run() already ran the default (no -p) cwd through encode_project_path before matching, but the -p branch passed the raw value straight through:

} else if let Some(p) = project {
    Some(p.to_string())   // never sanitized
}

A -p value containing / can therefore never substring-match the sanitized directory name (src/discover/provider.rs's discover_sessions_in_projects_dir does a plain dir_name.contains(filter)).

Fix: extracted the filter resolution into resolve_project_filter(project, all, cwd). A -p value containing / or \ is now treated as a filesystem path and sanitized the same way as the default cwd; a -p value with no separator is still treated as a plain name substring, unchanged from today's already-working "name substring" mode.

Adds five unit tests:

  • --all overrides everything regardless of -p
  • an absolute Unix path resolves to the exact same filter as the equivalent default cwd (Some("/home/user/projects/my-app") == default cwd "/home/user/projects/my-app")
  • a Windows backslash path is sanitized
  • a plain name substring passes through unchanged
  • the no-project default still encodes the cwd

Ran the mandatory gate locally:

  • cargo fmt --all — applied (reformatted a few wrapped lines)
  • cargo clippy --all-targets — clean
  • cargo test --all — 2398 passed (+ 6/11/11/14/5/11 in the other suites), 0 failed

`rtk discover -p <absolute path>` always reported 0 sessions and
printed the success message "No missed savings found. RTK usage looks
good!" -- a false all-clear -- while the same project filtered by a
name substring reported many sessions.

Claude Code stores transcripts under sanitized project directory names
where path separators (and other non-alphanumeric characters) become
dashes (~/.claude/projects/-home-user-projects-my-app/). The default
(no -p) branch already ran the cwd through
ClaudeProvider::encode_project_path before matching, but the -p branch
passed the raw value straight through. A -p value containing a path
separator can therefore never substring-match the sanitized directory
name, so the filter silently matched zero projects instead of erroring
or falling back.

Extracted the filter resolution into `resolve_project_filter`: a -p
value containing '/' or '\\' is now treated as a filesystem path and
sanitized the same way as the default cwd; a -p value with no
separator is still treated as a plain name substring, unchanged from
today's already-working behavior.

Adds five unit tests covering: --all overrides everything, an absolute
Unix path resolves to the exact same filter as the equivalent default
cwd, a Windows backslash path is sanitized, a plain name substring is
passed through untouched, and the no-project default still encodes the
cwd.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

discover: -p with an absolute path silently matches nothing (sanitized transcript dir names)

2 participants