sourcesweep 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ """SourceSweep: cited competitive landscape scans for biotech.
2
+
3
+ Copyright (C) 2026 Tegan Anderes / Anderes Lab Solutions.
4
+ Licensed under the GNU Affero General Public License v3.0 only (AGPL-3.0-only); see LICENSE and NOTICE.
5
+ """
6
+ from .scanner import __version__
7
+
8
+ __all__ = ["__version__"]
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ main()
sourcesweep/cli.py ADDED
@@ -0,0 +1,51 @@
1
+ """Command line: `sourcesweep <command>`.
2
+
3
+ sourcesweep run profiles/claudin-18-2 [--days 60] [--no-ai] [--no-track]
4
+ sourcesweep due [--profiles profiles] # run every profile whose cadence is up
5
+ sourcesweep check | scan | show | render # the low-level steps the Claude skill uses
6
+ """
7
+ import argparse
8
+ import sys
9
+ from datetime import date
10
+ from pathlib import Path
11
+
12
+ from . import pipeline, scanner
13
+
14
+
15
+ def _run_profile(path, days, use_ai, track, abstracts):
16
+ cfg, folder = pipeline.load_profile(path)
17
+ out = folder / "reports" / date.today().isoformat()
18
+ s = pipeline.run(cfg, out, days=days, use_ai=use_ai, history_dir=folder / "history" if track else None,
19
+ progress=lambda m: print(m, file=sys.stderr), abstracts=abstracts)
20
+ print(f"{cfg['name']}: {s['total']} sources, {s['direct']} directly relevant, {s['context']} context -> {out / 'report.html'}")
21
+ return s
22
+
23
+
24
+ def main(argv=None):
25
+ argv = list(sys.argv[1:] if argv is None else argv)
26
+ if not argv or argv[0] not in ("run", "due"):
27
+ return scanner.main(argv)
28
+ ap = argparse.ArgumentParser(prog="sourcesweep")
29
+ sub = ap.add_subparsers(dest="cmd", required=True)
30
+ r = sub.add_parser("run", help="scan, screen, track changes and render one profile")
31
+ r.add_argument("profile", help="profile folder (with profile.json) or a profile JSON file")
32
+ r.add_argument("--days", type=int)
33
+ d = sub.add_parser("due", help="run every profile whose cadence_days have passed")
34
+ d.add_argument("--profiles", default="profiles")
35
+ for p in (r, d):
36
+ p.add_argument("--no-ai", action="store_true", help="keyword scores only, no Anthropic API calls")
37
+ p.add_argument("--no-track", action="store_true", help="don't compare with or update the profile's history")
38
+ p.add_argument("--no-abstracts", action="store_true", help="leave publisher abstracts out of report.html")
39
+ a = ap.parse_args(argv)
40
+ if a.cmd == "run":
41
+ _run_profile(a.profile, a.days, not a.no_ai, not a.no_track, not a.no_abstracts)
42
+ return
43
+ todo = pipeline.due(a.profiles)
44
+ if not todo:
45
+ print("No profiles are due.")
46
+ for folder in todo:
47
+ _run_profile(folder, None, not a.no_ai, not a.no_track, not a.no_abstracts)
48
+
49
+
50
+ if __name__ == "__main__":
51
+ main()
@@ -0,0 +1,65 @@
1
+ """One unattended run: scan, screen, compare with the last run, write the briefing, render the report."""
2
+ import json
3
+ from datetime import date
4
+ from pathlib import Path
5
+
6
+ from . import scanner, screen, track
7
+
8
+
9
+ def load_profile(path):
10
+ """A profile is a folder with profile.json, or the JSON file itself."""
11
+ path = Path(path)
12
+ f = path / "profile.json" if path.is_dir() else path
13
+ cfg = json.loads(f.read_text())
14
+ cfg["keywords"] = scanner.normalize_keywords(cfg)
15
+ cfg.setdefault("slug", f.parent.name if f.name == "profile.json" else f.stem)
16
+ cfg.setdefault("name", cfg["slug"])
17
+ return cfg, f.parent
18
+
19
+
20
+ def run(cfg, out, days=None, use_ai=True, history_dir=None, progress=print, hub="", abstracts=True):
21
+ """Run everything and return a summary. `history_dir` turns on change tracking."""
22
+ days = int(days or cfg.get("days") or 60)
23
+ out = Path(out)
24
+ progress(f"Searching sources for {len(cfg['keywords'])} keywords over {days} days")
25
+ summary = scanner.scan(cfg, days, out, log=progress)
26
+ data = json.loads((out / "sources.json").read_text())
27
+ items = data["items"]
28
+
29
+ usage = screen.Usage()
30
+ scr = screen.screen(cfg, items, usage, progress=progress, use_ai=use_ai)
31
+ (out / "screening.json").write_text(json.dumps({k: {"rel": v["rel"], "note": v["note"]} for k, v in scr.items()}, indent=1))
32
+
33
+ changes_md, change_summary = "", None
34
+ if history_dir:
35
+ changes_md, change_summary = track.compare(items, history_dir, date.today().isoformat())
36
+
37
+ story = ""
38
+ if use_ai and screen.available():
39
+ progress("Writing the briefing")
40
+ story = screen.narrative(cfg, items, scr, usage, data["window"], changes_md)
41
+ (out / "briefing.md").write_text(screen.briefing(cfg, items, scr, data["status"], data["window"], story, changes_md))
42
+ scanner.render(out, hub=hub, title=f"{cfg.get('name')} scan {date.today().isoformat()}", abstracts=abstracts)
43
+
44
+ summary.update(direct=sum(1 for v in scr.values() if v["rel"] == 3),
45
+ context=sum(1 for v in scr.values() if v["rel"] == 2),
46
+ ai=usage.as_dict() if usage.calls else None, changes=change_summary,
47
+ ran_at=data.get("generated_at"))
48
+ (out / "run.json").write_text(json.dumps(summary, indent=1))
49
+ return summary
50
+
51
+
52
+ def due(profiles_root, today=None):
53
+ """Profiles whose cadence_days have passed since their last saved report."""
54
+ today = today or date.today()
55
+ out = []
56
+ for f in sorted(Path(profiles_root).glob("*/profile.json")):
57
+ cfg = json.loads(f.read_text())
58
+ cadence = cfg.get("cadence_days")
59
+ if not cadence:
60
+ continue
61
+ runs = sorted(d.name for d in (f.parent / "reports").glob("*") if d.is_dir())
62
+ last = date.fromisoformat(runs[-1][:10]) if runs else None
63
+ if last is None or (today - last).days >= int(cadence):
64
+ out.append(f.parent)
65
+ return out