Skip to content

feat(cli): /files shows files referenced in the session#201

Merged
emal-avala merged 1 commit intomainfrom
feat/files-command
Apr 23, 2026
Merged

feat(cli): /files shows files referenced in the session#201
emal-avala merged 1 commit intomainfrom
feat/files-command

Conversation

@emal-avala
Copy link
Copy Markdown
Member

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.

> /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/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. /files gives a dense summary in one place — useful for context hygiene, cost audits, and writing PR descriptions.

Implementation

Pure-read over engine.state().messages:

  • User messages → regex-lite extraction of @path mentions (same rule as the REPL's @-expansion: @ at start or after whitespace, path contains / or .)
  • Assistant messages → scan ContentBlock::ToolUse for file-accessing tools (FileRead, FileWrite, FileEdit, MultiEdit, NotebookRead, NotebookEdit) with path / file_path / notebook_path input fields

Dedup by path; sources are set-merged so the same file with multiple access modes shows all of them. Sorted alphabetically.

New public API:

pub enum FileSource { Mention, Read, Write, Edit }
pub fn collect_session_files(&[Message]) -> Vec<(String, Vec<FileSource>, usize)>

Test plan

  • cargo fmt --all — clean
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo test -p agent-code --bin agent -- extract_at_mentions extract_tool_file collect_session_files — 6/6 pass
    • mention extraction: simple, email-rejection, path-shape-requirement
    • tool-input extraction: known tools mapped correctly, unknown tools skipped
    • end-to-end aggregation: mixed user+assistant transcript, set-merged sources

@chatgpt-codex-connector
Copy link
Copy Markdown

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.
@emal-avala emal-avala merged commit bb1c032 into main Apr 23, 2026
14 checks passed
@emal-avala emal-avala deleted the feat/files-command branch April 23, 2026 07:03
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.

1 participant