import glob import json import os import re ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) LOG_PATH = os.path.join(ROOT, "docs", "progress-log.md") README_PATH = os.path.join(ROOT, "README.md") ADR_DIR = os.path.join(ROOT, "docs", "adr") def latest_progress_entry(): try: with open(LOG_PATH, encoding="utf-8") as f: text = f.read() except FileNotFoundError: return "" for part in re.split(r"^---$", text, flags=re.MULTILINE): if re.search(r"^## ", part, re.MULTILINE): return part.strip() return "" def readme_text(): try: with open(README_PATH, encoding="utf-8") as f: return f.read().strip() except FileNotFoundError: return "" def adr_index(): lines = [] for path in sorted(glob.glob(os.path.join(ADR_DIR, "*.md"))): try: with open(path, encoding="utf-8") as f: first_line = f.readline().strip() except OSError: continue title = re.sub(r"^#\s*", "", first_line) lines.append(f"- `docs/adr/{os.path.basename(path)}`: {title}") return "\n".join(lines) sections = [ "Project: Duoc Thu RAG medical chatbot (D:\\VSF-DUOCTHU). " "This is an automated orientation summary, not the full picture — read " "the referenced files (README.md, docs/architecture.md, the specific " "ADR, CLAUDE.md) before making claims about scope, architecture, or " "what already exists." ] readme = readme_text() if readme: sections.append("## README.md\n\n" + readme) adrs = adr_index() if adrs: sections.append( "## Architecture decision records (docs/adr/) — titles only, " "read the full ADR before relying on its rationale/consequences:\n\n" + adrs ) progress = latest_progress_entry() if progress: sections.append("## Latest entry from docs/progress-log.md\n\n" + progress) if len(sections) > 1: print(json.dumps({ "hookSpecificOutput": { "hookEventName": "SessionStart", "additionalContext": "\n\n".join(sections), } }))