from __future__ import annotations import json from datetime import datetime from pathlib import Path from typing import Any, Dict, List from .registry import ToolRegistry def t_report_write(args: Dict[str, Any]) -> str: """Write a Markdown report. Args: title, sections (list[{heading, body}]), out_path """ title = args.get("title", "Report") sections: List[Dict[str, Any]] = args.get("sections") or [] out_path = Path(str(args.get("out_path", f"/data/adaptai/projects/elizabeth/reports/{datetime.utcnow().strftime('%Y%m%dT%H%M%SZ')}_report.md"))) out_path.parent.mkdir(parents=True, exist_ok=True) lines = [f"# {title}", "", f"Generated: {datetime.utcnow().isoformat()}Z", ""] for sec in sections: h = sec.get("heading") or "Section" b = sec.get("body") or "" lines += [f"## {h}", "", str(b), ""] out_path.write_text("\n".join(lines), encoding="utf-8") return json.dumps({"path": str(out_path), "sections": len(sections)}) def t_plan_write(args: Dict[str, Any]) -> str: """Write a structured execution plan in Markdown. Args: objective, steps (list[str]), risks (list[str]), out_path """ objective = args.get("objective", "") steps: List[str] = args.get("steps") or [] risks: List[str] = args.get("risks") or [] out_path = Path(str(args.get("out_path", f"/data/adaptai/projects/elizabeth/plans/{datetime.utcnow().strftime('%Y%m%dT%H%M%SZ')}_plan.md"))) out_path.parent.mkdir(parents=True, exist_ok=True) lines = ["# Execution Plan", "", f"Generated: {datetime.utcnow().isoformat()}Z",""] if objective: lines += ["## Objective", "", objective, ""] if steps: lines += ["## Steps", ""] + [f"- {s}" for s in steps] + [""] if risks: lines += ["## Risks", ""] + [f"- {r}" for r in risks] + [""] out_path.write_text("\n".join(lines), encoding="utf-8") return json.dumps({"path": str(out_path), "steps": len(steps), "risks": len(risks)}) def register_tools(reg: ToolRegistry) -> None: reg.register( name="report_write", description="Write a Markdown report with sections.", parameters={"type": "object", "properties": {"title": {"type": "string"}, "sections": {"type": "array", "items": {"type": "object"}}, "out_path": {"type": "string"}}}, handler=t_report_write, ) reg.register( name="plan_write", description="Write a structured execution plan (Markdown).", parameters={"type": "object", "properties": {"objective": {"type": "string"}, "steps": {"type": "array", "items": {"type": "string"}}, "risks": {"type": "array", "items": {"type": "string"}}, "out_path": {"type": "string"}}}, handler=t_plan_write, )