Skip to content

Conversation

@diegonix
Copy link
Contributor

Fix attachment parser crash from visual dividers and improve comment detection

Prevent OSError: File name too long crashes when CLI output containing screen drawing characters is misinterpreted as file paths. The parser was incorrectly processing sequences like "/"
followed by repeated Unicode box drawing characters as valid filesystem paths.

Key changes:

  • Add comprehensive Unicode box drawing character detection: ─ │ ┌ ┐ └ ┘ ├ ┤ ┬ ┴ ┼ ═ ║ ╚ ╝ ╔ ╗ ╠ ╣ ╦ ╩ ╬ ━ ┃ ┏ ┓ ┗ ┛ ┣ ┫ ┳ ┻ ╋
  • Add line separator and decorative characters: - = — – • · ○ ● ■ □ ░ ▒ ▓ █ ▄ ▌ ▐ ▀ ╭ ╮ ╯ ╰
  • Implement 50% threshold rule: exclude tokens where >50% of non-slash characters are dividers
  • Enhance comment detection with whitespace support for #, #, //, /*, ;, --, !, %, rem, REM, Note:
  • Add OSError protection around unhandled path.exists() call at line 270
  • Preserve all valid path functionality including Unicode characters in filenames

This fix prevents crashes from CLI output containing visual dividers while maintaining full compatibility with legitimate file paths that may contain Unicode characters.

mpfaffenberger and others added 30 commits September 11, 2025 05:08
This commit introduces improved error handling when loading the extra models configuration file. Instead of crashing when the file is missing, contains invalid JSON, or is unreadable, the application now logs appropriate warnings and continues operation with the base models configuration.

Key changes:
- Added try-except blocks around extra models file loading operations
- Implemented specific handling for JSON decode errors with helpful warning messages
- Added general exception handling for other file read errors (e.g., permissions issues)
- Updated tests to verify that invalid JSON and file errors don't interrupt config loading
- Maintained existing functionality while making the system more resilient to configuration errors

The changes ensure that users can continue using the application even if their extra_models.json file has syntax errors or other issues, while still receiving feedback about what went wrong. This improves the overall user experience and system stability.
Copy link
Owner

@mpfaffenberger mpfaffenberger left a comment

Choose a reason for hiding this comment

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

Approving this - I'm down to merge but can you take one more look at this @diegonix ?

if token.startswith("#"):

