This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
CodeRunner is a Moodle question type plugin for creating programming questions. Students write code that gets executed in sandboxes to test correctness. This is a mature plugin (version 5.7.1+) supporting multiple programming languages with sophisticated templating and UI customization.
- Question Type:
questiontype.php- Main Moodle question type implementation - Question Model:
question.php- Question instance representing a CodeRunner question - Sandboxes:
classes/sandbox.php,classes/jobesandbox.php- Code execution environments- JobeSandbox is the primary sandbox connecting to Jobe servers
- Multiple sandbox implementations available (Ideone, local)
- Templates: Twig-based template system for test case generation and grading
- UI Plugins: JavaScript-based interfaces (Ace editor, scratchpad, table, graph, etc.)
- Graders: Different grading mechanisms (equality, regex, template-based)
- Student submits code through UI plugin
- Question processes submission using templates
- Code executed in sandbox against test cases
- Results graded and displayed to student
- PHPUnit Tests:
moodle-plugin-ci phpunit(requires Moodle plugin CI setup) - Behat Tests:
moodle-plugin-ci behat --profile chrome(functional tests) - Individual Test: Use Moodle's standard PHPUnit runner for specific test classes
- PHP Lint:
moodle-plugin-ci phplint - Code Checker:
moodle-plugin-ci codechecker --max-warnings 0 - PHP Mess Detector:
moodle-plugin-ci phpmd - Copy/Paste Detector:
moodle-plugin-ci phpcpd - PHPDoc Checker:
moodle-plugin-ci phpdoc
- Grunt:
moodle-plugin-ci grunt(for minifying AMD modules) - Mustache Lint:
moodle-plugin-ci mustache - Validation:
moodle-plugin-ci validate
- Requires Moodle 4.3+ with PHP 8.1+
- Install companion plugin:
qbehaviour_adaptive_adapted_for_coderunner - Set up Jobe server or JobeInABox for sandbox execution
- Configure test sandbox in
tests/fixtures/test-sandbox-config.php
version.php- Plugin version and dependenciessettings.php- Admin settings for sandbox configurationdb/- Database schema, caches, tasks, and built-in prototypesclasses/- Main PHP classes for sandboxes, graders, utilities
amd/src/- JavaScript AMD modules for UI pluginstemplates/- Mustache templates for renderingstyles.css- Plugin styles
samples/- Example questions and prototypesunsupportedquestiontypes/- Community-contributed question typesace/- Ace editor integration files
tests/- PHPUnit test classes and Behat featurestests/fixtures/- Test data and sandbox configuration
Built-in question types are defined as prototypes in db/builtin_PROTOTYPES.xml. Custom prototypes can be created through the UI.
Questions use Twig templates to:
- Generate test code from test cases
- Process student answers
- Grade submissions with custom logic
- Support per-test-case or combinator grading
Multiple UI options available:
- Ace: Syntax-highlighted code editor (default)
- Scratchpad: Ace + in-browser code execution
- Table: Spreadsheet-like interface
- Graph: Visual graph editing
- HTML: Custom HTML interfaces
Code execution environments:
- Jobe: Default HTTP-based sandbox server
- Ideone: Cloud-based execution (legacy)
- Local: Direct server execution (limited)
- Follow Moodle coding standards
- Use dependency injection pattern for sandbox selection
- Template parameters support randomization for unique student questions
- Extensive caching system for grading performance
- Web service API available for external integrations
- Comprehensive backup/restore support