File size: 1,519 Bytes
026774a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# TSA Agent Knowledge Base
# Markdown documentation for RAG and agent context

"""
Knowledge base containing TSA documentation for agent context:

- tsa_algorithms.md: Core TSA algorithms (Z-curve, OIS, pooling)
- effect_models.md: Fixed vs random effects, measures
- alpha_spending.md: O'Brien-Fleming, Pocock spending functions
- tsa_file_format.md: Internal TSA file format and code reference
"""

from pathlib import Path

KNOWLEDGE_DIR = Path(__file__).parent

def get_knowledge_path(topic: str) -> Path:
    """Get path to a knowledge file by topic name."""
    topic_map = {
        "algorithms": "tsa_algorithms.md",
        "tsa_algorithms": "tsa_algorithms.md",
        "effect_models": "effect_models.md",
        "models": "effect_models.md",
        "alpha_spending": "alpha_spending.md",
        "spending": "alpha_spending.md",
        "boundaries": "alpha_spending.md",
        "file_format": "tsa_file_format.md",
        "tsa_file_format": "tsa_file_format.md",
        "codes": "tsa_file_format.md",
        "format": "tsa_file_format.md",
    }
    filename = topic_map.get(topic.lower(), f"{topic}.md")
    return KNOWLEDGE_DIR / filename


def load_knowledge(topic: str) -> str:
    """Load knowledge content by topic."""
    path = get_knowledge_path(topic)
    if path.exists():
        return path.read_text()
    return f"Knowledge topic '{topic}' not found."


def list_topics() -> list[str]:
    """List available knowledge topics."""
    return [p.stem for p in KNOWLEDGE_DIR.glob("*.md")]