Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 11, 2025

๐Ÿค– AI-Powered Solution

This pull request implements a code verifier for the GitHub Bot, based on the requirements described in issue #232 and the Habr article referenced.

๐Ÿ“‹ Issue Reference

Fixes #232

๐Ÿš€ Implementation Details

Code Verifier Core (modules/code_verifier.py)

  • Safe Code Execution: Executes Python code in a controlled environment using exec() with isolated globals/locals
  • Output Capture: Captures both stdout and stderr using StringIO and redirect_stdout/redirect_stderr
  • Error Handling: Comprehensive exception handling with full traceback information
  • Environment Persistence: Variables persist between executions within the same session
  • Environment Reset: Ability to reset execution environment for fresh starts
  • Fix Callback Support: Framework for automatic code correction (up to 7 attempts)

Bot Commands

Two new commands have been added to the VK bot:

  1. Code Verification Command

    • Patterns: verify <code>, ะฟั€ะพะฒะตั€ะธั‚ัŒ <code>, ะฒั‹ะฟะพะปะฝะธั‚ัŒ <code>
    • Functionality: Executes Python code and returns results or error messages
    • Response Format:
      • Success: โœ… with output
      • Error: โŒ with traceback
    • Length Limiting: Responses are truncated to avoid VK message limits
  2. Environment Reset Command

    • Patterns: reset code, ัะฑั€ะพัะธั‚ัŒ ะบะพะด, reset env, ัะฑั€ะพัะธั‚ัŒ ัั€ะตะดัƒ
    • Functionality: Clears the execution environment
    • Response: ๐Ÿ”„ confirmation message

Integration Points

  • Pattern Matching: New regex patterns in patterns.py
  • Command Registration: Commands registered in main bot class __main__.py
  • Module Exports: CodeVerifier exported through modules/__init__.py

๐Ÿงช Testing

Comprehensive Test Suite (tests.py)

Added Test4CodeVerifier class with tests covering:

  • โœ… Simple successful code execution
  • โœ… Code with variables and multiple statements
  • โœ… Error handling for undefined variables
  • โœ… Syntax error handling
  • โœ… Environment persistence between executions
  • โœ… Environment reset functionality
  • โœ… Global variable management
  • โœ… Fix callback system (both with and without callbacks)

Standalone Testing

  • Created examples/test_code_verifier.py for dependency-free testing
  • All core functionality verified and working correctly

๐Ÿ“– Documentation

  • Examples: Comprehensive usage examples in examples/code_verifier_examples.md
  • Security Features: Documented isolation and safety measures
  • Integration Guide: Examples for AI assistant workflows

๐Ÿ”’ Security Considerations

  • Isolated Execution: Code runs in controlled environment with limited scope
  • Error Containment: All exceptions properly caught and handled
  • Output Control: Captured output prevents unintended side effects
  • Environment Isolation: Each user session maintains separate execution context

๐ŸŽฏ Use Cases

  1. Educational: Users can test Python code snippets and see results
  2. AI Integration: Combine with GitHub Copilot for code generation + verification workflow
  3. Debugging: Iterative code testing and improvement
  4. Learning: Safe environment for experimenting with Python concepts

๐Ÿ“ Implementation Notes

  • Based on the Habr article: https://habr.com/ru/articles/724012/
  • Follows the pattern of code generation โ†’ verification โ†’ correction loop
  • Compatible with existing bot architecture and commands
  • Minimal dependencies (uses only Python standard library for core functionality)

This implementation provides a solid foundation for the code verifier functionality requested in issue #232, enabling users to safely execute and verify Python code directly within the bot interface.


๐Ÿค– Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #232
@konard konard self-assigned this Sep 11, 2025
@konard konard changed the title [WIP] GitHub Bot: implement code verifier GitHub Bot: implement code verifier Sep 11, 2025
- Add CodeVerifier class for safe Python code execution
- Support code verification with output capture and error handling
- Add environment persistence and reset capabilities
- Implement verify and reset commands with Russian/English patterns
- Add comprehensive test suite covering all functionality
- Include examples and documentation
- Integration with existing bot command system

This enables the workflow described in issue #232 and the referenced
Habr article for code generation and verification.

๐Ÿค– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard marked this pull request as ready for review September 11, 2025 08:22
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.

GitHub Bot: implement code verifier

2 participants