Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
200 lines (163 loc) · 5.88 KB
/
Copy pathmain.py
File metadata and controls
200 lines (163 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
"""
DeepResearch CLI.
Commands:
main.py "your query" run new research
main.py --list show recent runs
main.py --list --all show all runs
main.py --show RUN_ID display a past report
main.py --search "keyword" find runs by query substring
main.py --reopen RUN_ID rerun synthesis on cached docs (no re-fetch)
main.py --retry RUN_ID resume a failed run from last checkpoint
main.py --auto-approve --top N skip approval UI, take top N
"""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
from rich.console import Console
from rich.table import Table
from rich.panel import Panel
from rich.markdown import Markdown
from src.storage import RunStore
from src.pipeline import run_pipeline, reopen_run, retry_run
console = Console()
def cmd_run(args) -> int:
if not args.query:
console.print("[red]Error: query is empty[/red]")
return 1
try:
run_pipeline(
args.query,
auto_approve=args.auto_approve,
auto_approve_top=args.top,
)
return 0
except KeyboardInterrupt:
console.print("\n[yellow]Interrupted[/yellow]")
return 130
except Exception:
return 1
def cmd_list(args) -> int:
store = RunStore()
limit = None if args.all else 20
runs = store.list_runs(limit=limit)
if not runs:
console.print("[dim]No runs yet. Try: uv run python main.py 'your query'[/dim]")
return 0
table = Table(show_header=True, header_style="bold magenta", show_lines=False)
table.add_column("Run ID", style="cyan", no_wrap=True)
table.add_column("Status", width=10)
table.add_column("Sources", justify="right", width=8)
table.add_column("Query", style="white", min_width=40)
for r in runs:
status_style = {
"completed": "green",
"running": "yellow",
"failed": "red",
}.get(r.status, "white")
sources_str = (
f"{r.sources_succeeded}/{r.sources_attempted}"
if r.sources_attempted else "-"
)
table.add_row(
r.run_id,
f"[{status_style}]{r.status}[/{status_style}]",
sources_str,
r.query[:80],
)
console.print(table)
console.print(f"\n[dim]Showing {len(runs)} runs[/dim]")
return 0
def cmd_show(args) -> int:
report_path = Path(f"data/runs/{args.run_id}/report.md")
if not report_path.exists():
console.print(f"[red]No report found at {report_path}[/red]")
console.print(f"[dim]Check: ls data/runs/{args.run_id}/[/dim]")
return 1
content = report_path.read_text(encoding="utf-8")
console.print(Panel(
f"[bold]Run:[/bold] {args.run_id}",
border_style="cyan",
))
console.print(Markdown(content))
return 0
def cmd_search(args) -> int:
store = RunStore()
matches = store.search_runs(args.keyword)
if not matches:
console.print(f"[dim]No runs matching '{args.keyword}'[/dim]")
return 0
console.print(f"[bold]{len(matches)} matches for '{args.keyword}':[/bold]\n")
for r in matches[:20]:
console.print(f" [cyan]{r.run_id}[/cyan] {r.query[:80]}")
if len(matches) > 20:
console.print(f"\n[dim]({len(matches) - 20} more not shown)[/dim]")
return 0
def cmd_reopen(args) -> int:
try:
reopen_run(args.run_id)
return 0
except FileNotFoundError as e:
console.print(f"[red]{e}[/red]")
return 1
except Exception as e:
console.print(f"[red]{type(e).__name__}: {e}[/red]")
return 1
def cmd_retry(args) -> int:
try:
retry_run(args.run_id)
return 0
except FileNotFoundError as e:
console.print(f"[red]{e}[/red]")
return 1
except Exception as e:
console.print(f"[red]{type(e).__name__}: {e}[/red]")
return 1
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="DeepResearch -- local-first AI research tool",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
%(prog)s "what are indian saas founders saying about CRMs"
%(prog)s --list
%(prog)s --show 2026-05-06-1430-indian-saas
%(prog)s --search "saas"
%(prog)s --reopen 2026-05-06-1430-indian-saas
%(prog)s --auto-approve --top 10 "your query"
""",
)
parser.add_argument("query", nargs="?", help="Research question (run new pipeline)")
parser.add_argument("--list", action="store_true", help="List recent runs")
parser.add_argument("--all", action="store_true", help="With --list: show all runs")
parser.add_argument("--show", metavar="RUN_ID", help="Display a past report")
parser.add_argument("--search", metavar="KEYWORD", help="Find runs by query substring")
parser.add_argument("--reopen", metavar="RUN_ID", help="Rerun synthesis on cached docs")
parser.add_argument("--retry", metavar="RUN_ID", help="Resume a failed run from its last checkpoint")
parser.add_argument("--auto-approve", action="store_true", help="Skip approval UI")
parser.add_argument("--top", type=int, default=None, metavar="N",
help="With --auto-approve: take top N candidates (default 10)")
return parser
def main() -> int:
parser = build_parser()
args = parser.parse_args()
if args.list:
return cmd_list(args)
if args.show:
args.run_id = args.show
return cmd_show(args)
if args.search:
args.keyword = args.search
return cmd_search(args)
if args.reopen:
args.run_id = args.reopen
return cmd_reopen(args)
if args.retry:
args.run_id = args.retry
return cmd_retry(args)
if args.query:
return cmd_run(args)
parser.print_help()
return 0
if __name__ == "__main__":
sys.exit(main())