Skip to content

feat(learn): mine agent session histories - #55

Merged
baanish merged 4 commits into
masterfrom
feat/learn-agent-history-merge
Jul 23, 2026
Merged

feat(learn): mine agent session histories#55
baanish merged 4 commits into
masterfrom
feat/learn-agent-history-merge

Conversation

@baanish

@baanish baanish commented Jul 23, 2026

Copy link
Copy Markdown
Owner

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.

baanish and others added 4 commits July 23, 2026 17:27
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>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@baanish, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 35d9b103-3295-459a-9a38-66819714be8d

📥 Commits

Reviewing files that changed from the base of the PR and between b75ed73 and 5ced8ca.

📒 Files selected for processing (11)
  • CHANGELOG.md
  • README.md
  • config/default.toml
  • src/agent_history.rs
  • src/commands/do_cmd.rs
  • src/commands/learn.rs
  • src/config.rs
  • src/lib.rs
  • src/main.rs
  • src/project_profile.rs
  • tests/cli.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/learn-agent-history-merge

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kilo-code-bot

kilo-code-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (11 files)
  • CHANGELOG.md
  • README.md
  • config/default.toml
  • src/agent_history.rs
  • src/commands/do_cmd.rs
  • src/commands/learn.rs
  • src/config.rs
  • src/lib.rs
  • src/main.rs
  • src/project_profile.rs
  • tests/cli.rs

Reviewed by glm-5.2-short · Input: 93.2K · Output: 11.8K · Cached: 843.5K

@baanish
baanish merged commit aff4ccd into master Jul 23, 2026
6 checks passed
@baanish
baanish deleted the feat/learn-agent-history-merge branch July 23, 2026 21:31

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agent_history.rs
Comment on lines +1176 to +1180
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}=***");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread src/agent_history.rs
Comment on lines +327 to +331
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread src/agent_history.rs
Comment on lines +748 to +750
let start = command_start_index(&words, |_, _| {});
if words.get(start).map(String::as_str) != Some("cd") {
return CdNavigation::NotCd;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread src/agent_history.rs
Comment on lines +423 to +425
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| {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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.

2 participants