feat(learn): mine agent session histories - #55
Conversation
Add opt-in mining (default off, asked at qr init) that extracts bash/exec commands from Claude, Codex, Pi, omp, and OpenCode histories for the current project into agent_commands. Enable via [learn].mine_agent_history or QR_LEARN_MINE_AGENT_HISTORY.
Hold the shared env lock in AI/config tests that mutate process env, snapshot HOME for omp encodings, and tighten mining: exclude parent Codex cwds, redact secret-like tokens, split short cd/&& chains, escape OpenCode LIKE wildcards, and cap Codex sessions after cwd filtering. Co-authored-by: Aanish Bhirud <baanish@users.noreply.github.com>
|
Warning Review limit reached
Next review available in: 23 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (11 files)
Reviewed by glm-5.2-short · Input: 93.2K · Output: 11.8K · Cached: 843.5K |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ced8ca4b8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if let Some((name, _value)) = token.split_once('=') { | ||
| let name = name.strip_prefix("export").unwrap_or(name); | ||
| let name = name.trim_start_matches(['\'', '"']); | ||
| if looks_secret_name(name) { | ||
| return format!("{name}=***"); |
There was a problem hiding this comment.
Redact secrets nested inside flag values
When history contains commands such as kubectl create secret generic db --from-literal=password=hunter2, this logic examines only --from-literal before the first =, so the password remains unchanged. The complete command is then persisted in .qr/profile.json and, on a later qr do, serialized into the AI request, exposing the credential despite the redaction pass.
Useful? React with 👍 / 👎.
| fn reserve_codex_session_scan(scanned: &mut usize, overlaps: bool) -> bool { | ||
| if !overlaps || *scanned >= MAX_SESSION_FILES_PER_AGENT { | ||
| return false; | ||
| } | ||
| *scanned = scanned.saturating_add(1); |
There was a problem hiding this comment.
Count unrelated Codex sessions against the scan budget
When ~/.codex/sessions contains many sessions for other projects and fewer than 200 overlapping sessions, scanned is never incremented for those unrelated files. Consequently visit_jsonl_files opens every such file through codex_session_cwd, defeating the stated per-agent cap and making an opted-in qr learn scale with the user's entire Codex history.
Useful? React with 👍 / 👎.
| let start = command_start_index(&words, |_, _| {}); | ||
| if words.get(start).map(String::as_str) != Some("cd") { | ||
| return CdNavigation::NotCd; |
There was a problem hiding this comment.
Track non-cd directory changes before attributing commands
When an agent runs a chain such as pushd ../sibling && cargo test, pushd is treated as an ordinary command, so the tracked workdir remains the original project and the following cargo test is incorrectly mined for it even though it ran in the sibling. This pollutes command frequencies and can fill an otherwise empty role with a command belonging to another project; directory-changing constructs should update scope or stop attribution for the remainder of the chain.
Useful? React with 👍 / 👎.
| for project in project_variants { | ||
| let project_str = project.to_string_lossy().to_string(); | ||
| let Ok(rows) = stmt.query_map(rusqlite::params![project_str], |row| { |
There was a problem hiding this comment.
Deduplicate OpenCode parts across path variants
When an OpenCode session stores one project-path variant in session.directory and another in the linked project.worktree—for example /private/var/app versus /var/app on macOS—the same part row matches separate iterations of this loop and is recorded twice. Because counts drive ranking and role selection, these duplicated observations can incorrectly outrank commands that were actually run more often.
Useful? React with 👍 / 👎.
Recreated from closed PR #52 after its stacked base branch was merged and deleted. Preserves the reviewed history-mining feature and header redaction fixes, rebased onto current master.