hitherto 0.1.0__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.

Potentially problematic release.


This version of hitherto might be problematic. Click here for more details.

Files changed (72) hide show
  1. casefile/__init__.py +3 -0
  2. casefile/_data/profiles/_template.yaml +61 -0
  3. casefile/_data/profiles/apertus.yaml +74 -0
  4. casefile/_data/profiles/numpy.yaml +60 -0
  5. casefile/_data/profiles/pytorch.yaml +96 -0
  6. casefile/_data/profiles/sklearn.yaml +58 -0
  7. casefile/_data/sample_cases.yaml +85 -0
  8. casefile/cache/__init__.py +3 -0
  9. casefile/cache/github_search.py +49 -0
  10. casefile/cli.py +145 -0
  11. casefile/clients/__init__.py +30 -0
  12. casefile/clients/discourse_html.py +34 -0
  13. casefile/clients/github.py +312 -0
  14. casefile/clients/http.py +55 -0
  15. casefile/clients/huggingface.py +105 -0
  16. casefile/clients/llm.py +180 -0
  17. casefile/config.py +54 -0
  18. casefile/engine/__init__.py +0 -0
  19. casefile/engine/citation_checker.py +99 -0
  20. casefile/engine/orchestrator.py +353 -0
  21. casefile/engine/planner.py +265 -0
  22. casefile/engine/synthesizer.py +164 -0
  23. casefile/engine/validator.py +134 -0
  24. casefile/eval/__init__.py +5 -0
  25. casefile/eval/sample_cases.py +69 -0
  26. casefile/index/__init__.py +0 -0
  27. casefile/models/__init__.py +15 -0
  28. casefile/models/assessment.py +38 -0
  29. casefile/models/evidence.py +53 -0
  30. casefile/models/profile.py +140 -0
  31. casefile/predict/__init__.py +47 -0
  32. casefile/predict/agreement.py +161 -0
  33. casefile/predict/assignment_score.py +340 -0
  34. casefile/predict/extract_run.py +597 -0
  35. casefile/predict/extractor.py +368 -0
  36. casefile/predict/features.py +75 -0
  37. casefile/predict/labels.py +261 -0
  38. casefile/predict/person_period.py +153 -0
  39. casefile/predict/quadrant.py +226 -0
  40. casefile/predict/scorer.py +122 -0
  41. casefile/predict/time.py +51 -0
  42. casefile/predict/topic_hazard.py +336 -0
  43. casefile/predict/topic_history.py +444 -0
  44. casefile/profiles/__init__.py +3 -0
  45. casefile/profiles/loader.py +39 -0
  46. casefile/render/__init__.py +0 -0
  47. casefile/render/markdown.py +229 -0
  48. casefile/retrievers/__init__.py +21 -0
  49. casefile/retrievers/adjacent.py +88 -0
  50. casefile/retrievers/base.py +43 -0
  51. casefile/retrievers/discourse.py +88 -0
  52. casefile/retrievers/git_activity.py +72 -0
  53. casefile/retrievers/github_issues.py +103 -0
  54. casefile/retrievers/github_prs.py +53 -0
  55. casefile/retrievers/huggingface_discussions.py +192 -0
  56. casefile/retrievers/process_docs.py +47 -0
  57. casefile/retrievers/repo_files.py +50 -0
  58. casefile/retrievers/vital_signs.py +276 -0
  59. casefile/web/__init__.py +1 -0
  60. casefile/web/app.py +230 -0
  61. casefile/web/jobs.py +59 -0
  62. casefile/web/static/app.css +21 -0
  63. casefile/web/templates/base.html +48 -0
  64. casefile/web/templates/health.html +19 -0
  65. casefile/web/templates/index.html +126 -0
  66. casefile/web/templates/result.html +110 -0
  67. casefile/web/templates/status.html +20 -0
  68. hitherto-0.1.0.dist-info/METADATA +143 -0
  69. hitherto-0.1.0.dist-info/RECORD +72 -0
  70. hitherto-0.1.0.dist-info/WHEEL +4 -0
  71. hitherto-0.1.0.dist-info/entry_points.txt +5 -0
  72. hitherto-0.1.0.dist-info/licenses/LICENSE +201 -0
