hitherto 0.1.0__tar.gz

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 (138) hide show
  1. hitherto-0.1.0/.env.example +9 -0
  2. hitherto-0.1.0/.github/workflows/ci.yml +26 -0
  3. hitherto-0.1.0/.github/workflows/publish.yml +32 -0
  4. hitherto-0.1.0/.gitignore +15 -0
  5. hitherto-0.1.0/AGENTS.md +24 -0
  6. hitherto-0.1.0/ARCHITECTURE.md +422 -0
  7. hitherto-0.1.0/LICENSE +201 -0
  8. hitherto-0.1.0/PKG-INFO +143 -0
  9. hitherto-0.1.0/README.md +120 -0
  10. hitherto-0.1.0/action/action.yml +117 -0
  11. hitherto-0.1.0/casefile/__init__.py +3 -0
  12. hitherto-0.1.0/casefile/cache/__init__.py +3 -0
  13. hitherto-0.1.0/casefile/cache/github_search.py +49 -0
  14. hitherto-0.1.0/casefile/cli.py +145 -0
  15. hitherto-0.1.0/casefile/clients/__init__.py +30 -0
  16. hitherto-0.1.0/casefile/clients/discourse_html.py +34 -0
  17. hitherto-0.1.0/casefile/clients/github.py +312 -0
  18. hitherto-0.1.0/casefile/clients/http.py +55 -0
  19. hitherto-0.1.0/casefile/clients/huggingface.py +105 -0
  20. hitherto-0.1.0/casefile/clients/llm.py +180 -0
  21. hitherto-0.1.0/casefile/config.py +54 -0
  22. hitherto-0.1.0/casefile/engine/__init__.py +0 -0
  23. hitherto-0.1.0/casefile/engine/citation_checker.py +99 -0
  24. hitherto-0.1.0/casefile/engine/orchestrator.py +353 -0
  25. hitherto-0.1.0/casefile/engine/planner.py +265 -0
  26. hitherto-0.1.0/casefile/engine/synthesizer.py +164 -0
  27. hitherto-0.1.0/casefile/engine/validator.py +134 -0
  28. hitherto-0.1.0/casefile/eval/__init__.py +5 -0
  29. hitherto-0.1.0/casefile/eval/sample_cases.py +69 -0
  30. hitherto-0.1.0/casefile/index/__init__.py +0 -0
  31. hitherto-0.1.0/casefile/models/__init__.py +15 -0
  32. hitherto-0.1.0/casefile/models/assessment.py +38 -0
  33. hitherto-0.1.0/casefile/models/evidence.py +53 -0
  34. hitherto-0.1.0/casefile/models/profile.py +140 -0
  35. hitherto-0.1.0/casefile/predict/__init__.py +47 -0
  36. hitherto-0.1.0/casefile/predict/agreement.py +161 -0
  37. hitherto-0.1.0/casefile/predict/assignment_score.py +340 -0
  38. hitherto-0.1.0/casefile/predict/extract_run.py +597 -0
  39. hitherto-0.1.0/casefile/predict/extractor.py +368 -0
  40. hitherto-0.1.0/casefile/predict/features.py +75 -0
  41. hitherto-0.1.0/casefile/predict/labels.py +261 -0
  42. hitherto-0.1.0/casefile/predict/person_period.py +153 -0
  43. hitherto-0.1.0/casefile/predict/quadrant.py +226 -0
  44. hitherto-0.1.0/casefile/predict/scorer.py +122 -0
  45. hitherto-0.1.0/casefile/predict/time.py +51 -0
  46. hitherto-0.1.0/casefile/predict/topic_hazard.py +336 -0
  47. hitherto-0.1.0/casefile/predict/topic_history.py +444 -0
  48. hitherto-0.1.0/casefile/profiles/__init__.py +3 -0
  49. hitherto-0.1.0/casefile/profiles/loader.py +39 -0
  50. hitherto-0.1.0/casefile/render/__init__.py +0 -0
  51. hitherto-0.1.0/casefile/render/markdown.py +229 -0
  52. hitherto-0.1.0/casefile/retrievers/__init__.py +21 -0
  53. hitherto-0.1.0/casefile/retrievers/adjacent.py +88 -0
  54. hitherto-0.1.0/casefile/retrievers/base.py +43 -0
  55. hitherto-0.1.0/casefile/retrievers/discourse.py +88 -0
  56. hitherto-0.1.0/casefile/retrievers/git_activity.py +72 -0
  57. hitherto-0.1.0/casefile/retrievers/github_issues.py +103 -0
  58. hitherto-0.1.0/casefile/retrievers/github_prs.py +53 -0
  59. hitherto-0.1.0/casefile/retrievers/huggingface_discussions.py +192 -0
  60. hitherto-0.1.0/casefile/retrievers/process_docs.py +47 -0
  61. hitherto-0.1.0/casefile/retrievers/repo_files.py +50 -0
  62. hitherto-0.1.0/casefile/retrievers/vital_signs.py +276 -0
  63. hitherto-0.1.0/casefile/web/__init__.py +1 -0
  64. hitherto-0.1.0/casefile/web/app.py +230 -0
  65. hitherto-0.1.0/casefile/web/jobs.py +59 -0
  66. hitherto-0.1.0/casefile/web/static/app.css +21 -0
  67. hitherto-0.1.0/casefile/web/templates/base.html +48 -0
  68. hitherto-0.1.0/casefile/web/templates/health.html +19 -0
  69. hitherto-0.1.0/casefile/web/templates/index.html +126 -0
  70. hitherto-0.1.0/casefile/web/templates/result.html +110 -0
  71. hitherto-0.1.0/casefile/web/templates/status.html +20 -0
  72. hitherto-0.1.0/docs/DEPLOY.md +36 -0
  73. hitherto-0.1.0/docs/MSR_ISSUE_RESOLUTION.md +38 -0
  74. hitherto-0.1.0/docs/PREDICT.md +347 -0
  75. hitherto-0.1.0/docs/PREDICT_QUADRANT.md +213 -0
  76. hitherto-0.1.0/docs/STATUS.md +65 -0
  77. hitherto-0.1.0/docs/VERIFICATION.md +55 -0
  78. hitherto-0.1.0/docs/WEB_UI.md +69 -0
  79. hitherto-0.1.0/docs/hf_snapshot/README.md +57 -0
  80. hitherto-0.1.0/docs/hf_snapshot/extractor_pin.json +11 -0
  81. hitherto-0.1.0/docs/hf_snapshot/gpt-oss-120b-card.json +6 -0
  82. hitherto-0.1.0/docs/hf_snapshot/hub_headers.txt +22 -0
  83. hitherto-0.1.0/docs/hf_snapshot/router_models.json +6136 -0
  84. hitherto-0.1.0/eval/extraction/README.md +143 -0
  85. hitherto-0.1.0/eval/extraction/agreement_2026-08-31_gpt_oss_x_gemma.json +72 -0
  86. hitherto-0.1.0/eval/extraction/agreement_2026-08-31_gpt_oss_x_qwen.json +72 -0
  87. hitherto-0.1.0/eval/extraction/agreement_2026-09-01_gpt_oss_x_gemma_v3.json +72 -0
  88. hitherto-0.1.0/eval/extraction/pilot_2026-08-30.jsonl +176 -0
  89. hitherto-0.1.0/eval/extraction/pilot_2026-08-31_block6_v2_gpt_oss.jsonl +176 -0
  90. hitherto-0.1.0/eval/extraction/pilot_2026-09-02_block6_v3_demand_gpt_oss.jsonl +112 -0
  91. hitherto-0.1.0/eval/extraction/secondary_block6_v3_gemma.jsonl +20 -0
  92. hitherto-0.1.0/eval/extraction/smoke_block6_v2_gemma.jsonl +20 -0
  93. hitherto-0.1.0/eval/extraction/smoke_block6_v2_gpt_oss.jsonl +10 -0
  94. hitherto-0.1.0/eval/extraction/smoke_block6_v2_qwen.jsonl +20 -0
  95. hitherto-0.1.0/eval/extraction/smoke_block6_v3_demand_gpt_oss.jsonl +20 -0
  96. hitherto-0.1.0/eval/extraction/smoke_block6_v3_gpt_oss.jsonl +10 -0
  97. hitherto-0.1.0/eval/extraction/smoke_block6_v3_stratified_gpt_oss.jsonl +20 -0
  98. hitherto-0.1.0/eval/sample_cases.yaml +85 -0
  99. hitherto-0.1.0/eval/topic_assignment/apertus.yaml +2363 -0
  100. hitherto-0.1.0/eval/topic_assignment/pytorch.yaml +3050 -0
  101. hitherto-0.1.0/eval/topic_assignment/pytorch_holdout.yaml +2019 -0
  102. hitherto-0.1.0/profiles/_template.yaml +61 -0
  103. hitherto-0.1.0/profiles/apertus.yaml +74 -0
  104. hitherto-0.1.0/profiles/numpy.yaml +60 -0
  105. hitherto-0.1.0/profiles/pytorch.yaml +96 -0
  106. hitherto-0.1.0/profiles/sklearn.yaml +58 -0
  107. hitherto-0.1.0/pyproject.toml +55 -0
  108. hitherto-0.1.0/scripts/fetch_apertus_assignment_sample.py +177 -0
  109. hitherto-0.1.0/scripts/fetch_pytorch_assignment_holdout.py +127 -0
  110. hitherto-0.1.0/scripts/fetch_topic_assignment_sample.py +126 -0
  111. hitherto-0.1.0/scripts/run_sample_assessments.sh +31 -0
  112. hitherto-0.1.0/scripts/score_topic_assignment.py +105 -0
  113. hitherto-0.1.0/scripts/validate_reports.py +60 -0
  114. hitherto-0.1.0/scripts/verify.sh +16 -0
  115. hitherto-0.1.0/tests/conftest.py +8 -0
  116. hitherto-0.1.0/tests/report_contract.py +86 -0
  117. hitherto-0.1.0/tests/test_adjacent.py +81 -0
  118. hitherto-0.1.0/tests/test_core.py +517 -0
  119. hitherto-0.1.0/tests/test_discourse.py +61 -0
  120. hitherto-0.1.0/tests/test_discourse_html.py +18 -0
  121. hitherto-0.1.0/tests/test_discourse_search.py +83 -0
  122. hitherto-0.1.0/tests/test_ecosystems.py +165 -0
  123. hitherto-0.1.0/tests/test_extract_run.py +549 -0
  124. hitherto-0.1.0/tests/test_extractor_agreement.py +66 -0
  125. hitherto-0.1.0/tests/test_github_cache.py +11 -0
  126. hitherto-0.1.0/tests/test_github_retry.py +46 -0
  127. hitherto-0.1.0/tests/test_held_out_eval.py +58 -0
  128. hitherto-0.1.0/tests/test_huggingface.py +124 -0
  129. hitherto-0.1.0/tests/test_integration.py +280 -0
  130. hitherto-0.1.0/tests/test_live.py +78 -0
  131. hitherto-0.1.0/tests/test_predict.py +846 -0
  132. hitherto-0.1.0/tests/test_profiles.py +75 -0
  133. hitherto-0.1.0/tests/test_sample_cases.py +18 -0
  134. hitherto-0.1.0/tests/test_topic_assignment_score.py +152 -0
  135. hitherto-0.1.0/tests/test_topic_quadrant.py +558 -0
  136. hitherto-0.1.0/tests/test_vital_signs.py +113 -0
  137. hitherto-0.1.0/tests/test_web.py +62 -0
  138. hitherto-0.1.0/tests/test_web_jobs.py +72 -0
