Skip to content

feat(compact): add context file extraction for /compact resume#1151

Merged
ErikBjare merged 2 commits into
masterfrom
feat-compact-filelist
Jan 26, 2026
Merged

feat(compact): add context file extraction for /compact resume#1151
ErikBjare merged 2 commits into
masterfrom
feat-compact-filelist

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Member

Summary

Implements Issue #1148: When using /compact resume, the LLM now identifies key files (specs, plans, source files) that should be preserved in the fresh context after compaction.

Changes

  • New: _parse_context_files() - Parses file paths from the LLM-generated resume
  • New: _load_context_files() - Loads file contents with optional truncation
  • Updated: _compact_resume() - Now includes context files in new conversation

Testing

Added 7 new tests. All 39 tests pass.

Closes #1148

Implements Issue #1148: When using '/compact resume', the LLM now identifies
key files (specs, plans, source files) that should be preserved in the fresh
context after compaction.

Changes:
- Add _parse_context_files() to extract file paths from LLM-generated resume
- Add _load_context_files() to load and optionally truncate file contents
- Update _compact_resume() to include context files in new conversation
- Add 7 new tests for file parsing and loading functionality

The LLM is prompted to list files in a parseable format within the
'Context Files' section. These files are then loaded and injected as
system messages before the resume summary, giving the model access to
the relevant file contents when continuing work.

Co-authored-by: Bob <[email protected]>
@greptile-apps

greptile-apps Bot commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR implements automatic context file extraction when using /compact resume. The LLM now identifies and suggests key files (specs, plans, source files) in the resume, which are then parsed, loaded, and included in the fresh conversation context after compaction.

The implementation adds two new helper functions:

  • _parse_context_files() extracts file paths from the LLM's resume using regex patterns to find markdown lists in a "Context Files" section
  • _load_context_files() loads the actual file contents with automatic truncation for large files (>2000 tokens)

The _compact_resume() function was updated to integrate this flow: after generating the resume, it parses suggested files, loads them, and inserts them as system messages in the new conversation log between the original system messages and the resume content.

The PR includes comprehensive test coverage (7 new tests) for parsing, loading, filtering, and truncation behavior.

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk
  • The implementation is well-tested with 7 new unit tests covering the main code paths. The changes are focused and isolated to the compact resume functionality. The only minor issue is a redundant import that doesn't affect functionality. The code properly handles errors (nonexistent files, truncation) and the tests verify correct behavior.
  • No files require special attention

Important Files Changed

Filename Overview
gptme/tools/autocompact.py Adds two new functions _parse_context_files() and _load_context_files() to extract and load context files from LLM-generated resume, and updates _compact_resume() to include these files in the new conversation. Contains a redundant import on line 868.
tests/test_auto_compact.py Adds 7 comprehensive tests for the new context file parsing and loading functionality, covering basic parsing, absolute paths, missing sections, URL filtering, file loading, and truncation.

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as /compact resume
    participant CompactResume as _compact_resume()
    participant LLM
    participant Parser as _parse_context_files()
    participant Loader as _load_context_files()
    participant FS as File System
    participant LogManager

    User->>CLI: /compact resume
    CLI->>CompactResume: msgs (conversation history)
    CompactResume->>CompactResume: prepare_messages(msgs)
    CompactResume->>User: Status: Generating resume...
    
    CompactResume->>LLM: Send conversation + prompt for resume
    Note over LLM: Generate resume with<br/>Context Files section
    LLM-->>CompactResume: resume_content (markdown)
    
    CompactResume->>FS: Save to RESUME.md
    
    CompactResume->>Parser: _parse_context_files(resume_content)
    Note over Parser: Extract file paths from<br/>Context Files section
    Parser-->>CompactResume: suggested_files[]
    
    CompactResume->>Loader: _load_context_files(suggested_files)
    loop For each file path
        Loader->>FS: Read file content
        FS-->>Loader: file content (or error)
        Loader->>Loader: Truncate if > max_tokens
    end
    Loader-->>CompactResume: loaded_files[(path, content)]
    
    CompactResume->>CompactResume: Extract original system messages
    CompactResume->>CompactResume: Create file_context_msgs from loaded_files
    CompactResume->>CompactResume: Build new log: system + files + resume
    
    CompactResume->>LogManager: Replace log with compacted version
    LogManager->>FS: Write new conversation.jsonl
    
    CompactResume->>User: Success: resume created, N files loaded
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread gptme/tools/autocompact.py Outdated
len_tokens is already imported at module level from ..message
@codecov

codecov Bot commented Jan 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 63.51351% with 27 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
gptme/tools/autocompact.py 63.51% 27 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ErikBjare ErikBjare merged commit 5b7b559 into master Jan 26, 2026
11 checks passed
@TimeToBuildBob TimeToBuildBob deleted the feat-compact-filelist branch February 28, 2026 20:59
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.

feat: support including file list in LLM-powered compact for Ralph Loop patterns

2 participants