from __future__ import annotations

from pathlib import Path

from src.tools import run_tool_pipeline

ROOT = Path(__file__).resolve().parent.parent
ARTIFACTS = ROOT / "artifacts"
ARTIFACTS.mkdir(exist_ok=True)


def plan_task(message: str) -> str:
    return f"# Plan\n- request: {message}\n- stack: deepagents\n- profile: langfuse_trace_analysis\n- mode: hybrid"


def run(message: str) -> str:
    plan = plan_task(message)
    (ARTIFACTS / "request.md").write_text(plan, encoding="utf-8")
    result = run_tool_pipeline(message)
    final = f"# Final Output\n{result}"
    (ARTIFACTS / "final.md").write_text(final, encoding="utf-8")
    return final