casefile/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """Casefile — evidence-first OSS contribution assessment."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,61 @@
1
+ # Ecosystem profile template — copy to {name}.yaml and fill in.
2
+ # Schema: casefile/profiles/schema.yaml (TODO Phase 0.5)
3
+ # Loader refuses profiles where last_verified is older than max_age_days.
4
+
5
+ id: example
6
+ display_name: Example Project
7
+ version: 1
8
+
9
+ last_verified: 2026-01-01 # ISO date; curator updates after manual review
10
+ max_age_days: 90
11
+
12
+ # Default GitHub repos this profile enriches (primary repo can override via CLI)
13
+ default_repos:
14
+ - owner/example
15
+
16
+ # Query expansion — map user phrases to search terms
17
+ synonyms:
18
+ feature name: [alias one, alias two]
19
+
20
+ # Ranking boosts (optional) — matched against issue labels
21
+ label_boosts:
22
+ enhancement: 0.05
23
+
24
+ # Static adjacent projects — URLs must be valid; curator maintains
25
+ adjacent_projects:
26
+ - name: Related Library
27
+ url: https://github.com/org/repo
28
+ relevance: one sentence on why this matters for contribution decisions
29
+
30
+ # Extra files to fetch from target repo beyond README / CONTRIBUTING / CODEOWNERS
31
+ scope_files:
32
+ - docs/design/README.md
33
+
34
+ # External discussion and design sources
35
+ discourse:
36
+ base_url: https://discourse.example.com
37
+ search_path: /search?q=
38
+ # Optional curated threads (always fetched)
39
+ pinned_threads:
40
+ - url: https://discourse.example.com/t/example-rfc/123
41
+
42
+ rfc:
43
+ - label: RFC index
44
+ url: https://example.com/rfcs
45
+
46
+ # Cross-repo comparisons (Tier 2)
47
+ sibling_repos:
48
+ - jax-ml/jax
49
+
50
+ # Path hints when CLI omits --path but question mentions a module
51
+ path_hints: {}
52
+
53
+ # Always include in issue search (repo: qualifier added by planner)
54
+ pinned_issue_numbers: []
55
+
56
+ # e.g. label:"module: foo", FeatureName in:title
57
+ issue_search_queries: []
58
+
59
+ # Optional per-module paths (override pinned_issue_numbers when path matches)
60
+ path_pinned_issue_numbers: {}
61
+ path_issue_search_queries: {}
@@ -0,0 +1,74 @@
1
+ # Apertus / Swiss AI — second case study for Swiss Python Summit.
2
+ # Discussion lives on Hugging Face Hub model repos more than GitHub issues.
3
+ # Question to run: does swiss-ai/apertus-format still earn its place now that
4
+ # 1.5 ships native tool use and a thinking mode?
5
+
6
+ id: apertus
7
+ display_name: Apertus (Swiss AI)
8
+ version: 1
9
+
10
+ last_verified: 2026-08-23
11
+ max_age_days: 90
12
+
13
+ default_repos:
14
+ - swiss-ai/apertus-format
15
+
16
+ synonyms:
17
+ apertus format: [apertus-format, chat template, tool call parser]
18
+ thinking mode: [enable_thinking, reasoning-parser apertus]
19
+ tool use: [tool-call-parser apertus, native tool use]
20
+ apertus 1.5: [Apertus-v1.5-8B, Apertus-v1.5-70B, Apertus 1.5]
21
+
22
+ label_boosts: {}
23
+
24
+ adjacent_projects:
25
+ - name: Apertus-v1.5-8B
26
+ url: https://huggingface.co/swiss-ai/Apertus-v1.5-8B
27
+ relevance: Primary 1.5 weights; documents native tool use and optional thinking mode.
28
+ - name: Apertus-v1.5-70B
29
+ url: https://huggingface.co/swiss-ai/Apertus-v1.5-70B
30
+ relevance: Larger 1.5 sibling with the same post-training recipe.
31
+ - name: apertus-format (GitHub)
32
+ url: https://github.com/swiss-ai/apertus-format
33
+ relevance: Custom chat-format library — candidate for redundancy vs native 1.5 templates.
34
+ - name: Apertus 1.5 announcement
35
+ url: https://www.apertus-ai.org/articles/2026-07-apertus-1-5/
36
+ relevance: Official release notes for multimodal input, thinking mode, and tool use.
37
+
38
+ scope_files:
39
+ - README.md
40
+
41
+ huggingface:
42
+ hub_repos:
43
+ - repo_id: swiss-ai/Apertus-v1.5-8B
44
+ repo_type: model
45
+ - repo_id: swiss-ai/Apertus-8B-Instruct-2509
46
+ repo_type: model
47
+ max_discussions_per_repo: 30
48
+
49
+ rfc:
50
+ - label: Swiss AI GitHub org
51
+ url: https://github.com/swiss-ai
52
+
53
+ sibling_repos:
54
+ - swiss-ai/apertus-format
55
+
56
+ path_hints: {}
57
+
58
+ pinned_issue_numbers: []
59
+ issue_search_queries:
60
+ - apertus-format in:title
61
+ - chat template in:title
62
+ - tool in:title
63
+
64
+ path_pinned_issue_numbers: {}
65
+ path_issue_search_queries: {}
66
+
67
+ # Item→topic assignment for synonym cluster `apertus format`. Frozen rule:
68
+ # profile synonyms in title/lead plus an `apertus` anchor (or swiss-ai/apertus-format).
69
+ # Not fit on these labels. Wilson 95% on precision is wide (few predicted positives).
70
+ assignment_precision:
71
+ measured_at: 2026-08-28
72
+ n: 81
73
+ precision: 0.88
74
+ recall: 0.64
@@ -0,0 +1,60 @@
1
+ # NumPy ecosystem — masked arrays, NEPs, and core MA maintenance (data-science staple).
2
+ # Curator: update last_verified after checking links.
3
+ # Re-verified 2026-08-30: adjacent/NEP URLs 200; pins 22338/18675/15858 200;
4
+ # labels `component: numpy.ma` and `01 - Enhancement` still exist.
5
+
6
+ id: numpy
7
+ display_name: NumPy
8
+ version: 1
9
+
10
+ last_verified: 2026-08-30
11
+ max_age_days: 90
12
+
13
+ default_repos:
14
+ - numpy/numpy
15
+
16
+ synonyms:
17
+ masked array: [numpy.ma, np.ma, MaskedArray, masked arrays]
18
+ missing data: [NA, NEP-12, missing values]
19
+ array api: [NEP 18, Python Array API]
20
+
21
+ label_boosts:
22
+ "component: numpy.ma": 0.2
23
+ "01 - Enhancement": 0.05
24
+
25
+ adjacent_projects:
26
+ - name: pandas
27
+ url: https://pandas.pydata.org/docs/user_guide/missing_data.html
28
+ relevance: Primary missing-data UX for many data scientists; often preferred over np.ma for new code.
29
+ - name: xarray
30
+ url: https://docs.xarray.dev/
31
+ relevance: Labeled N-D arrays with NA semantics; common in geoscience / climate stacks.
32
+ - name: JAX
33
+ url: https://jax.readthedocs.io/
34
+ relevance: Alternative array stack with different autograd and masking patterns.
35
+
36
+ scope_files:
37
+ - doc/neps/nep-0012-missing-data.rst
38
+ - numpy/ma/README.rst
39
+
40
+ rfc:
41
+ - label: NEP 12 — missing data (historical)
42
+ url: https://github.com/numpy/numpy/blob/main/doc/neps/nep-0012-missing-data.rst
43
+ - label: NEP 50 — scalar promotion
44
+ url: https://numpy.org/neps/nep-0050-scalar-promotion.html
45
+
46
+ sibling_repos:
47
+ - pandas-dev/pandas
48
+ - pydata/xarray
49
+
50
+ path_hints:
51
+ ma: numpy/ma
52
+
53
+ pinned_issue_numbers:
54
+ - 22338
55
+ - 18675
56
+ - 15858
57
+
58
+ issue_search_queries:
59
+ - "component: numpy.ma"
60
+ - MaskedArray in:title
@@ -0,0 +1,96 @@
1
+ # PyTorch ecosystem profile — reference instance for torch.masked assessments.
2
+ # Curator: update last_verified after checking links and label taxonomy.
3
+ # Re-verified 2026-08-30: adjacent/discourse/RFC URLs 200; golden issues 200.
4
+ # GitHub renamed the labels this profile was written against: `module: masked`
5
+ # → `module: masked operators`, `triaged review` → `triage review`, and
6
+ # `prototype` is gone (search total_count 0). Talk week still needs a pass —
7
+ # 22 October is 53 days after this stamp.
8
+
9
+ id: pytorch
10
+ display_name: PyTorch
11
+ version: 1
12
+
13
+ last_verified: 2026-08-30
14
+ max_age_days: 90
15
+
16
+ default_repos:
17
+ - pytorch/pytorch
18
+
19
+ synonyms:
20
+ masked tensor: [MaskedTensor, torch.masked, maskedtensor]
21
+ masked array: [MaskedTensor]
22
+ ragged tensor: [NestedTensor, nested tensor, torch.nested]
23
+ sparse attention mask: [FlexAttention, flex attention, scaled_dot_product_attention]
24
+
25
+ label_boosts:
26
+ "module: masked operators": 0.25
27
+ "triage review": 0.05
28
+
29
+ adjacent_projects:
30
+ - name: NestedTensor
31
+ url: https://pytorch.org/docs/stable/nested.html
32
+ relevance: Core team's structured approach to ragged/masked batch data; often preferred over MaskedTensor for sequence models.
33
+ - name: FlexAttention
34
+ url: https://pytorch.org/blog/flexattention/
35
+ relevance: Masked attention patterns without a dedicated MaskedTensor type in hot paths.
36
+ - name: torch.nested
37
+ url: https://github.com/pytorch/pytorch/tree/main/torch/nested
38
+ relevance: Active investment area adjacent to masked/ragged use cases.
39
+
40
+ scope_files:
41
+ - docs/source/masked.md
42
+ - torch/masked/__init__.py
43
+
44
+ discourse:
45
+ base_url: https://dev-discuss.pytorch.org
46
+ search_path: /search?q=
47
+ # Curated threads (MaskedTensor / tensor subclasses / maintainer context)
48
+ pinned_threads:
49
+ - https://dev-discuss.pytorch.org/t/state-of-pytorch-core-september-2021-edition/332
50
+ - https://dev-discuss.pytorch.org/t/what-and-why-is-torch-dispatch/557
51
+ - https://dev-discuss.pytorch.org/t/torch-nn-h2-2021-lookback-and-h1-2022-lookahead/477
52
+
53
+ rfc:
54
+ - label: PyTorch RFC repo
55
+ url: https://github.com/pytorch/rfcs
56
+
57
+ sibling_repos:
58
+ - jax-ml/jax
59
+ - numpy/numpy
60
+
61
+ # Path hints when CLI omits --path but question mentions a module
62
+ path_hints:
63
+ masked: torch/masked
64
+ nested: torch/nested
65
+
66
+ # Default golden issues (torch.masked); overridden per path when path_pinned_issue_numbers matches
67
+ pinned_issue_numbers:
68
+ - 89734
69
+ - 89320
70
+ - 124964
71
+
72
+ issue_search_queries:
73
+ - 'label:"module: masked operators"'
74
+ - MaskedTensor in:title
75
+
76
+ path_pinned_issue_numbers:
77
+ torch/nested:
78
+ - 112398
79
+ - 82534
80
+ - 118580
81
+
82
+ path_issue_search_queries:
83
+ torch/nested:
84
+ - NestedTensor in:title
85
+ - jagged in:title
86
+ torch/masked:
87
+ - 'label:"module: masked operators"'
88
+
89
+ # Disjoint holdout 2026-08-28 (eval/topic_assignment/pytorch_holdout.yaml).
90
+ # The n=88 / 1.00 numbers were in-sample on the set the vetoes were tuned on.
91
+ # Recall is omitted: adjacent titles were drawn from queries the assigner
92
+ # already rejects, so 1.00 would pass the recall floor without measuring it.
93
+ assignment_precision:
94
+ measured_at: 2026-08-28
95
+ n: 95
96
+ precision: 0.91
@@ -0,0 +1,58 @@
1
+ # scikit-learn ecosystem — API design via SLEPs, estimator conventions (data-science staple).
2
+ # Curator: update last_verified after checking links.
3
+ # Re-verified 2026-08-30: adjacent/SLEP/metadata-routing URLs 200; pins
4
+ # 22893/18936/31039 200; `Enhancement` label still exists.
5
+
6
+ id: sklearn
7
+ display_name: scikit-learn
8
+ version: 1
9
+
10
+ last_verified: 2026-08-30
11
+ max_age_days: 90
12
+
13
+ default_repos:
14
+ - scikit-learn/scikit-learn
15
+
16
+ synonyms:
17
+ metadata routing: [sample props, SLEP006, set_fit_request, routing]
18
+ callbacks: [SLEP023, training callbacks, Callback API]
19
+ pipeline: [Pipeline, ColumnTransformer, meta-estimator]
20
+
21
+ label_boosts:
22
+ Enhancement: 0.05
23
+
24
+ adjacent_projects:
25
+ - name: imbalanced-learn
26
+ url: https://imbalanced-learn.org/
27
+ relevance: Extension for imbalanced classification; builds on sklearn estimators.
28
+ - name: skorch
29
+ url: https://skorch.readthedocs.io/
30
+ relevance: sklearn API wrapper for PyTorch models when deep learning is needed.
31
+ - name: XGBoost sklearn API
32
+ url: https://xgboost.readthedocs.io/en/stable/python/sklearn_estimator.html
33
+ relevance: Common gradient boosting choice alongside sklearn ensembles.
34
+
35
+ scope_files:
36
+ - CONTRIBUTING.md
37
+ - doc/developer/develop.rst
38
+
39
+ rfc:
40
+ - label: SLEP index (enhancement proposals)
41
+ url: https://scikit-learn-enhancement-proposals.readthedocs.io/
42
+ - label: Metadata routing user guide
43
+ url: https://scikit-learn.org/stable/metadata_routing.html
44
+
45
+ sibling_repos:
46
+ - scikit-learn/enhancement_proposals
47
+
48
+ path_hints:
49
+ sklearn: sklearn
50
+
51
+ pinned_issue_numbers:
52
+ - 22893
53
+ - 18936
54
+ - 31039
55
+
56
+ issue_search_queries:
57
+ - SLEP006 in:body
58
+ - metadata routing in:title
@@ -0,0 +1,85 @@
1
+ # Curated assessment scenarios — UI presets, CLI samples, and offline eval.
2
+ # Loaded by assessor.eval.sample_cases; do not duplicate in app.py.
3
+ cases:
4
+ - id: pytorch-masked
5
+ label: "PyTorch — torch.masked"
6
+ blurb: >
7
+ Arraxis reference case. Tier 2 pulls golden issues (#89734, #89320, #124964),
8
+ dev-discuss (pinned + search), adjacent NestedTensor/FlexAttention, and merged PRs.
9
+ question: "Is reviving torch.masked / MaskedTensor worth an upstream contribution?"
10
+ repo: pytorch/pytorch
11
+ path: torch/masked
12
+ ecosystem: pytorch
13
+ tier: 2
14
+ synthesize_default: true
15
+ held_out: true
16
+ expect_issue_numbers: [89734, 89320, 124964]
17
+ expect_evidence_kinds: [issue, discourse_thread, adjacent_project]
18
+
19
+ - id: pytorch-nested
20
+ label: "PyTorch — torch.nested"
21
+ blurb: >
22
+ Second PyTorch module path — compare jagged/nested direction vs MaskedTensor for
23
+ variable-length batch work.
24
+ question: "Is contributing to torch.nested worth it for variable-length sequences?"
25
+ repo: pytorch/pytorch
26
+ path: torch/nested
27
+ ecosystem: pytorch
28
+ tier: 2
29
+ synthesize_default: true
30
+ held_out: false
31
+
32
+ - id: numpy-ma
33
+ label: "NumPy — numpy.ma"
34
+ blurb: >
35
+ Missing-data / masked arrays in core NumPy. Tier 2 adds PRs; use tier 1 for a
36
+ faster smoke test. Open questions should name pandas/xarray, not MaskedTensor.
37
+ question: "Is improving numpy.ma __array_function__ support worth an upstream contribution?"
38
+ repo: numpy/numpy
39
+ path: numpy/ma
40
+ ecosystem: numpy
41
+ tier: 2
42
+ synthesize_default: false
43
+ held_out: true
44
+ expect_issue_numbers: [22338]
45
+ expect_evidence_kinds: [issue, repo_file]
46
+
47
+ - id: numpy-ma-strategy
48
+ label: "NumPy — numpy.ma (strategy)"
49
+ blurb: >
50
+ Shorter strategy-style wording from the held-out eval set — same repo/profile as numpy-ma.
51
+ question: "Should we invest in numpy.ma long-term?"
52
+ repo: numpy/numpy
53
+ path: numpy/ma
54
+ ecosystem: numpy
55
+ tier: 1
56
+ synthesize_default: false
57
+ held_out: true
58
+ expect_issue_numbers: [22338]
59
+ expect_evidence_kinds: [issue, repo_file]
60
+
61
+ - id: sklearn-routing
62
+ label: "scikit-learn — metadata routing"
63
+ blurb: >
64
+ SLEP006 / metadata routing — pinned issues and sklearn ecosystem adjacencies.
65
+ question: "Is contributing to sklearn metadata routing (SLEP006) still worth it?"
66
+ repo: scikit-learn/scikit-learn
67
+ path: ""
68
+ ecosystem: sklearn
69
+ tier: 2
70
+ synthesize_default: true
71
+ held_out: false
72
+
73
+ - id: sklearn-generic
74
+ label: "scikit-learn — generic feature"
75
+ blurb: >
76
+ Template question when you do not have a specific feature name yet — tests generic
77
+ profile retrieval on sklearn.
78
+ question: "Is adding feature X to sklearn worth a PR?"
79
+ repo: scikit-learn/scikit-learn
80
+ path: ""
81
+ ecosystem: sklearn
82
+ tier: 1
83
+ synthesize_default: false
84
+ held_out: true
85
+ expect_evidence_kinds: [issue]
@@ -0,0 +1,3 @@
1
+ from casefile.cache.github_search import GitHubSearchCache
2
+
3
+ __all__ = ["GitHubSearchCache"]
@@ -0,0 +1,49 @@
1
+ """Disk cache for GitHub issue search results (reduces rate-limit pressure)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import json
7
+ import time
8
+ from pathlib import Path
9
+ from typing import Any
10
+
11
+
12
+ class GitHubSearchCache:
13
+ def __init__(self, cache_dir: Path, *, ttl_seconds: int = 3600) -> None:
14
+ self._dir = cache_dir / "github_search"
15
+ self._dir.mkdir(parents=True, exist_ok=True)
16
+ self._ttl = ttl_seconds
17
+
18
+ def get(self, query: str) -> dict[str, Any] | list[dict] | None:
19
+ path = self._path(query)
20
+ if not path.is_file():
21
+ return None
22
+ try:
23
+ payload = json.loads(path.read_text(encoding="utf-8"))
24
+ except (json.JSONDecodeError, OSError):
25
+ return None
26
+ if time.time() - float(payload.get("ts", 0)) > self._ttl:
27
+ return None
28
+ if "total_count" in payload and "items" in payload:
29
+ items = payload.get("items")
30
+ if isinstance(items, list):
31
+ return {"items": items, "total_count": int(payload.get("total_count") or 0)}
32
+ items = payload.get("items")
33
+ return items if isinstance(items, list) else None
34
+
35
+ def set(self, query: str, page: dict[str, Any] | list[dict]) -> None:
36
+ path = self._path(query)
37
+ if isinstance(page, list):
38
+ body = {"ts": time.time(), "items": page, "total_count": len(page)}
39
+ else:
40
+ body = {
41
+ "ts": time.time(),
42
+ "items": page.get("items", []),
43
+ "total_count": int(page.get("total_count") or 0),
44
+ }
45
+ path.write_text(json.dumps(body, ensure_ascii=False), encoding="utf-8")
46
+
47
+ def _path(self, query: str) -> Path:
48
+ digest = hashlib.sha256(query.encode("utf-8")).hexdigest()[:32]
49
+ return self._dir / f"{digest}.json"
casefile/cli.py ADDED
@@ -0,0 +1,145 @@
1
+ import asyncio
2
+ from pathlib import Path
3
+ from typing import Optional
4
+
5
+ import httpx
6
+ import typer
7
+
8
+ from casefile.clients import build_clients
9
+ from casefile.config import get_settings
10
+ from casefile.engine.orchestrator import AssessmentEngine
11
+ from casefile.models.assessment import AssessmentRequest
12
+ from casefile.profiles import ProfileNotFoundError, ProfileStaleError, list_profiles, load_profile
13
+ from casefile.render.markdown import render_markdown
14
+
15
+ app = typer.Typer(no_args_is_help=True, help="Evidence-first OSS contribution assessment.")
16
+
17
+
18
+ @app.command()
19
+ def ping() -> None:
20
+ """Verify GitHub API and LLM connectivity."""
21
+ asyncio.run(_ping())
22
+
23
+
24
+ @app.command()
25
+ def assess(
26
+ question: str = typer.Option(..., "--question", "-q", help="Feature or contribution hypothesis."),
27
+ repo: str = typer.Option(..., "--repo", "-r", help="Target repository owner/name."),
28
+ path: Optional[str] = typer.Option(None, "--path", "-p", help="Module path inside the repo."),
29
+ ecosystem: Optional[str] = typer.Option(None, "--ecosystem", "-e", help="Ecosystem profile name."),
30
+ tier: int = typer.Option(1, "--tier", "-t", min=1, max=3, help="Retriever tier cap."),
31
+ output: Optional[Path] = typer.Option(None, "--output", "-o", help="Write markdown report to file."),
32
+ json_output: bool = typer.Option(False, "--json", help="Print JSON report to stdout."),
33
+ no_synthesis: bool = typer.Option(False, "--no-synthesis", help="Skip LLM synthesis."),
34
+ max_evidence: int = typer.Option(60, "--max-evidence", min=1, max=200, help="Cap on evidence items."),
35
+ allow_stale_profile: bool = typer.Option(
36
+ False, "--allow-stale-profile", help="Use ecosystem profile past max_age_days."
37
+ ),
38
+ ) -> None:
39
+ """Run an evidence assessment and print or save a report."""
40
+ asyncio.run(
41
+ _assess(
42
+ question=question,
43
+ repo=repo,
44
+ path=path,
45
+ ecosystem=ecosystem,
46
+ tier=tier,
47
+ output=output,
48
+ json_output=json_output,
49
+ no_synthesis=no_synthesis,
50
+ max_evidence=max_evidence,
51
+ allow_stale_profile=allow_stale_profile,
52
+ )
53
+ )
54
+
55
+
56
+ @app.command("list-profiles")
57
+ def list_profiles_cmd() -> None:
58
+ """List available ecosystem profiles."""
59
+ settings = get_settings()
60
+ for name in list_profiles(settings.resolved_profiles_dir()):
61
+ typer.echo(name)
62
+
63
+
64
+ async def _ping() -> None:
65
+ settings = get_settings()
66
+ async with httpx.AsyncClient(timeout=settings.http_timeout) as client:
67
+ bundle = build_clients(settings, client)
68
+ if not settings.github_token:
69
+ typer.echo("GitHub: skipped (CASEFILE_GITHUB_TOKEN not set)", err=True)
70
+ else:
71
+ data = await bundle.github.ping()
72
+ core = data.get("resources", {}).get("core", {}) if isinstance(data, dict) else {}
73
+ remaining = core.get("remaining", "?")
74
+ typer.echo(f"GitHub: ok (core rate limit remaining: {remaining})")
75
+
76
+ if not bundle.llm.available:
77
+ typer.echo("LLM: skipped (no API key for configured provider)", err=True)
78
+ else:
79
+ reply = await bundle.llm.ping()
80
+ typer.echo(f"LLM ({settings.llm_provider}): ok ({reply.strip()[:40]})")
81
+
82
+
83
+ async def _assess(
84
+ *,
85
+ question: str,
86
+ repo: str,
87
+ path: str | None,
88
+ ecosystem: str | None,
89
+ tier: int,
90
+ output: Path | None,
91
+ json_output: bool,
92
+ no_synthesis: bool,
93
+ max_evidence: int,
94
+ allow_stale_profile: bool,
95
+ ) -> None:
96
+ settings = get_settings()
97
+ profile = None
98
+ if ecosystem:
99
+ try:
100
+ profile = load_profile(
101
+ settings.resolved_profiles_dir(),
102
+ ecosystem,
103
+ allow_stale=allow_stale_profile,
104
+ )
105
+ except ProfileNotFoundError as exc:
106
+ raise typer.BadParameter(str(exc)) from exc
107
+ except ProfileStaleError as exc:
108
+ raise typer.BadParameter(f"{exc}. Pass --allow-stale-profile to override.") from exc
109
+
110
+ request = AssessmentRequest(
111
+ question=question,
112
+ repo=repo,
113
+ path=path,
114
+ ecosystem=ecosystem,
115
+ tier=tier,
116
+ synthesize=not no_synthesis,
117
+ max_evidence=max_evidence,
118
+ )
119
+ engine = AssessmentEngine(settings)
120
+ report = await engine.run(request, profile)
121
+
122
+ if json_output and output is None:
123
+ typer.echo(report.model_dump_json(indent=2))
124
+ return
125
+
126
+ md = render_markdown(report)
127
+ if output:
128
+ if str(output).endswith(".json"):
129
+ output.write_text(report.model_dump_json(indent=2), encoding="utf-8")
130
+ typer.echo(f"Wrote {output}")
131
+ else:
132
+ output.write_text(md, encoding="utf-8")
133
+ typer.echo(f"Wrote {output}")
134
+ elif json_output:
135
+ typer.echo(report.model_dump_json(indent=2))
136
+ else:
137
+ typer.echo(md)
138
+
139
+
140
+ def main() -> None:
141
+ app()
142
+
143
+
144
+ if __name__ == "__main__":
145
+ main()
@@ -0,0 +1,30 @@
1
+ from dataclasses import dataclass, field
2
+
3
+ import httpx
4
+
5
+ from casefile.clients.github import GitHubClient
6
+ from casefile.clients.http import HttpClient
7
+ from casefile.clients.huggingface import HuggingFaceClient
8
+ from casefile.clients.llm import LlmClient
9
+ from casefile.config import Settings
10
+
11
+
12
+ @dataclass
13
+ class ClientBundle:
14
+ github: GitHubClient
15
+ http: HttpClient
16
+ llm: LlmClient
17
+ huggingface: HuggingFaceClient
18
+ stats: dict[str, int] = field(
19
+ default_factory=lambda: {"github_api": 0, "http": 0, "llm": 0, "huggingface": 0}
20
+ )
21
+
22
+
23
+ def build_clients(settings: Settings, httpx_client: httpx.AsyncClient | None = None) -> ClientBundle:
24
+ client = httpx_client or httpx.AsyncClient(timeout=settings.http_timeout)
25
+ return ClientBundle(
26
+ github=GitHubClient(settings, client),
27
+ http=HttpClient(client),
28
+ llm=LlmClient(settings, client),
29
+ huggingface=HuggingFaceClient(settings, client),
30
+ )