11import json
2- import re
32from datetime import datetime , timezone
43from pathlib import Path
5- from typing import Any , TYPE_CHECKING
64
75import click
86
2422)
2523
2624
27-
2825@click .group ()
2926def cli () -> None :
3027 """Compendium Scribe: AI Research & Rendering Tool."""
@@ -124,17 +121,22 @@ def handle_progress(update: ResearchProgress) -> None:
124121 click .echo ("\n Hard shutdown requested." , err = True )
125122 raise SystemExit (1 )
126123 except ResearchTimeoutError as exc :
124+ compendium_title = getattr (exc , "compendium_title" , None )
127125 timeout_data = {
128126 "research_id" : exc .research_id ,
129127 "topic" : topic ,
128+ "title" : compendium_title or topic ,
130129 "no_background" : no_background ,
131130 "formats" : list (formats ),
132131 "max_tool_calls" : max_tool_calls ,
133132 "timestamp" : datetime .now (timezone .utc ).isoformat (),
134133 }
135134 Path ("timed_out_research.json" ).write_text (json .dumps (timeout_data , indent = 2 ))
136135 click .echo (f"\n [!] Deep research timed out (ID: { exc .research_id } )." , err = True )
137- click .echo (f"Stored recovery information in timed_out_research.json" , err = True )
136+ click .echo (
137+ "Stored recovery information in timed_out_research.json" ,
138+ err = True ,
139+ )
138140 raise SystemExit (1 ) from exc
139141 except MissingAPIKeyError as exc :
140142 click .echo (f"Configuration error: { exc } " , err = True )
@@ -154,7 +156,8 @@ def handle_progress(update: ResearchProgress) -> None:
154156 # If output_path has a suffix, we use it as the stem to avoid out.md.md
155157 base_path = output_path .parent / output_path .stem
156158 else :
157- slug = slugify (topic )
159+ name_for_slug = compendium .topic or topic
160+ slug = slugify (name_for_slug )
158161 timestamp = datetime .now (timezone .utc ).strftime ("%Y%m%d_%H%M%S" )
159162 base_path = Path (f"{ slug } _{ timestamp } " )
160163
@@ -226,14 +229,15 @@ def recover(input_file: Path):
226229 data = json .loads (input_file .read_text (encoding = "utf-8" ))
227230 research_id = data ["research_id" ]
228231 topic = data ["topic" ]
232+ title = data .get ("title" ) or topic
229233 formats = tuple (data ["formats" ])
230234 max_tool_calls = data .get ("max_tool_calls" )
231235 no_background = data .get ("no_background" , False )
232236 except (json .JSONDecodeError , KeyError ) as exc :
233237 click .echo (f"Error: Failed to parse recovery file: { exc } " , err = True )
234238 raise SystemExit (1 )
235239
236- click .echo (f"Checking status for research ID: { research_id } ('{ topic } ')..." )
240+ click .echo (f"Checking status for research ID: { research_id } ('{ title } ')..." )
237241
238242 config = ResearchConfig (
239243 background = not no_background ,
@@ -243,13 +247,13 @@ def recover(input_file: Path):
243247 try :
244248 compendium = recover_compendium (
245249 research_id = research_id ,
246- topic = topic ,
250+ topic = title ,
247251 config = config ,
248252 )
249253
250254 click .echo ("Research completed! Writing outputs." )
251255
252- slug = slugify (topic )
256+ slug = slugify (title )
253257 timestamp = datetime .now (timezone .utc ).strftime ("%Y%m%d_%H%M%S" )
254258 base_path = Path (f"{ slug } _{ timestamp } " )
255259
0 commit comments