Coverage for .claude/hooks/moai/lib/context.py: 0.00%
13 statements
« prev ^ index » next coverage.py v7.11.3, created at 2025-11-19 08:00 +0900
« prev ^ index » next coverage.py v7.11.3, created at 2025-11-19 08:00 +0900
1#!/usr/bin/env python3
2"""Context Engineering utilities
4JIT (Just-in-Time) Retrieval
5"""
7from pathlib import Path
10def get_jit_context(prompt: str, cwd: str) -> list[str]:
11 """JIT Context Retrieval based on prompt.
13 Analyze user prompts and automatically recommend relevant documents.
14 Alfred commands and keyword-based pattern matching load only the documents you need.
16 Args:
17 prompt: Prompt for user input (case is irrelevant)
18 cwd: Project root directory path
20 Returns:
21 List of recommended document paths (relative paths).
22 If there is no matching pattern or file, an empty list []
24 Patterns:
25 - "/alfred:1-plan" → .claude/skills/moai-core-spec-metadata-extended/reference.md
26 - "/alfred:2-run" → .claude/skills/moai-core-dev-guide/reference.md
27 - "test" → tests/ (if directory exists)
29 Examples:
30 >>> get_jit_context("/alfred:1-plan", "/project")
31 ['.claude/skills/moai-core-spec-metadata-extended/reference.md']
32 >>> get_jit_context("implement test", "/project")
33 ['tests/']
34 >>> get_jit_context("unknown", "/project")
35 []
37 Notes:
38 - Context Engineering: Compliance with JIT Retrieval principles
39 - Minimize initial context burden by loading only necessary documents
40 - Return after checking whether file exists
42 TDD History:
43 - RED: 18 items scenario testing (command matching, keywords, empty results)
44 - GREEN: Pattern matching dictionary-based implementation
45 - REFACTOR: Expandable pattern structure, file existence validation added
46 """
47 context_files = []
48 cwd_path = Path(cwd)
50 # Pattern matching
51 patterns = {
52 "/alfred:1-plan": [".claude/skills/moai-core-spec-metadata-extended/reference.md"],
53 "/alfred:2-run": [".claude/skills/moai-core-dev-guide/reference.md"],
54 "test": ["tests/"],
55 }
57 for pattern, files in patterns.items():
58 if pattern in prompt.lower():
59 for file in files:
60 file_path = cwd_path / file
61 if file_path.exists():
62 context_files.append(file)
64 return context_files
67__all__ = ["get_jit_context"]