51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
"""动态编译流水线的全部路径规则。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
def _find_project_root(module_dir: Path) -> Path:
|
|
"""通过项目标志定位根目录,不编码包目录深度。"""
|
|
|
|
for candidate in (module_dir, *module_dir.parents):
|
|
if (
|
|
(candidate / "provider_routes.json").is_file()
|
|
and (candidate / "scripts").is_dir()
|
|
and (candidate / "data").is_dir()
|
|
):
|
|
return candidate
|
|
raise RuntimeError(f"cannot locate project root from {module_dir}")
|
|
|
|
|
|
PROJECT_ROOT = _find_project_root(Path(__file__).resolve().parent)
|
|
DATA_ROOT = PROJECT_ROOT / "data"
|
|
RESULTS_ROOT = PROJECT_ROOT / "results"
|
|
ENV_FILE = PROJECT_ROOT / ".env"
|
|
|
|
DYNAMIC_RESULTS_ROOT = RESULTS_ROOT / "dynamic-optimization"
|
|
TRACE_ROOT = DYNAMIC_RESULTS_ROOT / "traces"
|
|
RAW_TRACE_ROOT = TRACE_ROOT / "raw_agent_trace"
|
|
FINAL_SCORE_ROOT = TRACE_ROOT / "final-score"
|
|
COMPILED_SKILL_ROOT = DYNAMIC_RESULTS_ROOT / "compiled-skills"
|
|
|
|
|
|
def project_path(value: Path) -> Path:
|
|
"""将命令行相对路径稳定地解释为项目根目录下的路径。"""
|
|
|
|
expanded = value.expanduser()
|
|
return (expanded if expanded.is_absolute() else PROJECT_ROOT / expanded).resolve()
|
|
|
|
|
|
def default_outputs(trace_input: Path, compile_type: str) -> tuple[Path, Path]:
|
|
"""按默认原始轨迹树中的身份生成评分和候选产物目录。"""
|
|
|
|
try:
|
|
relative = trace_input.resolve().relative_to(RAW_TRACE_ROOT)
|
|
except ValueError as exc:
|
|
raise ValueError(
|
|
"轨迹不在默认数据树中,请同时提供 --score-output 和 --output"
|
|
) from exc
|
|
identity = relative.parent / compile_type
|
|
return FINAL_SCORE_ROOT / identity, COMPILED_SKILL_ROOT / identity
|