SSkilltecabyclaudinhocode
Enviar skill
← Voltar para o catálogo

moodle-coderunner

Desenvolvimento

Generate Moodle CodeRunner programming questions with Jobe server validation. Uses minimal pipeline: AI generates code + tests, Jobe computes expected output. Supports Java, Python, C, C++, Node.js. Produces import-ready Moodle XML. Battle-tested: 1000+ questions validated with 0% failure rate.

2estrelas
Ver no GitHub ↗Autor: danielcreggLicença: MIT

CodeRunner Question Generator (Minimal Pipeline)

Generate Moodle CodeRunner questions. Two modes depending on your environment.

Mode Detection

Before doing anything else, determine your mode:

Run this command:

echo "jobe-check"
  • If the command succeeds (you can execute bash): use FULL PIPELINE MODE (Sections 3-9). Jobe computes all expected output via curl. This is the preferred mode.
  • If the command fails (no bash access, e.g. Claude.ai or ChatGPT): use FALLBACK MODE (see box below). You must mentally trace expected output yourself.

FALLBACK MODE (no bash access)

When you cannot run bash commands (Claude.ai, ChatGPT, API without tools):

  1. Generate the same JSON structure as Section 6, but you MUST include "expected" in each test case by carefully tracing the solution through the test code.
  2. Trace character-by-character. Pay special attention to: trailing spaces, newlines, floating-point precision, array formatting.
  3. Apply all per-language rules from Section 2 and auto-fix rules from Section 8 manually.
  4. Wrap in XML using the template from Section 7.
  5. Add this warning to the user: "These questions were generated WITHOUT Jobe server validation. Before using them, import into Moodle and ensure Validate on save is enabled (it is by default). Moodle will run the solution against all test cases on import and flag any mismatches."
  6. All other sections (question design, type rules, XML template, checklist) still apply.

Full Pipeline mode is strongly preferred. It eliminates the #1 source of errors (hallucinated expected output, which causes 35% of all failures).


1. Question Type Reference

Choose the type FIRST -- it determines everything else.

TypeStudent WritesTest MechanismStdin?Reliability
java_classA classTest code calls methodsNoHIGH
java_methodStatic method(s) ONLYTest code calls methodsNoHIGH
java_programFull program with mainEmpty test, stdin inputYesLOW -- EOF issues
python3Function(s) or classTest code calls with print()NoHIGH
python3_w_inputFull programEmpty test, stdin inputYesMEDIUM -- EOF issues
c_functionFunction(s) + headersTest code has main()NoHIGH
c_programFull program with mainEmpty test, stdin inputYesMEDIUM
cpp_functionFunction(s) + headersTest code has main()NoMEDIUM -- Werror
cpp_programFull program with mainEmpty test, stdin inputYesMEDIUM -- Werror
nodejsFunction(s)Test code uses console.log()NoHIGH

Default choice: Prefer java_class > java_method > java_program. Prefer function types over program types -- they avoid stdin/EOF problems entirely.


2. Per-Language Rules

These rules are derived from 1000+ validated questions. Every rule exists because questions failed without it.

Java

RuleApplies ToWhat To Do
Scanner EOF guardjava_programALWAYS call hasNextLine()/hasNextInt() before EVERY Scanner read. #1 Java failure cause.
Class namejava_programClass MUST be named Answer
Method-only solutionjava_methodSolution MUST be ONLY the method(s) -- NO class wrapper, NO main(), NO import statements. The buildSource step wraps it in public class Answer { <methods> main() { testcode } }. Including public class or main() causes compilation errors.
Class qualifier in testsjava_classTest code runs in a separate __Tester__ class. Call static methods as ClassName.method(). Create objects as ClassName obj = new ClassName(); obj.method().

Python

RuleApplies ToWhat To Do
EOF guardpython3_w_inputUse import sys; data = sys.stdin.read().strip() with if data: guard. Never bare input().
Function-only solutionpython3Solution is function/class definitions only. Test code calls them with print().

