Load requested specs documents and return their content. Returns: str: Markdown string (default) or JSON string mapping spec to content.
(
self,
spec_map: Dict[str, Tuple[str, str]],
specs: List[str],
format: str = 'markdown',
include_titles: bool = False,
join_with: str = '\n\n---\n\n',
strict: bool = False,
)
| 222 | return await self.load_specs(principle_map, principles, **kwargs) |
| 223 | |
| 224 | async def load_specs( |
| 225 | self, |
| 226 | spec_map: Dict[str, Tuple[str, str]], |
| 227 | specs: List[str], |
| 228 | format: str = 'markdown', |
| 229 | include_titles: bool = False, |
| 230 | join_with: str = '\n\n---\n\n', |
| 231 | strict: bool = False, |
| 232 | ) -> str: |
| 233 | """Load requested specs documents and return their content. |
| 234 | |
| 235 | Returns: |
| 236 | str: Markdown string (default) or JSON string mapping spec to content. |
| 237 | """ |
| 238 | |
| 239 | if not specs: |
| 240 | return json.dumps( |
| 241 | { |
| 242 | 'success': False, |
| 243 | 'error': 'No specs provided.' |
| 244 | }, |
| 245 | ensure_ascii=False, |
| 246 | indent=2, |
| 247 | ) |
| 248 | |
| 249 | resolved: Dict[str, Tuple[str, str]] = {} |
| 250 | unknown: List[str] = [] |
| 251 | for name in specs: |
| 252 | key = self._normalize_name(name) |
| 253 | if key in spec_map: |
| 254 | resolved[name] = spec_map[key] |
| 255 | else: |
| 256 | unknown.append(name) |
| 257 | |
| 258 | if unknown and strict: |
| 259 | return json.dumps( |
| 260 | { |
| 261 | 'success': False, |
| 262 | 'error': |
| 263 | 'Unknown specs (strict mode): ' + ', '.join(unknown), |
| 264 | }, |
| 265 | ensure_ascii=False, |
| 266 | indent=2, |
| 267 | ) |
| 268 | |
| 269 | loaded: Dict[str, str] = {} |
| 270 | for _, (filename, canonical_title) in resolved.items(): |
| 271 | path = os.path.join(self.spec_dir, filename) |
| 272 | try: |
| 273 | with open(path, 'r') as f: |
| 274 | content = f.read().strip() |
| 275 | loaded[canonical_title] = content |
| 276 | except Exception as e: # noqa |
| 277 | loaded[ |
| 278 | canonical_title] = f'Failed to load {filename}: {str(e)}' |
| 279 | |
| 280 | if not loaded: |
| 281 | return json.dumps( |
no test coverage detected