|
34 | 34 | import sys |
35 | 35 | from typing import Any |
36 | 36 |
|
37 | | -from git_notes_memory.config import HOOK_SESSION_START_TIMEOUT |
| 37 | +from git_notes_memory.config import HOOK_SESSION_START_TIMEOUT, get_index_path |
38 | 38 | from git_notes_memory.hooks.config_loader import load_hook_config |
39 | 39 | from git_notes_memory.hooks.context_builder import ContextBuilder |
40 | 40 | from git_notes_memory.hooks.guidance_builder import GuidanceBuilder |
41 | 41 | from git_notes_memory.hooks.project_detector import detect_project |
| 42 | +from git_notes_memory.index import IndexService |
42 | 43 |
|
43 | 44 | __all__ = ["main"] |
44 | 45 |
|
@@ -117,18 +118,43 @@ def _validate_input(data: dict[str, Any]) -> bool: |
117 | 118 | return all(field in data and data[field] for field in required_fields) |
118 | 119 |
|
119 | 120 |
|
120 | | -def _write_output(context: str) -> None: |
| 121 | +def _get_memory_count() -> int: |
| 122 | + """Get total memory count from index. |
| 123 | +
|
| 124 | + Returns: |
| 125 | + Number of memories indexed, or 0 if index doesn't exist. |
| 126 | + """ |
| 127 | + try: |
| 128 | + index_path = get_index_path() |
| 129 | + if not index_path.exists(): |
| 130 | + return 0 |
| 131 | + index = IndexService(index_path) |
| 132 | + index.initialize() |
| 133 | + stats = index.get_stats() |
| 134 | + index.close() |
| 135 | + return stats.total_memories |
| 136 | + except Exception: |
| 137 | + return 0 |
| 138 | + |
| 139 | + |
| 140 | +def _write_output(context: str, memory_count: int = 0) -> None: |
121 | 141 | """Write hook output to stdout. |
122 | 142 |
|
123 | 143 | Args: |
124 | 144 | context: XML context string to inject. |
| 145 | + memory_count: Number of memories in the system. |
125 | 146 | """ |
126 | | - output = { |
| 147 | + output: dict[str, Any] = { |
127 | 148 | "hookSpecificOutput": { |
128 | 149 | "hookEventName": "SessionStart", |
129 | 150 | "additionalContext": context, |
130 | 151 | } |
131 | 152 | } |
| 153 | + # Add user-visible status message |
| 154 | + if memory_count > 0: |
| 155 | + output["message"] = f"📚 Memory system: {memory_count} memories indexed" |
| 156 | + else: |
| 157 | + output["message"] = "📚 Memory system: initialized" |
132 | 158 | print(json.dumps(output)) |
133 | 159 |
|
134 | 160 |
|
@@ -214,8 +240,11 @@ def main() -> None: |
214 | 240 |
|
215 | 241 | logger.debug("Total context (%d chars)", len(full_context)) |
216 | 242 |
|
217 | | - # Output result |
218 | | - _write_output(full_context) |
| 243 | + # Get memory count for status message |
| 244 | + memory_count = _get_memory_count() |
| 245 | + |
| 246 | + # Output result with memory count |
| 247 | + _write_output(full_context, memory_count=memory_count) |
219 | 248 |
|
220 | 249 | except json.JSONDecodeError as e: |
221 | 250 | logger.error("Failed to parse hook input: %s", e) |
|
0 commit comments