File size: 1,436 Bytes
32df48d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""Models for coding_tools_env."""

from __future__ import annotations

from typing import Any

from openenv.core.env_server.types import State
from pydantic import BaseModel, Field


class CommandResult(BaseModel):
    """Normalized result for one tool execution."""

    tool: str
    ok: bool
    output: str = ""
    error: str | None = None
    metadata: dict[str, Any] = Field(default_factory=dict)


class TodoItem(BaseModel):
    """Todo item tracked by todo_write."""

    id: str
    content: str
    status: str
    priority: str


class CodingToolsState(State):
    """Per-session state for coding_tools_env."""

    sandbox_id: str | None = None
    setup_results: list[CommandResult] = Field(default_factory=list)
    verify_commands: list[str] = Field(default_factory=list)
    verify_results: list[CommandResult] = Field(default_factory=list)
    todos: list[TodoItem] = Field(default_factory=list)
    tool_history: list[CommandResult] = Field(default_factory=list)
    submitted: bool = False
    last_reward: float | None = None
    last_error: str | None = None


class EditSpec(BaseModel):
    """One edit operation for multi_edit."""

    old_string: str
    new_string: str
    replace_all: bool = False