Skip to content

Conversation

@RonStew2019
Copy link

Adds /history command to display message history within current autosave session

Usage:

/history [N] [-v|--verbose]

Features:

  • Default: Shows last 10 messages with truncation for long content
  • Line count: N limits displayed messages (e.g., /history 5)
  • Verbose mode: -v displays full content without truncation

Normal:

image

Verbose:

image

github-actions bot and others added 26 commits October 12, 2025 03:37
… and model switching

- Update get_model_context_length() to respect agent-specific model pins via get_model_name()
- Add graceful fallback to prevent status bar crashes if model config lookup fails
- Ensure immediate agent reload when switching models in both CLI and TUI interfaces
- Call refresh_config() for JSON agents before reload to pick up new model settings
- Wrap reload operations in try-except to maintain stability during model changes
Add comprehensive attachment handling to enable users to drag files or paste URLs directly into prompts. The system automatically detects and processes images, PDFs, and other supported file types, passing them as binary content or URL references to the language model.

- Implement `attachments.py` parser with shell-like tokenization to extract file paths and URLs from raw prompt text
- Support local binary attachments (images: png/jpg/gif/webp, documents: pdf/txt/md) with MIME type detection
- Support remote URL attachments (http/https image and document links) using pydantic-ai's ImageUrl/DocumentUrl types
- Extend BaseAgent.run_with_mcp() to accept optional attachments and link_attachments parameters
- Add run_prompt_with_attachments() helper in main.py to parse, validate, and execute prompts with attachments
- Integrate attachment processing into both interactive mode and single-prompt execution flows
- Provide user-friendly warnings for unsupported file types, missing files, or permission errors
- Generate default prompt "Describe the attached files in detail" when user provides only attachments
- Add comprehensive test coverage for parsing logic, file type detection, and integration with agent execution
Previously, BinaryContent objects in messages were silently skipped during
string formatting, making it difficult to debug messages containing binary
data. Now BinaryContent is explicitly marked in the formatted output.
Implement comprehensive handling of terminal drag-and-drop file paths that contain backslash-escaped spaces, ensuring reliable attachment detection and proper prompt cleaning across the command processing pipeline.

- Introduce `_unescape_dragged_path()` to normalize backslash-space sequences before path resolution
- Use sentinel markers to preserve escaped spaces during shlex tokenization in `_detect_path_tokens()`
- Track token start indices in `_DetectedPath` for accurate span-based text replacement
- Rebuild cleaned prompts using token-span logic to maintain exact punctuation and spacing
- Update placeholder processor to use token spans for robust visual replacement with escaped paths
- Parse attachments before command detection to prevent leading file paths from being misinterpreted as commands
- Add test coverage for drag-and-drop escaped space handling
- Remove unused `_clean_binaries()` method from base agent
- Disable POSIX mode in shlex.split() on Windows to prevent backslash escaping
- Ensures Windows file paths with backslashes are correctly parsed as attachments
- Fixes issue where backslashes in paths were being incorrectly interpreted as escape characters
- Remove document file type support (.pdf, .txt, .md)
- Streamline media type detection to focus solely on images
- Eliminate document-specific fallback logic in MIME type detection
- Update function documentation to reflect image-only scope
- Add paginated display showing 5 sessions per page instead of fixed top-5 list
- Replace single prompt with interactive loop supporting page navigation
- Enable option 6 to cycle through pages or return to first page when at end
- Preserve existing selection methods (numeric choice and direct name entry)
- Improve user feedback with page-specific prompts and invalid selection warnings
- Maintain backward compatibility with original session restoration behavior
…tory mutation

- Remove URL detection from _parse_link to prevent URLs from being treated as attachments
- URLs in prompts now remain as plain text instead of being converted to ImageUrl or DocumentUrl
- Fix potential mutation bug in agent_manager by storing shallow copies of message histories
- Prevent shared list instances between agent history cache and active agents
- Update tests to reflect new behavior where URLs are left untouched in prompts
- Add persistent profile directory management to maintain browser state across runs
- Configure Camoufox to use stored cookies, localStorage, and history via storage_state
- Save browser context state on cleanup to preserve session data for future use
- Display profile directory path in startup info and state save confirmation
- Ensure profile directory is created if it doesn't exist at ~/.code_puppy/camoufox_profile
- Fix UsageLimits import to use public API instead of private module path
- Downgrade pydantic-ai from 1.0.6 to 1.0.5 for stability
- Refactor Camoufox browser initialization to use persistent context mode
- Remove automatic homepage navigation to prevent duplicate tabs
- Implement lazy page creation in get_current_page() method
- Add persistent storage state handling for cookies and localStorage
)
return True

if command.startswith("/history"):
Copy link
Owner

Choose a reason for hiding this comment

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

Hey Ronan - do you think you could refactor this nested functionality into its own thing, and then make this change in command_handler.py a 2-liner?

- Create code_puppy/command_line/history_command.py with MessageFormatter and HistoryCommand classes
- Refactor command_handler.py to use 2-liner for /history command as requested in PR feedback
- Maintain identical external functionality while improving internal structure
- Apply SOLID principles: Single Responsibility and Dependency Inversion
- Extract complex message formatting logic into reusable MessageFormatter class
- Clean separation of concerns between parsing, formatting, and display

Addresses PR feedback: 'refactor this nested functionality into its own thing, and then make this change in command_handler.py a 2-liner'
- Move /history implementation from command_handler.py to history_command.py
- Add comprehensive argument parsing and error handling
- Maintain full backward compatibility with all existing functionality
- Fix function name typo in test imports (get_current_autosave_session_name)
- Ensure all 8 history-related tests pass individually and as a group
- Improve code organization with better separation of concerns
- Enhance maintainability by isolating history logic in dedicated module

Changed files:
- code_puppy/command_line/history_command.py (new)
- code_puppy/command_line/command_handler.py (refactor)
- tests/test_command_handler.py (fix imports)
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.

6 participants