Spaces:
Sleeping
Sleeping
File size: 4,602 Bytes
57c1397 | 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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | """Typed models for the WebSec Repair environment."""
from __future__ import annotations
from typing import Literal
from openenv.core.env_server.types import Action, Observation, State
from pydantic import BaseModel, Field
class PatchOption(BaseModel):
"""One available patch template for the active vulnerability task."""
id: str
label: str
class WebSecRepairAction(Action):
"""Actions available to an agent inside the environment."""
action_type: Literal["inspect", "classify", "apply_patch", "verify", "submit"]
vulnerability_type: str | None = Field(
default=None,
description="Chosen vulnerability label for classify actions.",
)
patch_id: str | None = Field(
default=None,
description="Chosen patch option for apply_patch actions.",
)
class WebSecRepairObservation(Observation):
"""Observation returned after each environment step."""
task_id: str = Field(default="", description="Active task id.")
instruction: str = Field(default="", description="Task instruction.")
code_snippet: str = Field(
default="",
description="Visible vulnerable code snippet after inspect.",
)
scanner_hint: str = Field(
default="",
description="Visible scanner hint after inspect.",
)
status_message: str = Field(
default="",
description="Human-readable result of the last action.",
)
selected_vulnerability: str = Field(
default="",
description="Currently selected vulnerability label.",
)
applied_patch_id: str = Field(
default="",
description="Currently applied patch option id.",
)
patch_options: list[PatchOption] = Field(
default_factory=list,
description="Patch options visible after inspect.",
)
exploit_test_passed: bool = Field(
default=False,
description="Whether the exploit is blocked.",
)
functionality_test_passed: bool = Field(
default=False,
description="Whether the legitimate behavior is preserved.",
)
grader_passed: bool = Field(
default=False,
description="Whether the task fully passes the grader.",
)
class WebSecRepairState(State):
"""Persistent episode state tracked by the environment."""
task_id: str = Field(default="sqli_login", description="Active task id.")
difficulty: str = Field(default="easy", description="Difficulty bucket.")
inspected: bool = Field(
default=False,
description="Whether inspect has been called in this episode.",
)
selected_vulnerability: str = Field(
default="",
description="Chosen vulnerability classification.",
)
applied_patch_id: str = Field(default="", description="Chosen patch option id.")
exploit_test_passed: bool = Field(
default=False,
description="Whether verify blocked the exploit.",
)
functionality_test_passed: bool = Field(
default=False,
description="Whether verify preserved functionality.",
)
submitted: bool = Field(default=False, description="Whether submit was called.")
score: float = Field(default=0.0, description="Current absolute grader score.")
class TaskDefinition(BaseModel):
"""Public task metadata."""
id: str
difficulty: str
title: str
instruction: str
code_snippet: str
scanner_hint: str
patch_options: list[PatchOption] = Field(default_factory=list)
class TaskCatalog(BaseModel):
"""Response model for /tasks."""
environment: str
default_task_id: str
tasks: list[TaskDefinition]
class GraderCheck(BaseModel):
"""One individual grader check."""
name: str
passed: bool
detail: str
class GraderReport(BaseModel):
"""Current grader state for a task."""
task_id: str
passed: bool
score: float
message: str
checks: list[GraderCheck] = Field(default_factory=list)
class BaselineActionStep(BaseModel):
"""One baseline action in the reference trajectory."""
action_type: Literal["inspect", "classify", "apply_patch", "verify", "submit"]
vulnerability_type: str | None = None
patch_id: str | None = None
class BaselineDefinition(BaseModel):
"""Public baseline trajectory for one task."""
task_id: str
title: str
description: str
actions: list[BaselineActionStep] = Field(default_factory=list)
class BaselineCatalog(BaseModel):
"""Response model for /baseline."""
environment: str
baselines: list[BaselineDefinition] = Field(default_factory=list)
|