File size: 1,011 Bytes
18a3fbf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Annotation enrichment utilities for Phase B5."""

from __future__ import annotations

from ci_triage_env.schemas.scenario import Scenario
from ci_triage_env.schemas.tools import ALL_TOOLS

_ALL_TOOL_NAMES: list[str] = [t.name for t in ALL_TOOLS]


def enrich_annotations(scenario: Scenario) -> Scenario:
    """Return a copy of *scenario* with ``informative_tools`` auto-populated.

    If the scenario already has a non-empty ``informative_tools`` list it is
    returned unchanged.  Otherwise we fall back to listing every tool for which
    at least one ``tool_outputs`` key exists — a conservative but correct
    default.
    """
    if scenario.informative_tools:
        return scenario

    covered: list[str] = []
    for tool_name in _ALL_TOOL_NAMES:
        for key in scenario.tool_outputs:
            if key == tool_name or key.startswith(tool_name + ":"):
                covered.append(tool_name)
                break

    return scenario.model_copy(update={"informative_tools": covered})