feat(cli): /files shows files referenced in the session#201
Merged
emal-avala merged 1 commit intomainfrom Apr 23, 2026
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Replaces the previous stub `/files` (which just prompted the agent to
list files via ls) with a real command that surfaces every file the
session has touched — @-mentioned paths, FileRead, FileWrite,
FileEdit, MultiEdit, NotebookRead, NotebookEdit.
> /files
Files referenced this session (3):
src/main.rs [@,read ] ×3
src/lib.rs [edit ] ×1
README.md [@ ] ×1
Each entry shows which access modes were used (`@` = @-mention,
`read` = FileRead, `write` = FileWrite, `edit` = FileEdit/MultiEdit)
and the total reference count.
Derived from scanning the conversation history:
* User messages → extract @-mentions (same rule as REPL
@-expansion: `@` at start or after whitespace, contains `/` or `.`)
* Assistant messages → extract `ContentBlock::ToolUse` entries
where the tool is file-accessing and the input has a path field
Dedup by path; sources are set-merged so the same file with multiple
access modes shows all of them. Sorted alphabetically by path.
New public API:
services (none — lives in cli/commands)
pub enum FileSource { Mention, Read, Write, Edit }
pub fn collect_session_files(&[Message]) -> Vec<(String, Vec<FileSource>, usize)>
Tests: 6 unit tests — mention extraction (simple, email rejection,
path-shape requirement), tool-input extraction (known tools mapped
to correct source, unknown tools skipped), and end-to-end
aggregation of a mixed user+assistant transcript.
537592f to
d086db1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the previous stub
/files(which just prompted the agent to `ls` the cwd) with a real command that surfaces every file the session has touched —@-mentioned paths,FileRead,FileWrite,FileEdit,MultiEdit,NotebookRead,NotebookEdit.Each entry shows which access modes were used (
@= @-mention,read= FileRead,write= FileWrite,edit= FileEdit/MultiEdit/NotebookEdit) and the total reference count.Why
Mid-session, the user often can't remember which files the agent has looked at. Scrolling back through the transcript is slow and noisy.
/filesgives a dense summary in one place — useful for context hygiene, cost audits, and writing PR descriptions.Implementation
Pure-read over
engine.state().messages:@pathmentions (same rule as the REPL's @-expansion:@at start or after whitespace, path contains/or.)ContentBlock::ToolUsefor file-accessing tools (FileRead,FileWrite,FileEdit,MultiEdit,NotebookRead,NotebookEdit) withpath/file_path/notebook_pathinput fieldsDedup by path; sources are set-merged so the same file with multiple access modes shows all of them. Sorted alphabetically.
New public API:
Test plan
cargo fmt --all— cleancargo clippy --workspace --all-targets -- -D warnings— cleancargo test -p agent-code --bin agent -- extract_at_mentions extract_tool_file collect_session_files— 6/6 pass