Coverage for src \ truenex_memory \ adapters \ __init__.py: 38%

21 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-05-19 10:21 +0200

1"""Agent instruction file generators.""" 

2 

3from __future__ import annotations 

4 

5from pathlib import Path 

6 

7AGENTS_FILENAME = "AGENTS.md" 

8CLAUDE_FILENAME = "CLAUDE.md" 

9 

10 

11def render_agents_md(project_name: str = "Truenex Memory") -> str: 

12 """Render an AGENTS.md file for local coding agents.""" 

13 

14 return f"""# {project_name} Agent Notes 

15 

16- Keep memory data local by default. 

17- Do not require cloud services for diagnostics, import, export, or local tools. 

18- Prefer small, testable changes and avoid unrelated rewrites. 

19- Run focused tests for touched surfaces before handing work back. 

20""" 

21 

22 

23def render_claude_md(project_name: str = "Truenex Memory") -> str: 

24 """Render a CLAUDE.md file for Claude-style coding agents.""" 

25 

26 return f"""# {project_name} 

27 

28Use this repository as a local-first memory layer for coding agents. 

29 

30## Working Rules 

31 

32- Keep generated memory artifacts in local files unless the user asks otherwise. 

33- Treat MCP tools as local callable helpers during development. 

34- Do not assume production cloud, licensing, or UI services are available. 

35""" 

36 

37 

38def write_agent_docs( 

39 directory: str | Path, 

40 *, 

41 project_name: str = "Truenex Memory", 

42 overwrite: bool = False, 

43) -> dict[str, Path]: 

44 """Write AGENTS.md and CLAUDE.md files into a directory.""" 

45 

46 target = Path(directory) 

47 target.mkdir(parents=True, exist_ok=True) 

48 files = { 

49 AGENTS_FILENAME: render_agents_md(project_name), 

50 CLAUDE_FILENAME: render_claude_md(project_name), 

51 } 

52 written: dict[str, Path] = {} 

53 for filename, content in files.items(): 

54 path = target / filename 

55 if path.exists() and not overwrite: 

56 raise FileExistsError(f"{path} already exists") 

57 path.write_text(content, encoding="utf-8") 

58 written[filename] = path 

59 return written 

60 

61 

62__all__ = [ 

63 "AGENTS_FILENAME", 

64 "CLAUDE_FILENAME", 

65 "render_agents_md", 

66 "render_claude_md", 

67 "write_agent_docs", 

68]