@@ -1256,6 +1256,8 @@ def _interactive_shell(opts: argparse.Namespace, config: "Config", cache) -> Non
12561256 total_tokens = 0
12571257 session_start = _time .time ()
12581258 researches_done = 0
1259+ last_report : str | None = None # Keep last report for /graph, /polish
1260+ last_report_file : str | None = None # Path to last saved report
12591261
12601262 # Menu items shown above the prompt
12611263 _MENU = [
@@ -1431,7 +1433,11 @@ def _interactive_shell(opts: argparse.Namespace, config: "Config", cache) -> Non
14311433 if cmd_lower .startswith ("/polish" ):
14321434 parts = user_input .split (maxsplit = 1 )
14331435 if len (parts ) < 2 :
1434- console .print ("[dim]Usage: /polish <file.md>[/dim]" )
1436+ # Use last report if available
1437+ if last_report :
1438+ _run_polish_inline (last_report )
1439+ else :
1440+ console .print ("[dim]Usage: /polish <file.md> (or run a research first)[/dim]" )
14351441 continue
14361442 filepath = parts [1 ].strip ()
14371443 try :
@@ -1445,7 +1451,10 @@ def _interactive_shell(opts: argparse.Namespace, config: "Config", cache) -> Non
14451451 if cmd_lower .startswith ("/graph" ):
14461452 parts = user_input .split (maxsplit = 1 )
14471453 if len (parts ) < 2 :
1448- console .print ("[dim]Usage: /graph <file.md>[/dim]" )
1454+ if last_report :
1455+ _run_graph_inline (last_report )
1456+ else :
1457+ console .print ("[dim]Usage: /graph <file.md> (or run a research first)[/dim]" )
14491458 continue
14501459 filepath = parts [1 ].strip ()
14511460 try :
@@ -1456,6 +1465,16 @@ def _interactive_shell(opts: argparse.Namespace, config: "Config", cache) -> Non
14561465 _run_graph_inline (text )
14571466 continue
14581467
1468+ if cmd_lower in ("/last" ,):
1469+ if last_report :
1470+ from .report import print_report
1471+ print_report (last_report )
1472+ if last_report_file :
1473+ console .print (f" [dim]📄 File: { last_report_file } [/dim]" )
1474+ else :
1475+ console .print ("[dim]No research done yet.[/dim]" )
1476+ continue
1477+
14591478 if user_input .startswith ("/" ):
14601479 console .print (f"[yellow]Unknown command: { user_input .split ()[0 ]} [/yellow]" )
14611480 console .print ("[dim]Type /help for available commands[/dim]" )
@@ -1539,21 +1558,37 @@ def _interactive_shell(opts: argparse.Namespace, config: "Config", cache) -> Non
15391558 continue
15401559
15411560 researches_done += 1
1561+ last_report = report
15421562
15431563 # Track tokens from this research
15441564 tracker = getattr (researcher , "last_token_tracker" , None )
15451565 if tracker :
15461566 total_tokens += tracker .total_tokens
15471567
1568+ # Auto-save report to file
1569+ import re as _re
1570+ slug = _re .sub (r'[^\w\s-]' , '' , topic ).strip ()[:50 ]
1571+ slug = _re .sub (r'[\s]+' , '_' , slug ).lower ()
1572+ timestamp = _time .strftime ("%Y%m%d_%H%M%S" )
1573+ reports_dir = os .path .expanduser ("~/.deepworm/reports" )
1574+ os .makedirs (reports_dir , exist_ok = True )
1575+ auto_path = os .path .join (reports_dir , f"{ slug } _{ timestamp } .md" )
1576+ with open (auto_path , "w" , encoding = "utf-8" ) as _f :
1577+ _f .write (report )
1578+ last_report_file = auto_path
1579+
15481580 # Output report
15491581 if output_file :
15501582 from .report import save_report
15511583 path = save_report (report , output_file , topic = topic )
1552- console .print (f"[green]Report saved to { path } [/green]" )
1584+ console .print (f"[green]✓ Report saved to { path } [/green]" )
15531585 else :
15541586 from .report import print_report
15551587 print_report (report )
15561588
1589+ console .print (f" [dim]📄 Auto-saved: { auto_path } [/dim]" )
1590+ console .print (f" [dim]💡 Use /graph or /polish on this report, or /last to view it[/dim]" )
1591+
15571592 # Polish if requested
15581593 if do_polish :
15591594 _run_polish_inline (report )
0 commit comments