C

RuleApplies ToWhat To Do
-WerrorALL C typesJobe compiles with -Werror. ALL warnings are fatal. No unused variables, no implicit declarations.
#include in answerc_functionALL headers (<stdio.h>, <ctype.h>, <string.h>, <math.h>, <stdlib.h>) MUST be in the solution, not just test code.
scanf return checkc_programAlways: if (scanf("%d", &n) == 1) { ... }. Unchecked scanf on empty stdin = uninitialized variable.
Test code wrapperc_functionTest code MUST include #include <stdio.h> and int main(void) { ... return 0; }
Array printingALL C typesUse if (i) printf(" "); printf("%d", arr[i]); -- NOT printf("%d ", arr[i]) (trailing space fails).
Function-only solutionc_functionSolution is function(s) with #include headers only. NO main(). Test code provides main().

C++

RuleApplies ToWhat To Do
-WerrorALL C++ typesSame as C -- all warnings fatal.
size_t for .size()ALL C++ typesfor (size_t i = 0; i < vec.size(); i++) -- int vs size_t is -Werror=sign-compare fatal.
Member init ordercpp_functionDeclare class members in SAME order as constructor initializer list. -Werror=reorder is fatal.
#include in answercpp_functionInclude <vector>, <string>, <algorithm>, <sstream> etc. in the solution, not just test code.
Test code wrappercpp_functionTest code MUST include #include <iostream>, using namespace std;, and int main() { ... }
Array printingALL C++ typesif (i) cout << " "; cout << v[i]; -- no trailing space.

Node.js

RuleApplies ToWhat To Do
Deterministic outputnodejsUse JSON.stringify(result) for objects/arrays. Do NOT use JSON.stringify(obj, replacer).
No npm packagesnodejsOnly Node.js built-in features. No require() of external modules.

3. Jobe Server Configuration

Servers

ServerURLNotes
Primaryhttps://jobe2.cosc.canterbury.ac.nzCanterbury University public Jobe. No API key needed.
Backuphttp://3.252.250.94EC2 backup with CORS proxy.

Try the primary server first. If it fails (timeout or HTTP error), fall back to the backup.

Language IDs for Jobe

Question TypesJobe language_id
python3, python3_w_inputpython3
java_class, java_method, java_programjava
c_function, c_programc
cpp_function, cpp_programcpp
nodejsnodejs

Calling Jobe via curl

Use this exact curl pattern for every Jobe call:

curl -s -w "\n%{http_code}" \
  https://jobe2.cosc.canterbury.ac.nz/jobe/index.php/restapi/runs \
  -H "Content-Type: application/json" \
  -d '{
    "run_spec": {
      "language_id": "LANGUAGE_ID",
      "sourcecode": "FULL_SOURCE_CODE",
      "input": "STDIN_OR_EMPTY",
      "sourcefilename": "FILENAME",
      "parameters": {"cputime": 10, "memorylimit": 256000}
    }
  }'

Response format:

{"outcome": 15, "cmpinfo": "", "stdout": "42\n", "stderr": ""}

Outcome codes:

  • 15 = success. Use stdout as the expected output.
  • 11 = compilation error. Read cmpinfo for the error.
  • 12 = runtime error. Read stderr for the error.
  • 13 = time limit exceeded.
  • 17 = memory limit exceeded.
  • Any other outcome = failure.

Important: Stdin MUST end with \n. If the input does not end with a newline, append one before sending.

Important: Expected output: strip the trailing newline from stdout before using it as expected output. CodeRunner strips trailing newlines before comparing, so the <expected> tag should NO

Como adicionar

/plugin marketplace add danielcregg/coderunner-skill

O comando exato pode variar conforme o repositório. Confira o README no GitHub.

Comentários · Nenhum comentário

Entre para comentar. Entrar

  • Ainda não há comentários. Seja o primeiro.