File size: 3,520 Bytes
2db0a88
 
 
 
 
 
 
a8a9661
2db0a88
 
 
 
 
 
 
 
 
 
 
7b9f847
 
 
2db0a88
 
 
 
 
a8a9661
2db0a88
 
 
 
 
 
 
 
 
 
 
 
 
 
7b9f847
 
 
2db0a88
 
 
 
 
a8a9661
2db0a88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b9f847
 
 
 
 
2db0a88
 
 
 
 
 
 
147b2e1
 
 
2db0a88
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from app.models import TaskDefinition, TaskType


TASKS: dict[str, TaskDefinition] = {
    "easy": TaskDefinition(
        id="easy",
        task_type=TaskType.EASY,
        has_grader=True,
        title="Detect syntax errors",
        code=(
            "def add_numbers(a, b)\n"
            "    result = a + b\n"
            "    return result\n"
        ),
        instructions=(
            "Identify the exact syntax error in the code and propose a valid fix. "
            "The response should mention the specific line-level issue and corrected syntax."
        ),
        criteria=[
            ["syntax error", "invalid syntax", "parse error"],
            ["missing colon", "colon after function definition", "def line needs colon", "function header missing :"],
            ["def add_numbers(a, b):", "add a colon at end of function definition", "append colon to def add_numbers(a, b)"],
        ],
    ),
    "medium": TaskDefinition(
        id="medium",
        task_type=TaskType.MEDIUM,
        has_grader=True,
        title="Suggest optimization",
        code=(
            "def squared_evens(numbers):\n"
            "    result = []\n"
            "    for n in numbers:\n"
            "        if n % 2 == 0:\n"
            "            result.append(n * n)\n"
            "    return result\n"
        ),
        instructions=(
            "Suggest performance or readability optimizations while preserving behavior. "
            "Mention at least one concrete optimization strategy and why it helps."
        ),
        criteria=[
            ["list comprehension", "comprehension", "single expression"],
            ["same behavior", "preserve behavior", "without changing output", "no behavior change", "identical output"],
            ["readability", "cleaner", "more concise", "more readable", "clearer"],
        ],
    ),
    "hard": TaskDefinition(
        id="hard",
        task_type=TaskType.HARD,
        has_grader=True,
        title="Full code review with scoring",
        code=(
            "def average(values):\n"
            "    total = 0\n"
            "    for i in range(len(values)):\n"
            "        total += values[i]\n"
            "    return total / len(values)\n\n"
            "def process(data):\n"
            "    try:\n"
            "        return [average(x) for x in data]\n"
            "    except Exception:\n"
            "        return []\n"
        ),
        instructions=(
            "Perform a full code review covering correctness, robustness, efficiency, and maintainability. "
            "Include an explicit overall score in the review."
        ),
        criteria=[
            ["division by zero", "empty list", "len(values) == 0", "guard against empty values"],
            ["broad exception", "except Exception", "too broad catch", "catching all exceptions"],
            ["iterate directly", "avoid range(len", "pythonic loop", "loop over values directly"],
            ["type hints", "docstring", "tests", "unit tests", "annotations"],
            ["overall score", "score", "rating", "final score", "overall rating"],
        ],
    ),
}


ORDERED_TASK_IDS: list[str] = ["easy", "medium", "hard"]

# Explicit curriculum ordering for multi-task episodes and static validators.
ORDERED_TASK_DEFINITIONS: list[TaskDefinition] = [TASKS[tid] for tid in ORDERED_TASK_IDS]


def get_task(task_id: str) -> TaskDefinition:
    if task_id not in TASKS:
        raise KeyError(f"Unknown task_id: {task_id}")
    return TASKS[task_id]