File size: 2,744 Bytes
93be2a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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,
    )