terminal-bench

repository·main·Indexed 25 days ago

https://github.com/harbor-framework/terminal-bench

A collection of tasks and evaluation harness (version 0.2.18) designed to evaluate AI agents' ability to perform autonomous, end-to-end complex tasks in real-world terminal environments. It includes adapters for converting and running benchmarks such as Aider Polyglot, AlgoTune, AppWorld, and CyBench, utilizing a CLI tool (`tb run`) to manage agent execution, Docker-based environments, and oracle solution verification.

Tokens
55.9K
Snippets
125
Records
255
Agent score
55%

What's inside terminal-bench

  1. Overview of the EvoEval Adapter

    main

    The EvoEval Adapter converts EvoEval Python programming problems into the Terminal-Bench format. It specifically targets the EvoEval_difficult subset, which consists of 100 challenging problems designed to test an agent's ability to handle complex requirements and robust algorithms.

    Key features include:

    • Automatic Repository Management: Supports auto-cloning the EvoEval GitHub repo or using a local installation.
    • Task Generation: Extracts function signatures, converts extensive test suites, and includes reference solutions.
    • Docker Integration: Runs each task in an isolated Docker container using pytest for validation.
    • Tailored Evaluation: Uses dynamic imports and type normalization to ensure rigorous testing of the agent's solution.py.
  2. Use the AlgoTune → Terminal-Bench Adapter

    main

    The AlgoTune adapter integrates 154 Python-based algorithm optimization tasks into the Terminal-Bench framework. The goal for an agent is to modify the Solver class in /app/solver.py to produce code that is both correct (identical outputs to the reference) and faster than the baseline implementation.

    Key Metrics: When using this adapter, refer to the benchmark as AlgoTune-Pass and the metric as resolve rate. This is distinct from the original AlgoTune 'score' which uses continuous speedup metrics. In Terminal-Bench, a task is a 'pass' if the solution is valid and not slower than the best solver in the original AlgoTune repository.

  3. Structure of a generated Aider Polyglot task

    main

    Each task generated by the Aider Polyglot adapter follows a specific directory structure to support multi-language builds and oracle solutions:

    • task.yaml: Terminal-bench task configuration.
    • run-tests.sh: Language-specific script to execute tests.
    • solution.sh: Script used to decrypt and apply the oracle solution.
    • Dockerfile: Defines the containerized runtime environment.
    • docker-compose.yaml: Orchestrates the container.
    • workspace/: The student's working directory, containing:
      • solution_files: Files intended for modification.
      • build_configs: Language-specific build files (e.g., Cargo.toml, build.gradle).
    • tests/: The test environment, containing:
      • .meta/: Exercism metadata and examples.
      • test_files: Unit tests.
      • helper_files: Additional files required for testing.
  4. Structure of a generated EvoEval task

    main

    Each EvoEval problem is converted into a standalone task directory with the following structure:

    evoeval/
    ├── {task_id}/
    │   ├── task.yaml                 # Task configuration
    │   ├── Dockerfile               # Container definition  
    │   ├── docker-compose.yaml      # Docker Compose configuration
    │   ├── run-tests.sh            # Test execution script
    │   ├── solution.sh             # Golden solution
    │   ├── problem_statement.py    # Original problem description
    │   └── tests/
    │       ├── test_outputs.py     # Evaluation script
    │       ├── setup-uv-pytest.sh  # uv and pytest setup script
    │       └── run-uv-pytest.sh    # uv pytest execution script

    Harness Lifecycle for these tasks:

    1. Setup: Docker container initializes with a Python environment.
    2. Problem presentation: Agent receives the problem_statement.py.
    3. Solution development: Agent creates a solution.py file.
    4. Testing: The evaluation script (test_outputs.py) imports the solution and runs pytest.
    5. Validation: Tests automatically discover the target function from the problem description to validate correctness.
  5. MDF JSON Format Conventions

    main

    The Model Data Format (MDF) JSON uses the following conventions for spatial and temporal data:

    • Spatial Vectors: Positions, normals, translations, and scales are expressed as [x, y, z] arrays.
    • Rotations: Expressed as quaternions in the format [x, y, z, w].
    • Texture Coordinates: Expressed as [u, v] arrays.
    • Time: All durations and timestamps are in seconds.
    • Matrices: Stored as flat arrays of 16 floats representing a row-major 4x4 matrix.
    • Hierarchy: All transformations are relative to the parent joint. Root joints are identified by a parent index of -1.
  6. SWE-Perf Adapter task details and metrics

    main

    Docker Images

    The adapter uses task-specific Docker images containing the environment and repository setup. Images follow the pattern: betty1202/sweb.eval.x86_64.<instance_id> (e.g., betty1202/sweb.eval.x86_64.scikit-learn_s_scikit-learn-11674).

    Task Instructions

    Instructions are derived from the original SWE-Perf dataset on Hugging Face. For OpenHands users, a Jinja2 template sweperf-openhands-instruction.j2 is provided to match the original authors' inference logic.

    Evaluation Metrics

    Currently, the adapter supports two of the three original SWE-Perf metrics:

    1. Apply (integrated into correctness)
    2. Correctness

    Note: The Performance improvement metric is planned for a future update.

  7. How the CyBench adapter works

    main

    The adapter uses a copy + append approach. It preserves the original CyBench structure while adding Terminal-Bench compatibility files.

    Key Generated Files:

    • task.yaml: Terminal-Bench task configuration (includes instruction, category, difficulty, and max_agent_timeout_sec: 3000.0).
    • Dockerfile.agent: An agent container based on cybench/cybench:latest (a 17GB Kali Linux image).
    • docker-compose.yaml: Orchestrates the agent and necessary services.
    • solution.sh: A rewritten oracle solution wrapper compatible with the Terminal-Bench container framework.

    Agent Environment: The agent runs in a container with tools like pwntools, ROPgadget, z3, and angr. Python 3.9 is provided with a virtual environment at /venv.

  8. How the GitHub webhook integration works

    main

    The bot includes a FastAPI server that listens for GitHub webhooks on the /webhook endpoint.

    When a Pull Request is merged, the following workflow occurs:

    1. Signature Verification: The bot verifies the x-hub-signature-256 header using the GITHUB_PAT to ensure the request came from GitHub.
    2. File Detection: It scans the files changed in the PR for any file named task.yaml.
    3. Content Fetching: For every task.yaml found, the bot fetches the full content from the GitHub API.
    4. Task Parsing: The YAML content is parsed to extract instruction, author_email, difficulty, and category.
    5. Discord Notification: An embed message is sent to the configured DISCORD_CHANNEL_ID containing the task details and PR metadata.
  9. Understand the DevEval task structure and lifecycle

    main

    Each DevEval repository is transformed into three distinct Terminal-Bench tasks (Implementation, UnitTesting, and AcceptanceTesting).

    Task Directory Structure

    Each task directory follows this pattern:

    • task.yaml: Task configuration.
    • Dockerfile: Container definition.
    • docker-compose.yaml: Docker Compose configuration.
    • run-tests.sh: Test execution script.
    • solution.sh: Golden solution.
    • deveval_source_repo/: The complete source repository (hidden from agents).
    • tests/: Contains test_outputs.py (evaluation script) and uv/pytest setup scripts.

    Execution Lifecycle

    1. Isolation: The deveval_source_repo is copied to /deveval_source_repo (hidden) and to /app (the agent's workspace).
    2. Setup: Files the agent is expected to create are removed from /app to prevent cheating.
    3. Evaluation: run-tests.sh is executed. It restores the removed files from /deveval_source_repo and runs the original test scripts.
    4. Success Marker: If tests pass, an ALL_PASSED marker is appended to unit_test.log or acceptance.log.
    5. Final Check: test_outputs.py (run via pytest) checks for the existence of the ALL_PASSED marker in the log files to determine the final score.
  10. Structure of a generated USACO task

    main

    Each USACO problem is converted into a self-contained directory containing the problem statement, oracle solution, test cases, and Docker configuration. The judge evaluates the agent's solution.py against the files in tests/data/ using tests/evaluate.py under the constraints defined in tests/data/constraint.json.

    usaco/
    ├── {problem_id}/
    │   ├── task.yaml                 # Task description (metadata, task time limits)
    │   ├── Dockerfile                # Container definition
    │   ├── docker-compose.yaml       # Docker Compose configuration
    │   ├── run-tests.sh              # Test execution script
    │   ├── solution.py               # Oracle solution
    │   └── tests/
    │       ├── data/                 # Input test cases/Expected outputs
    │       │   ├── 1.in
    │       │   ├── 2.in
    │       │   ├── ...
    │       │   ├── 1.out
    │       │   ├── 2.out
    │       │   └── constraint.json   # Test case limit (memory, time limits)
    │       └── evaluate.py           # Judge relevant codes