@@ -0,0 +1,9 @@
1
+ # Copy to .env and fill in. Never commit .env.
2
+ CASEFILE_GITHUB_TOKEN=
3
+ CASEFILE_HF_TOKEN=
4
+ CASEFILE_OPENAI_API_KEY=
5
+ # CASEFILE_ANTHROPIC_API_KEY=
6
+ # Primary synthesis backend: huggingface | openai | anthropic
7
+ CASEFILE_LLM_PROVIDER=huggingface
8
+ # Optional model override (HF Inference Providers router). Pin, not :fastest.
9
+ # CASEFILE_LLM_MODEL=openai/gpt-oss-120b:groq
@@ -0,0 +1,26 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ verify:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: actions/setup-python@v5
13
+ with:
14
+ python-version: "3.12"
15
+ - name: Install
16
+ run: pip install -e ".[dev,web]"
17
+ - name: Mandatory verify script
18
+ run: bash scripts/verify.sh
19
+ - name: Wheel ships profiles and sample cases
20
+ run: |
21
+ pip install build
22
+ python -m build --wheel -o dist
23
+ python -m venv /tmp/wheel-venv
24
+ /tmp/wheel-venv/bin/pip install dist/*.whl
25
+ cd /tmp && /tmp/wheel-venv/bin/hitherto list-profiles | grep -qx pytorch
26
+ /tmp/wheel-venv/bin/python -c "from casefile.eval.sample_cases import load_sample_cases; assert load_sample_cases()"
@@ -0,0 +1,32 @@
1
+ name: Publish to PyPI
2
+
3
+ # Trusted publishing — no API token on the laptop.
4
+ # PyPI project name: hitherto
5
+ # One-time setup on https://pypi.org/manage/account/publishing/:
6
+ # Owner: sulimovp Repo: hitherto Workflow: publish.yml Environment: pypi
7
+ # Then create a GitHub Release tagged v0.1.0.
8
+
9
+ on:
10
+ release:
11
+ types: [published]
12
+ workflow_dispatch:
13
+
14
+ permissions:
15
+ id-token: write
16
+ contents: read
17
+
18
+ jobs:
19
+ publish:
20
+ runs-on: ubuntu-latest
21
+ environment: pypi
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ - uses: actions/setup-python@v5
25
+ with:
26
+ python-version: "3.12"
27
+ - name: Build
28
+ run: |
29
+ pip install build
30
+ python -m build
31
+ - name: Publish
32
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,15 @@
1
+ .env
2
+ __pycache__/
3
+ *.pyc
4
+ .pytest_cache/
5
+ .venv/
6
+ report.md
7
+ report-live-test.md
8
+ reports/
9
+ .cache/
10
+ eval/topic_assignment/_raw.json
11
+ eval/topic_assignment/_raw_holdout.json
12
+ eval/topic_assignment/apertus_raw.json
13
+ eval/topic_assignment/_probe_hf.py
14
+ eval/topic_assignment/_dump_apertus.py
15
+ eval/topic_assignment/_apply_*.py
@@ -0,0 +1,24 @@
1
+ # Hitherto — contributor notes
2
+
3
+ Architecture: `ARCHITECTURE.md`. Current implementation snapshot: `docs/STATUS.md`.
4
+
5
+ ## Commands
6
+
7
+ ```bash
8
+ pip install -e ".[dev,web]"
9
+ ./scripts/verify.sh
10
+ hitherto ping
11
+ hitherto list-profiles
12
+ hitherto-web
13
+ ```
14
+
15
+ ## Verification
16
+
17
+ 1. `./scripts/verify.sh` must exit 0 before claiming work is done.
18
+ 2. Web/UI changes: walk `docs/VERIFICATION.md`.
19
+ 3. Secrets stay in env. Never commit `.env`.
20
+
21
+ ## Design
22
+
23
+ - Evidence over verdict; every synthesis claim needs a citation.
24
+ - Ecosystem specialisation lives in `profiles/*.yaml`.
@@ -0,0 +1,422 @@
1
+ # Casefile — system architecture
2
+
3
+ **Implementation:** standalone Python package.
4
+
5
+ This document describes a **universal** evidence-retrieval pipeline. [`torch.masked`](https://github.com/pytorch/pytorch/tree/main/torch/masked) is the reference scenario throughout; the same engine must run for any `--repo owner/name` with optional `--ecosystem` enrichment.
6
+
7
+ ---
8
+
9
+ ## Goals and non-goals
10
+
11
+ **Goals**
12
+
13
+ - Given a natural-language question and a target repository, produce a **structured, cited evidence report** a human can verify in minutes.
14
+ - Keep retrieval, validation, and synthesis as separate stages so each can be tested without an LLM.
15
+ - Specialise via **ecosystem profiles** (YAML), not hard-coded PyTorch logic in core code.
16
+
17
+ **Non-goals**
18
+
19
+ - Verdict-first Q&A ("yes, contribute").
20
+ - Auto-labeling, auto-closing issues, or submitting PRs.
21
+ - Full-repo mirroring or code understanding beyond path-scoped git metadata.
22
+ - Replacing maintainer judgment.
23
+
24
+ ---
25
+
26
+ ## High-level pipeline
27
+
28
+ ```mermaid
29
+ flowchart LR
30
+ subgraph input
31
+ Q[Question]
32
+ R[Target repo]
33
+ P[Ecosystem profile optional]
34
+ end
35
+
36
+ subgraph core
37
+ PL[Query planner]
38
+ RT[Retrievers]
39
+ IX[(Index and cache)]
40
+ VA[Evidence validator]
41
+ SY[Synthesizer]
42
+ CV[Citation checker]
43
+ RP[Report renderer]
44
+ end
45
+
46
+ subgraph output
47
+ MD[Markdown report]
48
+ JSON[JSON bundle optional]
49
+ end
50
+
51
+ Q --> PL
52
+ R --> PL
53
+ P --> PL
54
+ PL --> RT
55
+ RT --> IX
56
+ RT --> VA
57
+ VA --> SY
58
+ SY --> CV
59
+ CV --> RP
60
+ RP --> MD
61
+ RP --> JSON
62
+ ```
63
+
64
+ **Invariant:** nothing enters the report `Evidence` section unless it passed validation (real URL, fetch succeeded, within freshness window). The synthesizer may only reference evidence IDs present in the bundle.
65
+
66
+ ---
67
+
68
+ ## Package layout
69
+
70
+ Planned Python 3.11 package. One library; CLI and GitHub App are thin adapters.
71
+
72
+ ```text
73
+ casefile/
74
+ pyproject.toml
75
+ casefile/
76
+ __init__.py
77
+ cli.py # typer: assess, ping, index refresh
78
+ config.py # env, paths, rate-limit budgets
79
+
80
+ models/
81
+ assessment.py # AssessmentRequest, AssessmentReport
82
+ evidence.py # EvidenceItem, EvidenceBundle, EvidenceKind
83
+ profile.py # EcosystemProfile (pydantic)
84
+
85
+ engine/
86
+ planner.py # Question → RetrievalPlan
87
+ orchestrator.py # runs retrievers, merges, dedupes
88
+ validator.py # URL alive, freshness, no orphan claims
89
+ synthesizer.py # LLM call with evidence-only context
90
+ citation_checker.py # post-pass: every [n] resolves
91
+
92
+ retrievers/
93
+ base.py # Retriever protocol
94
+ github_issues.py
95
+ github_prs.py # Tier 2
96
+ git_activity.py # path-scoped log (local clone or API)
97
+ repo_files.py # README, CONTRIBUTING, CODEOWNERS
98
+ discourse.py # generic HTTP fetch + extract (profile-driven)
99
+ adjacent.py # candidate generation + existence check
100
+
101
+ clients/
102
+ github.py # httpx, ETag cache, rate-limit tracker
103
+ llm.py # provider protocol; anthropic, openai
104
+ http.py # HEAD/GET for validation
105
+
106
+ index/
107
+ store.py # SQLite: metadata, fetch timestamps
108
+ fts.py # FTS5 on issue/PR titles and bodies
109
+ vectors.py # lancedb embeddings (optional hybrid rank)
110
+
111
+ profiles/
112
+ loader.py # load YAML, check last_verified
113
+ schema.yaml # JSON Schema for profile files
114
+ pytorch.yaml # first shipped profile
115
+ _template.yaml # copy for new ecosystems
116
+
117
+ render/
118
+ markdown.py # fixed report schema
119
+ github_comment.py # collapsible sections for App
120
+
121
+ tests/
122
+ fixtures/ # recorded HTTP (vcr/pytest-httpx)
123
+ golden/ # torch.masked expected evidence IDs
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Core data model
129
+
130
+ All stages exchange pydantic models. Serialization to JSON enables golden tests and GitHub App replay.
131
+
132
+ ### AssessmentRequest
133
+
134
+ | Field | Type | Required | Example (`torch.masked`) |
135
+ |-------|------|----------|--------------------------|
136
+ | `question` | str | yes | "Is reviving MaskedTensor worth an upstream contribution?" |
137
+ | `repo` | str | yes | `pytorch/pytorch` |
138
+ | `path` | str | no | `torch/masked` |
139
+ | `ecosystem` | str | no | `pytorch` |
140
+ | `tier` | int | no (default 1) | `2` enables PR/discourse retrievers |
141
+ | `max_evidence` | int | no (default 40) | cap before synthesis |
142
+
143
+ ### EvidenceItem
144
+
145
+ | Field | Type | Notes |
146
+ |-------|------|-------|
147
+ | `id` | str | stable slug, e.g. `issue-89734` |
148
+ | `kind` | EvidenceKind | enum below |
149
+ | `title` | str | human label |
150
+ | `url` | HttpUrl | canonical link |
151
+ | `snippet` | str | ≤500 chars for synthesis context |
152
+ | `retrieved_at` | datetime | UTC |
153
+ | `source_retriever` | str | provenance for debugging |
154
+ | `relevance_score` | float | 0–1 from ranker |
155
+ | `metadata` | dict | kind-specific (state, labels, merged_at, …) |
156
+
157
+ **EvidenceKind** (extensible enum):
158
+
159
+ `issue`, `issue_comment`, `pull_request`, `commit`, `file`, `discourse_thread`, `release`, `adjacent_project`, `process_doc`
160
+
161
+ ### EvidenceBundle
162
+
163
+ - `items: list[EvidenceItem]` — deduped by URL
164
+ - `open_questions: list[str]` — retriever failures, rate limits, ambiguous gaps
165
+ - `freshness: datetime` — oldest `retrieved_at` or profile `last_verified`, whichever is worse
166
+ - `retrieval_stats: dict` — API calls, cache hits, duration
167
+
168
+ ### AssessmentReport
169
+
170
+ - `request: AssessmentRequest`
171
+ - `evidence: EvidenceBundle`
172
+ - `summary: str | None` — synthesis paragraphs with `[n]` tags; `None` if `--no-synthesis`
173
+ - `citation_map: dict[int, str]` — `[n]` → evidence id
174
+ - `validation_errors: list[str]` — citation checker output; empty = pass
175
+
176
+ ---
177
+
178
+ ## Retriever protocol
179
+
180
+ Every retriever is a stateless class implementing one interface. The orchestrator runs them concurrently (asyncio + httpx) subject to a global rate-limit budget.
181
+
182
+ ```python
183
+ class Retriever(Protocol):
184
+ name: str
185
+ tier: int # 1 = MVP, 2 = Phase 1.5, 3 = optional
186
+
187
+ def plan(self, request: AssessmentRequest, profile: EcosystemProfile | None) -> RetrievalSpec: ...
188
+
189
+ async def fetch(
190
+ self,
191
+ spec: RetrievalSpec,
192
+ clients: ClientBundle,
193
+ index: IndexStore,
194
+ ) -> list[EvidenceItem]: ...
195
+ ```
196
+
197
+ **RetrievalSpec** carries planned queries (GitHub search strings, paths, discourse URLs) so `plan()` is unit-testable without network.
198
+
199
+ ### Built-in retrievers (universal)
200
+
201
+ | Retriever | Tier | Input | Output kind |
202
+ |-----------|------|-------|-------------|
203
+ | `GitHubIssuesRetriever` | 1 | repo + query embedding/keywords | `issue`, `issue_comment` |
204
+ | `RepoFilesRetriever` | 1 | repo + paths from profile or defaults | `file`, `process_doc` |
205
+ | `GitActivityRetriever` | 1 | repo + `--path` | `commit` |
206
+ | `AdjacentProjectsRetriever` | 1 | question + profile.adjacent | `adjacent_project` (validated only) |
207
+ | `GitHubPRsRetriever` | 2 | repo + path + linked issues | `pull_request` |
208
+ | `DiscourseRetriever` | 2 | profile.discourse URLs + query | `discourse_thread` |
209
+ | `ReleasesRetriever` | 2 | repo tags/releases | `release` |
210
+
211
+ Profile adds **sources and synonyms**; retriever code stays generic.
212
+
213
+ ### Ranking (hybrid)
214
+
215
+ 1. **FTS5** keyword match on indexed issue/PR text (profile synonym expansion).
216
+ 2. **Vector** similarity (embedding of question vs item title+snippet).
217
+ 3. **Recency** boost for commits and merged PRs.
218
+ 4. **Profile weights** — e.g. label `module: masked` +0.2 for PyTorch.
219
+
220
+ Final score = weighted sum; top-K per kind before global cap.
221
+
222
+ ---
223
+
224
+ ## Query planner
225
+
226
+ `planner.py` turns `(question, repo, profile)` into a `RetrievalPlan`:
227
+
228
+ 1. Expand question with profile **synonyms** (`masked tensor` → `MaskedTensor`, `NestedTensor`, …).
229
+ 2. Select retrievers by `tier` and available profile sections.
230
+ 3. Build GitHub search queries (issues: `repo:pytorch/pytorch masked tensor`, PRs: `repo:pytorch/pytorch path:torch/masked`).
231
+ 4. Attach default file paths: `README.md`, `CONTRIBUTING.md`, `.github/CODEOWNERS`, plus profile `scope_files`.
232
+ 5. Set rate-limit budget (default: 25 search calls, 100 REST calls per assessment).
233
+
234
+ No LLM in the planner for MVP — keeps runs deterministic and cheap. Optional later: LLM suggests extra keywords, planner still validates.
235
+
236
+ ---
237
+
238
+ ## Evidence validator
239
+
240
+ Runs **before** synthesis on every `EvidenceItem`:
241
+
242
+ | Check | Action on failure |
243
+ |-------|-------------------|
244
+ | URL returns 2xx or valid GitHub API object | drop item; log to `open_questions` |
245
+ | `retrieved_at` within profile `max_age_days` | drop if index stale; suggest `casefile index refresh` |
246
+ | Adjacent project: repo or docs URL exists | drop; never pass to synthesizer |
247
+ | Duplicate URL | merge, keep higher score |
248
+
249
+ AdjacentProjectsRetriever flow:
250
+
251
+ 1. Static list from profile `adjacent_projects` (always validated).
252
+ 2. Optional LLM proposes extra names → **must** pass HTTP/GitHub existence check → drop failures silently.
253
+
254
+ ---
255
+
256
+ ## Synthesizer and citation checker
257
+
258
+ **Synthesizer**
259
+
260
+ - Input: question + evidence items (id, title, snippet, url only — not full bodies).
261
+ - System prompt: evidence-only; refuse unknown projects; tag sentences with `[n]`.
262
+ - Output: structured JSON `{ paragraphs: [...], citations: { "1": "issue-89734", ... } }` preferred over free text.
263
+
264
+ **Citation checker**
265
+
266
+ - Every `[n]` in summary maps to an evidence id.
267
+ - Every evidence id referenced must exist in bundle.
268
+ - Optional: LLM sentence ↔ snippet entailment check (Phase 3 eval harness).
269
+
270
+ If checker fails: strip summary, keep evidence, set `validation_errors`, still write report.
271
+
272
+ ---
273
+
274
+ ## Index and cache
275
+
276
+ Single-machine SQLite under `~/.cache/casefile/` (override via env).
277
+
278
+ | Table | Purpose |
279
+ |-------|---------|
280
+ | `evidence_raw` | serialized item bodies, etag |
281
+ | `evidence_fts` | FTS5 virtual table |
282
+ | `fetch_log` | url, fetched_at, status |
283
+ | `embeddings` | optional lancedb path or blob ref |
284
+
285
+ **Index refresh** (`casefile index refresh --repo pytorch/pytorch`):
286
+
287
+ - Incremental GitHub issue/PR sync since last cursor.
288
+ - Respects rate limits; resumes on interrupt.
289
+
290
+ Assessments prefer index when fresh; fall back to live API with shorter timeout.
291
+
292
+ ---
293
+
294
+ ## Ecosystem profile
295
+
296
+ Profiles are YAML on disk. Core code loads by name; no PyTorch imports in engine.
297
+
298
+ See [`profiles/_template.yaml`](profiles/_template.yaml) and [`profiles/pytorch.yaml`](profiles/pytorch.yaml).
299
+
300
+ Profile responsibilities:
301
+
302
+ - Extra retrieval sources (discourse base URL, RFC doc patterns).
303
+ - Synonym map for query expansion.
304
+ - Adjacent projects list (pre-validated URLs maintained by curator).
305
+ - Label hints for ranking boosts.
306
+ - Freshness metadata (`last_verified`).
307
+
308
+ Adding JAX = new YAML file, zero engine changes.
309
+
310
+ ---
311
+
312
+ ## Delivery adapters
313
+
314
+ ### CLI (`casefile assess`)
315
+
316
+ ```bash
317
+ casefile assess \
318
+ --question "Should we invest in reviving MaskedTensor?" \
319
+ --repo pytorch/pytorch \
320
+ --path torch/masked \
321
+ --ecosystem pytorch \
322
+ --tier 2 \
323
+ --output report.md
324
+ ```
325
+
326
+ Flags: `--no-synthesis`, `--json`, `--refresh-index`.
327
+
328
+ ### GitHub App (Phase 2)
329
+
330
+ - Webhook → build `AssessmentRequest` from issue title + body.
331
+ - Call same `orchestrator.run()`.
332
+ - `render.github_comment` → sticky comment; store report hash on issue label for idempotent re-run.
333
+
334
+ ---
335
+
336
+ ## Reference walkthrough: `torch.masked`
337
+
338
+ **Request**
339
+
340
+ ```yaml
341
+ question: "Is reviving torch.masked / MaskedTensor worth a multi-month upstream contribution?"
342
+ repo: pytorch/pytorch
343
+ path: torch/masked
344
+ ecosystem: pytorch
345
+ tier: 2
346
+ ```
347
+
348
+ **Planner output (abbreviated)**
349
+
350
+ | Retriever | Planned work |
351
+ |-----------|--------------|
352
+ | GitHubIssues | search: `repo:pytorch/pytorch masked MaskedTensor`; boost labels from profile |
353
+ | GitHubPRs | merged PRs `path:torch/masked` last 24 months |
354
+ | GitActivity | log stat on `torch/masked/` |
355
+ | RepoFiles | `CONTRIBUTING.md`, `.github/CODEOWNERS`, `docs/source/masked.md` |
356
+ | Discourse | search dev-discuss for "masked tensor" |
357
+ | Adjacent | validate NestedTensor, FlexAttention, `torch.nested` docs from profile |
358
+
359
+ **Expected evidence IDs (golden test)**
360
+
361
+ Must appear in top results for regression:
362
+
363
+ - `issue-89734`, `issue-89320`, `issue-124964` (exact numbers may shift; golden file uses pattern + manual review)
364
+ - At least one `adjacent_project` for NestedTensor or FlexAttention with live doc URL
365
+ - `commit` or activity block showing last touch on `torch/masked`
366
+ - Tier 2: optional `discourse_thread` or `pull_request` if linked
367
+
368
+ **Open questions the report should honestly list**
369
+
370
+ - Prototype label removal timeline (if not in sources).
371
+ - Whether core team prefers NestedTensor for all masked-sequence use cases.
372
+ - Maintainer bandwidth (inference, not fact — synthesis must say "open question").
373
+
374
+ ---
375
+
376
+ ## Configuration and secrets
377
+
378
+ | Env var | Purpose |
379
+ |---------|---------|
380
+ | `CASEFILE_GITHUB_TOKEN` | fine-grained PAT, read-only |
381
+ | `CASEFILE_ANTHROPIC_API_KEY` | primary LLM |
382
+ | `CASEFILE_OPENAI_API_KEY` | fallback / embeddings |
383
+ | `CASEFILE_CACHE_DIR` | override index path |
384
+ | `CASEFILE_LLM_PROVIDER` | `anthropic` \| `openai` |
385
+
386
+ Never commit tokens. `casefile ping` verifies GitHub + LLM connectivity.
387
+
388
+ ---
389
+
390
+ ## Testing strategy
391
+
392
+ | Layer | Approach |
393
+ |-------|----------|
394
+ | Retrievers | pytest-httpx fixtures from recorded GitHub responses |
395
+ | Validator | synthetic dead URLs, stale timestamps |
396
+ | Planner | snapshot tests on torch.masked plan |
397
+ | Golden | full assess run against fixtures → compare evidence ids |
398
+ | Citation checker | mutate summary with bad `[n]` → expect errors |
399
+ | Live smoke | optional nightly, rate-limited, not in CI |
400
+
401
+ ---
402
+
403
+ ## Phased implementation map
404
+
405
+ | Architecture piece | backlog phase |
406
+ |--------------------|-------------------|
407
+ | models, clients, `ping` | 0.5 |
408
+ | Tier 1 retrievers, validator, markdown render | 1 |
409
+ | GitHubPRs, Discourse, pytorch profile | 1.5 |
410
+ | synthesizer + citation checker | 1 |
411
+ | GitHub App adapter | 2 |
412
+ | second profile, eval harness | 3 |
413
+
414
+ ---
415
+
416
+ ## Open design decisions
417
+
418
+ - [ ] Async (`asyncio`) vs sync retrievers with thread pool — default async for parallel I/O.
419
+ - [ ] Embed at index time vs query time — index time for issues; query time for question embedding only.
420
+ - [ ] Local git clone vs GitHub commits API for activity — prefer API for MVP; optional clone for offline.
421
+ - [ ] JSON report as primary artifact with markdown as render target — lean toward yes for App idempotency.
422
+