Skip to content

feat(learn): mine agent session histories (opt-in) - #52

Closed
baanish wants to merge 8 commits into
feat/learn-common-commandsfrom
feat/learn-agent-history
Closed

feat(learn): mine agent session histories (opt-in)#52
baanish wants to merge 8 commits into
feat/learn-common-commandsfrom
feat/learn-agent-history

Conversation

@baanish

@baanish baanish commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • Stacked on feat(learn): common build/test/dev/run/debug commands #51 (feat/learn-common-commands).
  • Adds opt-in agent session mining for qr learn (default off).
  • qr init asks whether to mine coding-agent session histories; stored as [learn].mine_agent_history (override with QR_LEARN_MINE_AGENT_HISTORY).
  • When enabled, scans local histories for bash/exec-like commands scoped to the current project folder:
    • Claude Code~/.claude/projects/<encoded-path>/*.jsonl
    • Codex~/.codex/sessions/**/*.jsonl (filtered by session cwd)
    • Pi~/.pi/agent/sessions/<encoded-path>/**/*.jsonl
    • omp (Pi fork) — ~/.omp/agent/sessions/<encoded-path>/**/*.jsonl
    • OpenCode~/.local/share/opencode/opencode.db parts for matching sessions
  • Results land in agent_commands (frequency-ranked), may fill empty role fields, and never clobber manifest-derived scripts. Inspection-only noise (ls, git status, cat, …) is filtered out.
  • Parsers are defensive (formats drift; local agent data may be incomplete). Missing stores are skipped silently.

Test plan

  • cargo test
  • cargo clippy --all-targets --locked -- -D warnings
  • cargo fmt --all -- --check
  • Unit tests with synthetic Claude/Codex/omp fixtures
  • CLI test: QR_LEARN_MINE_AGENT_HISTORY=true mines fixture under fake HOME
  • Manual: enable in config → qr learn in a project with real Claude/omp sessions → confirm agent_commands in .qr/profile.json

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.
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 481d51d5-6be1-4552-a086-9dce5c810899

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/learn-agent-history

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.

Comment thread src/agent_history.rs Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issue Found | Recommendation: Merge (non-blocking suggestion)

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1

Incremental review of 5068b3c..e179b1e (new commits: redact secret-bearing headers, align Go race targets, base sync). The 6 previously-reported findings remain resolved at HEAD (paths_related = cwd == project || cwd.starts_with(project); secret redaction, OpenCode LIKE escaping, chain splitting, and codex cap-after-filter all verified in place).

Issue Details (click to expand)

SUGGESTION

File Line Issue
src/agent_history.rs 755 parse_cd_navigation only recognises cd <target> and cd -- <target>; POSIX-flagged forms (cd -P/-L/-e) and bare cd fall into the _ => CdNavigation::Invalid arm, which breaks the whole mined chain (line 697) — dropping useful trailing commands (e.g. cd -P /repo && cargo test records nothing). Consider skipping recognized cd flags instead of Invalid-and-break.
Files Reviewed (5 files)
  • src/agent_history.rs - 1 issue
  • src/commands/learn.rs - 0 issues (terminal-control escaping added)
  • tests/cli.rs - 0 issues
  • CHANGELOG.md - 0 issues
  • src/project_profile.rs - 0 issues (incremental changes here are base-branch sync from feat(learn): common build/test/dev/run/debug commands #51, outside this PR's diff-vs-base)

Fix these issues in Kilo Cloud

Previous Review Summaries (2 snapshots, latest commit 5068b3c)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 5068b3c)

Status: No Issues Found | Recommendation: Merge

The incremental commit 5068b3c fix(learn): harden agent history mining and stop MSRV env races resolves all six previously reported findings in changed code:

  • Codex cwd over-matching (WARNING)paths_related no longer matches parent-directory sessions; parent-cwd sessions excluded (verified by new paths_related_excludes_parent_cwd test + codex fixture).
  • P1 secret redactionredact_secrets masks secret env assignments (*_API_KEY, *_SECRET, *_TOKEN, …) and known token literals (sk-, ghp_, AKIA, …) before storage.
  • P2 parent Codex sessions — fixed by the paths_related change above.
  • P2 short cd-prefixed chainsnormalize_and_split always splits &&/; chains and strip_leading_cd drops leading cd <dir> navigation.
  • P2 OpenCode LIKE wildcardsescape_like_literal escapes \, %, _ with ESCAPE '\\'.
  • P2 Codex cap before filteringcollect_jsonl_files_uncapped collects paths broadly, then the cap is applied after cwd matching.

Additional hardening (not flagged previously): AgentHistoryRoots.home is snapshotted once at construction so mining no longer re-reads HOME mid-scan (removes test env races); matching test_env_lock() guards added in src/ai/client.rs and src/config.rs.

Changed files reviewed line-by-line; no new issues found on changed lines.

Files Reviewed (3 files changed since 1e6d012)
  • src/agent_history.rs - 0 issues (all prior findings resolved)
  • src/ai/client.rs - 0 issues (test-only env-lock guard)
  • src/config.rs - 0 issues (test-only env-lock guards)

Previous review (commit 1e6d012)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
src/agent_history.rs 769 paths_related over-matches codex sessions whose cwd is an ancestor of the project (project.starts_with(cwd)), contradicting the "this project or a subdir" scoping documented at line 221.
Files Reviewed (11 files)
  • CHANGELOG.md - 0 issues
  • README.md - 0 issues
  • config/default.toml - 0 issues
  • src/agent_history.rs - 1 issue
  • src/commands/do_cmd.rs - 0 issues
  • src/commands/learn.rs - 0 issues
  • src/config.rs - 0 issues
  • src/lib.rs - 0 issues
  • src/main.rs - 0 issues
  • src/project_profile.rs - 0 issues
  • tests/cli.rs - 0 issues

Fix these issues in Kilo Cloud


Reviewed by glm-5.2-short · Input: 27.8K · Output: 23.2K · Cached: 1.3M

@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: 1e6d012c67

ℹ️ 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 thread src/agent_history.rs Outdated
Comment thread src/agent_history.rs Outdated
Comment thread src/agent_history.rs Outdated
Comment thread src/agent_history.rs Outdated
cursoragent and others added 7 commits July 9, 2026 09:04
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>
Comment thread src/agent_history.rs
match &words[start..] {
[_, target] => CdNavigation::Target(PathBuf::from(target)),
[_, option, target] if option == "--" => CdNavigation::Target(PathBuf::from(target)),
_ => CdNavigation::Invalid,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: parse_cd_navigation only recognises cd <target> and cd -- <target>; every other cd invocation (e.g. POSIX-flagged forms like cd -P /path / cd -L /path, or bare cd) falls into the _ => CdNavigation::Invalid arm.

record_command_scoped breaks the whole chain on Invalid (see line 697), so a mined session line such as cd -P /repo && cargo test is dropped entirely — the useful cargo test is silently skipped instead of being attributed to the resolved workdir. Consider treating recognized cd options (-e, -L, -P) as a no-op (skip the flag, keep scanning the remainder) rather than Invalid-and-break.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@baanish
baanish deleted the branch feat/learn-common-commands July 23, 2026 21:26
@baanish baanish closed this Jul 23, 2026
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