# Reject screen drawing/divider characters
divider_chars = {
Copy link
Owner

Choose a reason for hiding this comment

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

There has to be a better way to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! I agree the long hard‑coded list of “divider” characters wasn’t ideal. I’ve refactored it to a small, maintainable heuristic:

  • Detect visual separators by Unicode block ranges (Box Drawing U+2500–U257F, Block Elements U+2580–U259F, Geometric Shapes U+25A0–U25FF) plus a short extra set for common CLI/Markdown dividers, and keep the >50% ratio rule.
  • Treat long runs like ====/---- as dividers via a tiny regex.
  • Consolidate comment detection into one regex (^\s*(#|//|/\*|;|--|!|%), case‑insensitive).
  • Fix the OSError guard so the only exists()/is_file() check lives inside a try/except, preventing ENAMETOOLONG crashes.
    This removes the giant char set, improves readability, and broadens coverage without risking false positives on legitimate Unicode filenames. I’ve also added tests covering these cases. Happy to tweak thresholds if you prefer.
    (Unicode references for the blocks are in the PR description.)

mpfaffenberger and others added 28 commits October 26, 2025 16:59
- Update .python-version to pin to Python 3.13
- Add UV-managed Python installation instructions to README
- Include permanent configuration options and verification commands
- Ensure users get latest Python version instead of old system versions
- Remove .python-version file to let UV handle versions naturally
- Update README with one-time setup: export UV_MANAGED_PYTHON=1
- Users can now just run 'uvx code-puppy -i' without special flags
- UV automatically downloads latest compatible Python (3.13.3) when needed
- Tested: works perfectly even with old system Python (3.9.6)
Changed requires-python from '>=3.11' to '>=3.11,<3.14' to prevent
installation with Python 3.14+ when released. The uv.lock file was
updated to reflect this dependency constraint change.
…calls (mpfaffenberger#60)

* fix: race condition between automatic summarization and pending tool calls

Implement comprehensive solution to prevent "Cannot provide a new user prompt when the message history contains unprocessed tool calls" errors during automatic message compaction.

Key changes:
- Add has_pending_tool_calls() method to detect incomplete tool call sequences
- Implement delayed compaction queuing system with request_delayed_compaction() and should_attempt_delayed_compaction()
- Add race condition protection in compact_messages() before initiating summarization
- Include automatic retry mechanism in run_agent_task() after tool calls complete
- Add get_pending_tool_call_count() for debugging and user feedback
- Implement global _delayed_compaction_requested flag for cross-call coordination
- Provide comprehensive error handling with informative warning messages

Features:
- Detects ToolCallParts without corresponding ToolReturnParts
- Queues compaction requests when tool calls are pending execution
- Automatically retries compaction after tool completion without user intervention
- Maintains 100% backward compatibility with existing configurations
- Provides clear user feedback during deferred compaction scenarios

Testing:
- Comprehensive test suite validates syntax, method implementation, race condition protection, integration points, error handling, and logic correctness
- All 6 test categories pass with 100% success rate
- Mock testing confirms accurate detection of 4 test scenarios including complete, pending, empty, and mixed tool call states

This fix eliminates crashes while preserving automatic summarization functionality and maintaining system stability during high-volume tool execution scenarios.

* style: fix E402 import order - move global variable after imports
* add context diff line config

* format
Introduce a new plugin system that allows users to create custom slash commands by placing markdown files in specific directories. This feature enables users to define reusable prompts and commands without modifying the core codebase.

- Add customizable_commands plugin with automatic discovery and registration
- Support command files in .claude/commands/, .github/prompts/, and .agents/commands/ directories
- Implement MarkdownCommandResult class for seamless integration with existing command handler
- Update command handler to process markdown command results as input
- Add comprehensive documentation with usage examples in README
- Include message limit configuration for agent tool invocations
…broad exception handlers

The autosave calls were being swallowed by overly broad try/except blocks
in both main.py (interactive mode) and tui/app.py (TUI mode), causing
autosaves to fail silently without user notification.

- Move auto_save_session_if_enabled() call outside the broad exception handler in main.py
- Remove silent exception swallowing in TUI mode autosave call
- Ensures autosave errors are properly visible to users
- Fixes regression caused by race condition fix that introduced overly broad exception handling
- Add new auto_save_session config option with default value "true"
- Display auto_save_session status in command handler output
- Ensure auto_save_session is set when creating/updating config files
- Show current value as enabled/disabled in status information
* adding planning agent

* format
Integrate Claude Code OAuth authentication into Code Puppy, enabling users to authenticate through browser and automatically import available models.

- Implement complete OAuth 2.0 flow with PKCE security for Claude Code
- Add three custom commands: auth, status, and logout for token management
- Automatically fetch and register Claude Code models with 'claude-code-' prefix
- Securely store OAuth tokens in ~/.code_puppy with proper file permissions
- Include comprehensive test suite and detailed setup documentation
- Improve version handling fallback for development environments
…entication

- Add comprehensive ChatGPT OAuth plugin with browser-based authentication flow
- Implement PKCE OAuth flow matching OpenAI's official Codex CLI implementation
- Automatically fetch and register available ChatGPT models with 'chatgpt-' prefix
- Provide custom commands: /chatgpt-auth, /chatgpt-status, /chatgpt-logout
- Store tokens securely in ~/.code_puppy/chatgpt_oauth.json with 0600 permissions
- Exchange OAuth tokens for OpenAI API keys when organization/project is configured
- Refactor existing Claude Code OAuth plugin to use dedicated model files for better separation
- Update model factory to load from multiple model configuration sources
- Include comprehensive documentation, setup guides, and test coverage
- Add task tracking to enable graceful shutdown of running agent operations
- Modify run_prompt_with_attachments to return both result and asyncio task
- Update interactive mode to cancel running tasks on /exit and /quit commands
- Refactor ChatGPT OAuth plugin to create fresh OAuth contexts per instance
- Remove global OAuth context state machine for better isolation
- Update OAuth client ID configuration for Code Puppy application
- Delete unused math_utils.py file
- Removed complex API key exchange flow in favor of direct OAuth token usage like ChatMock
- Fixed JWT parsing to handle nested organization structure from user's payload
- Consolidated OAuth success/failure HTML templates into shared oauth_puppy_html module
- Replaced urllib.request/ssl with requests library for consistent HTTP handling
- Simplified token storage and model fetching logic
- Removed extensive documentation files (SETUP.md, README.md, ENABLE.md)
- Updated ChatGPT and Claude OAuth plugins to use shared HTML templates
- Fixed codex model to use OpenAIResponsesModel instead of OpenAIChatModel
- Filtered empty thinking parts from message history processing
- Added comprehensive test cases for JWT parsing with nested organization structure
…ents

- Assign underscore to second return value in test_run_prompt_with_attachments_passes_binary
- Assign underscore to second return value in test_run_prompt_with_attachments_warns_on_blank_prompt
- Maintains test compatibility with updated function signature that now returns a tuple
- Introduce new claude_code model type in ModelFactory with custom OAuth authentication
- Add specialized system prompt handling for Claude Code models in BaseAgent
- Update Claude Code OAuth plugin to use claude_code model type with proper headers
- Temporarily disable ChatGPT OAuth callbacks due to current implementation issues
- Include OAuth-specific headers (anthropic-beta) for Claude Code API compatibility
- Update model retrieval to use agent-specific configuration instead of global model
- Add special handling for Claude Code models with custom instructions
- Prepend Claude Code system prompt when applicable to ensure proper behavior
- Maintain separation between agent-specific and general prompt instructions
Fresh models on every auth! 🎾

- Changed add_models_to_extra_config() to start with empty dict
- Removes stale/accumulated models from previous auth sessions
- Ensures ~/.code_puppy/claude_models.json always reflects current API state
- Cleaner approach: overwrite instead of load-merge-save pattern

Now every /claude-code-auth gives you a clean slate with only the
models currently available from Claude Code's API. No more cruft!
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.

9 participants