reponeedle 1.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.
Files changed (74) hide show
  1. reponeedle-1.1.0/LICENSE +22 -0
  2. reponeedle-1.1.0/PKG-INFO +406 -0
  3. reponeedle-1.1.0/README.md +368 -0
  4. reponeedle-1.1.0/pyproject.toml +59 -0
  5. reponeedle-1.1.0/reponeedle/__init__.py +42 -0
  6. reponeedle-1.1.0/reponeedle/cli.py +125 -0
  7. reponeedle-1.1.0/reponeedle/core/__init__.py +23 -0
  8. reponeedle-1.1.0/reponeedle/core/abstention.py +132 -0
  9. reponeedle-1.1.0/reponeedle/core/arm101.py +301 -0
  10. reponeedle-1.1.0/reponeedle/core/attenuation.py +74 -0
  11. reponeedle-1.1.0/reponeedle/core/budget.py +25 -0
  12. reponeedle-1.1.0/reponeedle/core/cascade.py +295 -0
  13. reponeedle-1.1.0/reponeedle/core/change_impact.py +246 -0
  14. reponeedle-1.1.0/reponeedle/core/function_graph.py +507 -0
  15. reponeedle-1.1.0/reponeedle/core/graph.py +860 -0
  16. reponeedle-1.1.0/reponeedle/core/lexical.py +170 -0
  17. reponeedle-1.1.0/reponeedle/core/packer.py +509 -0
  18. reponeedle-1.1.0/reponeedle/core/router.py +108 -0
  19. reponeedle-1.1.0/reponeedle/core/semantic.py +217 -0
  20. reponeedle-1.1.0/reponeedle/core/tokenizer.py +133 -0
  21. reponeedle-1.1.0/reponeedle/engine.py +580 -0
  22. reponeedle-1.1.0/reponeedle/models.py +287 -0
  23. reponeedle-1.1.0/reponeedle.egg-info/PKG-INFO +406 -0
  24. reponeedle-1.1.0/reponeedle.egg-info/SOURCES.txt +72 -0
  25. reponeedle-1.1.0/reponeedle.egg-info/dependency_links.txt +1 -0
  26. reponeedle-1.1.0/reponeedle.egg-info/entry_points.txt +2 -0
  27. reponeedle-1.1.0/reponeedle.egg-info/requires.txt +22 -0
  28. reponeedle-1.1.0/reponeedle.egg-info/top_level.txt +1 -0
  29. reponeedle-1.1.0/setup.cfg +4 -0
  30. reponeedle-1.1.0/tests/test_ablation_switches.py +119 -0
  31. reponeedle-1.1.0/tests/test_abstention.py +35 -0
  32. reponeedle-1.1.0/tests/test_arm101_production_parity.py +132 -0
  33. reponeedle-1.1.0/tests/test_benchmark.py +40 -0
  34. reponeedle-1.1.0/tests/test_budget.py +41 -0
  35. reponeedle-1.1.0/tests/test_cud_pack_production.py +289 -0
  36. reponeedle-1.1.0/tests/test_engine.py +42 -0
  37. reponeedle-1.1.0/tests/test_graph.py +160 -0
  38. reponeedle-1.1.0/tests/test_lexical.py +37 -0
  39. reponeedle-1.1.0/tests/test_public_api.py +105 -0
  40. reponeedle-1.1.0/tests/test_robustness_and_quality.py +143 -0
  41. reponeedle-1.1.0/tests/test_router.py +44 -0
  42. reponeedle-1.1.0/tests/test_semantic.py +27 -0
  43. reponeedle-1.1.0/tests/test_stage3_10_1_metric_validation.py +184 -0
  44. reponeedle-1.1.0/tests/test_stage3_10_2_integrity.py +134 -0
  45. reponeedle-1.1.0/tests/test_stage3_10_class_to_test.py +225 -0
  46. reponeedle-1.1.0/tests/test_stage3_10_verification.py +104 -0
  47. reponeedle-1.1.0/tests/test_stage3_11_function_graph.py +176 -0
  48. reponeedle-1.1.0/tests/test_stage3_11_integrity.py +131 -0
  49. reponeedle-1.1.0/tests/test_stage3_12_factorial.py +180 -0
  50. reponeedle-1.1.0/tests/test_stage3_12_hardening.py +186 -0
  51. reponeedle-1.1.0/tests/test_stage3_12a_reconciliation.py +94 -0
  52. reponeedle-1.1.0/tests/test_stage3_13_reconciliation.py +122 -0
  53. reponeedle-1.1.0/tests/test_stage3_14_language_attenuation.py +124 -0
  54. reponeedle-1.1.0/tests/test_stage3_14_safeguards.py +177 -0
  55. reponeedle-1.1.0/tests/test_stage3_15_reconciliation_safeguards.py +137 -0
  56. reponeedle-1.1.0/tests/test_stage3_15_safeguards.py +175 -0
  57. reponeedle-1.1.0/tests/test_stage3_16_contextbench_gate.py +236 -0
  58. reponeedle-1.1.0/tests/test_stage3_17_evaluation_gate.py +173 -0
  59. reponeedle-1.1.0/tests/test_stage3_18_candidate_provenance_and_reconciliation.py +199 -0
  60. reponeedle-1.1.0/tests/test_stage3_19_production_parity_and_integrity.py +223 -0
  61. reponeedle-1.1.0/tests/test_stage3_20_production_integration.py +113 -0
  62. reponeedle-1.1.0/tests/test_stage3_21_production_quality.py +141 -0
  63. reponeedle-1.1.0/tests/test_stage3_6_forensic_reconciliation.py +120 -0
  64. reponeedle-1.1.0/tests/test_stage3_7_component_isolation.py +153 -0
  65. reponeedle-1.1.0/tests/test_stage3_7_fail_closed_audit.py +140 -0
  66. reponeedle-1.1.0/tests/test_stage3_7_metrics.py +195 -0
  67. reponeedle-1.1.0/tests/test_stage3_8_query_conditioned_graph.py +139 -0
  68. reponeedle-1.1.0/tests/test_stage3_8_reproducibility.py +158 -0
  69. reponeedle-1.1.0/tests/test_stage3_9_2_budget_audit.py +309 -0
  70. reponeedle-1.1.0/tests/test_stage3_9_cascade.py +252 -0
  71. reponeedle-1.1.0/tests/test_stage3_9_recovery.py +105 -0
  72. reponeedle-1.1.0/tests/test_stage3_candidates.py +121 -0
  73. reponeedle-1.1.0/tests/test_tokenizer.py +43 -0
  74. reponeedle-1.1.0/tests/test_v1_1_change_impact_integration.py +242 -0
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RepoNeedle Authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,406 @@
1
+ Metadata-Version: 2.4
2
+ Name: reponeedle
3
+ Version: 1.1.0
4
+ Summary: Token-Budget-Aware, Workflow-Adaptive Repository Context Retrieval for AI Coding Agents
5
+ Author: RepoNeedle Contributors
6
+ License-Expression: MIT
7
+ Keywords: code-retrieval,ai-agents,context-selection,token-budget,repository-retrieval,llm
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: numpy>=1.24.0
21
+ Requires-Dist: scipy>=1.10.0
22
+ Requires-Dist: networkx>=3.0
23
+ Requires-Dist: pydantic>=2.0.0
24
+ Requires-Dist: pathspec>=0.11.0
25
+ Requires-Dist: rich>=13.0.0
26
+ Requires-Dist: tomli>=2.0.1; python_version < "3.11"
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
29
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
30
+ Provides-Extra: api
31
+ Requires-Dist: fastapi<1.0,>=0.115; extra == "api"
32
+ Requires-Dist: httpx>=0.24; extra == "api"
33
+ Requires-Dist: uvicorn[standard]<1.0,>=0.30; extra == "api"
34
+ Provides-Extra: hf
35
+ Requires-Dist: huggingface_hub>=0.20.0; extra == "hf"
36
+ Requires-Dist: gradio>=4.0.0; extra == "hf"
37
+ Dynamic: license-file
38
+
39
+ # 🪡 RepoNeedle
40
+
41
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
42
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
43
+ [![CI](https://github.com/krishika08/RepoNeedle/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/krishika08/RepoNeedle/actions/workflows/ci.yml)
44
+ [![Hugging Face Dataset](https://img.shields.io/badge/%F0%9F%A4%97%20Dataset-RepoNeedle--Bench-blue)](https://huggingface.co/datasets/RepoNeedle/RepoNeedle-Bench)
45
+ [![Hugging Face Space](https://img.shields.io/badge/%F0%9F%A4%97%20Space-RepoNeedle--Playground-indigo)](https://huggingface.co/spaces/RepoNeedle/RepoNeedle-Playground)
46
+ [![Hugging Face Space](https://img.shields.io/badge/%F0%9F%A4%97%20Space-RepoNeedle--Playground-indigo)](https://huggingface.co/spaces/Krishikax/RepoNeedle-Playground)
47
+
48
+ [![Buy Me a Coffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-Support%20RepoNeedle-FFDD00?logo=buymeacoffee&logoColor=000000)](https://buymeacoffee.com/krishika.x)
49
+
50
+ **RepoNeedle** is an open-source, token-budget-aware repository context retrieval system designed to help AI coding agents discover the most critical files for a coding task under strict context-token constraints.
51
+
52
+ ---
53
+
54
+ ## ⚡ The Upstream Context Problem in AI Coding
55
+
56
+ Autonomous coding agents (e.g., Claude Code, Aider, OpenHands, Cline) face a severe upstream bottleneck: **Context Acquisition**.
57
+
58
+ When an agent tackles an issue, bug report, or test failure, passing the entire repository into the prompt is cost-prohibitive or exceeds context windows. Existing approaches face persistent failure modes:
59
+ - **Dense Embedding Models**: Rank files without considering file size (tokens), repository topology (call/import graphs), or task intent. They frequently retrieve large, irrelevant files that exhaust the context window.
60
+ - **RepoMap / PageRank Centrality**: Heavily prioritizes architectural hubs, but is completely blind to test files (which are leaf nodes with zero in-degree in import graphs) and cannot route specific error frames.
61
+ - **Context Bloat & Token Waste**: Studies like ContextBench demonstrate that coding agents pull massive amounts of irrelevant noise into context, degrading reasoning quality via "lost-in-the-middle" effects.
62
+ - **Selective Hallucination**: When a query cannot be answered within the repository (e.g. out-of-scope or counterfactual tasks), standard retrievers still force top-$k$ hallucinated files into context instead of abstaining.
63
+
64
+ RepoNeedle solves this upstream bottleneck by combining:
65
+ 1. **Multi-Signal Hybrid Scoring**: Field-weighted BM25 + Subword Semantic Vectors + AST Repository Graph Centrality.
66
+ 2. **Workflow-Adaptive Routing**: Automatic classification of query intent (`trace2code`, `code2test`, `edit2ripple`, `comment2context`, `selective`) with dynamic weight tuning.
67
+ 3. **Inverted Test-to-Target Mapping**: Dependency graph inversion and naming convention heuristics to locate regression test suites.
68
+ 4. **Calibrated Selective Abstention**: Peak-to-noise ($Z$-score) and repository symbol overlap gating to abstain from returning noise on counterfactual tasks.
69
+ 5. **CUD-Pack (Capacity-Sensitive Utility-Density Packing)**: Adaptive knapsack selection engine providing strict zero downstream overflows ($C_{\text{actual}} \le B_{\text{configured}}$) according to RepoNeedle's regex code token model across dual modes: **Compact Mode** ($\le 4\text{k}$ tokens, extracting high-density implementation spans and structural skeletons) and **Complete Context Mode** ($\ge 8\text{k}$ tokens, preserving whole source files).
70
+ 6. **Change-Impact Ranking Engine (V1.1 Opt-in)**: Seed-relative relationship scoring (evaluating static imports, symbol definitions, call sites, build manifests (`setup.py`, `setup.cfg`, `pyproject.toml`, `cargo.toml`, `package.json`, `go.mod`, `pom.xml`), test-stems, and directory proximity) designed for bug fixing and refactoring tasks.
71
+
72
+ ---
73
+
74
+ ## 📊 Benchmark Validation
75
+
76
+ To maintain strict scientific integrity, **Official External Benchmark Results** are reported separately from **Independent Research Evaluations**. Dataset sizes, query counts ($N$), candidate pool properties, and evaluation methodologies are explicitly documented for every measurement.
77
+
78
+ ---
79
+
80
+ ### Part A: Full Official Agent Retrieval Bench (ARB v2) Evaluation ($N=345$ Positive Samples)
81
+
82
+ Evaluated directly using the official `agent_retrieval_bench` evaluation package (`agent_retrieval_bench.baseline.sample_metrics`, v0.2.1, commit `9e4d68937f29`) on the complete **Agent Retrieval Bench v2** release ($N=345$ positive retrieval samples across 25 open-source repositories and 218 frozen repository snapshots):
83
+
84
+ | System / Ranker | Overall MRR | Recall@5 | Recall@10 | Recall@20 | BCY@4k | BCY@8k | BCY@16k | BCY@32k |
85
+ | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
86
+ | **RepoNeedle (Full)** | **0.2287** | **0.3011** | **0.4110** | **0.4279** | **0.2436** | **0.3450** | **0.4192** | **0.4279** |
87
+ | **Official RepoMap** | 0.2140 | 0.3185 | 0.4786 | **0.6306** | 0.2024 | **0.3788** | **0.5235** | **0.6166** |
88
+ | **Official Lexical** | 0.1574 | 0.2292 | 0.3548 | 0.4940 | 0.1488 | 0.2650 | 0.3886 | 0.4882 |
89
+ | **Official BM25** | 0.1520 | 0.1899 | 0.3034 | 0.4452 | 0.1220 | 0.2051 | 0.3184 | 0.4365 |
90
+ | *Qwen3-Embedding-4B (Ext Ref)* | *0.2379* | *—* | *—* | *0.6306* | *—* | *0.3409* | *—* | *—* |
91
+ | *Qwen3-Embedding-8B (Ext Ref)* | *0.2336* | *—* | *—* | *0.7029* | *—* | *0.3732* | *—* | *—* |
92
+ | *pplx-embed-v1-4b (Ext Ref)* | *0.2267* | *—* | *—* | *0.6072* | *—* | *0.3549* | *—* | *—* |
93
+ | *jina-code-0.5b (Ext Ref)* | *0.1914* | *—* | *—* | *0.4823* | *—* | *0.2783* | *—* | *—* |
94
+
95
+ #### Matched Paired Statistical Tests against Baselines ($N=345$ Identical Queries)
96
+
97
+ Evaluated with **10,000 bootstrap resamples** (repository-clustered bootstrap across 25 repositories):
98
+
99
+ | Paired Comparison | Mean Diff (Δ) | Std Error | Sample 95% CI | Repo-Clustered 95% CI | Paired $t$-test | Wilcoxon $W$ ($p$-value) | Wins / Ties / Losses | Statistically Significant |
100
+ | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
101
+ | **RepoNeedle vs BM25** | **+0.0767** (+50.5%) | 0.0161 | [+0.0458, +0.1085] | **[+0.0202, +0.1129]** | $t = 4.776$ ($p = 2.65\times 10^{-6}$) | $W = 22384.0$ ($p = 0.0096$) | 148 / 18 / 179 | **YES ($p < 0.01$)** |
102
+ | **RepoNeedle vs RepoMap** | **+0.0148** (+6.9%) | 0.0179 | [-0.0198, +0.0497] | **[-0.0466, +0.0619]** | $t = 0.827$ ($p = 0.4089$) | $W = 23821.5$ ($p = 0.3032$) | 122 / 26 / 197 | **NO (Parity in MRR)** |
103
+ | **RepoNeedle vs Lexical** | **+0.0713** (+45.3%) | 0.0157 | [+0.0409, +0.1031] | **[+0.0307, +0.1029]** | $t = 4.529$ ($p = 8.17\times 10^{-6}$) | $W = 22521.5$ ($p = 0.1215$) | 133 / 29 / 183 | **YES ($p < 0.001$)** |
104
+
105
+ > [!IMPORTANT]
106
+ > **Scientific Disclosure on RepoMap Comparison**: RepoNeedle does **NOT** achieve statistically significant overall superiority over RepoMap on MRR ($p = 0.4089$, repository-clustered 95% CI crosses zero: `[-0.0466, +0.0619]`). Furthermore, **RepoMap achieves substantially higher deep recall** (Recall@20: `0.6306` vs `0.4279`, a +47.4% relative advantage for RepoMap) and higher BCY@8k (`0.3788` vs `0.3450`, +9.8% relative advantage). RepoNeedle demonstrates a focused advantage under strict low-token budgets (BCY@4k: `0.2436` vs `0.2024`, +20.4% relative advantage) and specialized regression test discovery (`code2test`).
107
+
108
+ #### Per-Task Track Breakdown ($N=345$ Positive Samples)
109
+
110
+ | Task Track | Sample Count ($N$) | Metric | Official BM25 | Official Lexical | Official RepoMap | RepoNeedle | Relative Gain vs BM25 | Relative Gain vs RepoMap |
111
+ | :--- | :---: | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
112
+ | **`code2test`** | $N=106$ | **MRR** | 0.1057 | 0.0663 | 0.1942 | **0.2660** | **+151.7%** | **+37.0%** |
113
+ | | | Recall@5 | 0.1305 | 0.0676 | 0.2645 | **0.3918** | +200.2% | +48.1% |
114
+ | | | Recall@20 | 0.3066 | 0.2469 | 0.5572 | **0.5931** | +93.4% | +6.4% |
115
+ | | | **BCY@8k** | 0.1541 | 0.0928 | 0.3462 | **0.4814** | **+212.4%** | **+39.1%** |
116
+ | **`comment2context`** | $N=80$ | **MRR** | **0.1974** | 0.1530 | 0.1532 | 0.1708 | **-13.5%** | +11.5% |
117
+ | | | Recall@5 | **0.2146** | 0.1667 | 0.1750 | 0.1646 | -23.3% | -5.9% |
118
+ | | | Recall@20 | **0.5292** | 0.4979 | 0.4688 | 0.2083 | -60.6% | -55.6% |
119
+ | | | **BCY@8k** | 0.2604 | 0.2167 | **0.2792** | 0.1896 | -27.2% | -32.1% |
120
+ | **`trace2code`** | $N=101$ | **MRR** | 0.1638 | 0.2075 | **0.2723** | 0.2337 | +42.7% | **-14.2%** |
121
+ | | | Recall@5 | 0.2228 | 0.3432 | **0.4604** | 0.2855 | +28.1% | -38.0% |
122
+ | | | Recall@20 | 0.4934 | 0.6964 | **0.8465** | 0.4092 | -17.1% | -51.7% |
123
+ | | | **BCY@8k** | 0.1931 | 0.3795 | **0.5066** | 0.2954 | +53.0% | -41.7% |
124
+ | **`edit2ripple`** | $N=58$ | **MRR** | 0.1536 | **0.2428** | 0.2323 | 0.2320 | +51.0% | -0.1% |
125
+ | | | Recall@5 | 0.2069 | **0.4124** | 0.3678 | 0.3506 | +69.5% | -4.7% |
126
+ | | | Recall@20 | 0.4986 | 0.5876 | **0.6121** | 0.4612 | -7.5% | -24.7% |
127
+ | | | **BCY@8k** | 0.2428 | **0.4468** | 0.3534 | 0.3966 | +63.3% | +12.2% |
128
+
129
+ > [!IMPORTANT]
130
+ > **Methodological Disclosure on `code2test` (+151.7%) and Workflow Routing**:
131
+ > - **Task-Conditioned Evaluation**: In the official ARB evaluation above, benchmark task labels (`code2test`, `trace2code`, etc.) were supplied directly to the `WorkflowRouter` (`task_type = sample.get("task_type")`), dynamically activating task-specific fusion weights and test-graph linkages.
132
+ > - **Not Default AUTO-Mode Performance**: This measures **task-conditioned retrieval capacity**, not unassisted automatic classification. In unassisted production deployment (`TaskType.AUTO`), the engine relies on query text regex heuristics. If a natural-language query lacks explicit test keywords, automatic intent classification may default to `comment2context`, reducing the observed gain toward baseline BM25 performance (`0.1057`).
133
+ > - **Candidate Set Integrity**: The task conditioning dynamically modulates ranking weights and structural graph boosts; candidate file pools themselves are never filtered by oracle labels.
134
+
135
+ ---
136
+
137
+ ### Part B: Official ARB Selective Retrieval Evaluation ($N=82$ Abstention Samples)
138
+
139
+ Evaluated on the complete official Agent Retrieval Bench Selective Retrieval split (`v2_selective_mixed`, $N=82$ total queries across 71 repository snapshots):
140
+
141
+ | Evaluation Track | Sample Count ($N$) | Correctly Abstained | False Positives (Returned Noise) | Abstention Accuracy |
142
+ | :--- | :---: | :---: | :---: | :---: |
143
+ | **Natural No-Gold Issues** | 50 | 0 | 50 (100.0%) | **0.0%** |
144
+ | **Counterfactual Wrong-Repo** | 32 | 0 | 32 (100.0%) | **0.0%** |
145
+ | **Combined Selective Benchmark** | **82** | **0** | **82 (100.0%)** | **0.0%** |
146
+
147
+ > [!CAUTION]
148
+ > **Heuristic Abstention Failure Analysis**: In production benchmark conditions, RepoNeedle's heuristic confidence gating ($Z$-score + repository symbol overlap) achieved **0% abstention accuracy (0/82)**.
149
+ > - *Root Cause*: Heuristic confidence scores ranged between `0.64` and `0.86`, far exceeding the default threshold (`0.12` / `0.38`). Natural GitHub issue descriptions filed against a repository inherently contain valid repository vocabulary. Counterfactual queries similarly contain ubiquitous software engineering terminology (`error`, `parse`, `client`, `handler`).
150
+ > - *Recommendation*: Heuristic score thresholds are insufficient for reliable abstention in large codebases. Selective retrieval requires a dedicated, trained neural discriminator rather than surface lexical statistics.
151
+
152
+ ---
153
+
154
+ ### Part C: Component Ablations on Full ARB v2 ($N=345$)
155
+
156
+ Ablation evaluation conducted on the complete $N=345$ positive ARB v2 benchmark:
157
+
158
+ | Configuration | Overall MRR | Drop vs Full | Recall@5 | Recall@20 | Description |
159
+ | :--- | :---: | :---: | :---: | :---: | :--- |
160
+ | **Full RepoNeedle** | **0.2287** | **0.00%** | **0.3011** | 0.4279 | All components active (Router + Graph + BM25 + Skeletons) |
161
+ | *w/o WorkflowRouter* | 0.1642 | **-28.20%** | — | — | Static uniform weights across all task categories |
162
+ | *w/o RepoGraph* | 0.2287 | 0.00% | — | — | Graph centrality and test-to-target links zeroed |
163
+ | **Official RepoMap Baseline** | 0.2140 | -6.45% | 0.3185 | **0.6306** | Standalone PageRank graph centrality ranker |
164
+ | **Official BM25 Baseline** | 0.1520 | -33.53% | 0.1899 | 0.4452 | Standalone field BM25 ranker |
165
+
166
+ ---
167
+
168
+ ### Part D: Multi-Scale Token Payload Reduction & Measured Runtime
169
+
170
+ #### 1. Actual Content Payload Reduction Across Multiple Languages & File Sizes
171
+
172
+ Measured using exact BPE code subword regex (`re.compile(r"[A-Za-z0-9_]+|[^\s\w]|\s+")`, calibrated to OpenAI cl100k / LLaMA / Qwen tokenizers):
173
+
174
+ | Corpus File & Language | Lines | Full BPE Tokens | Skeleton BPE Tokens | Actual BPE Token Savings | Character Savings | Architectural Symbols Preserved |
175
+ | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
176
+ | **Python (Short)** | 50L | 280 | 280 | 0.0% *(fits budget)* | 0.0% | **YES** (Complete) |
177
+ | **Python (Medium Adapter)** | 250L | 2,060 | 305 | **85.2% reduction** | 85.8% reduction | **YES** (Class, methods, docstrings) |
178
+ | **Python (Long Session Mgr)** | 700L | 4,061 | 404 | **90.1% reduction** | 90.0% reduction | **YES** (Class, methods, TTL logic) |
179
+ | **Rust (Async RingBuffer)** | 200L | 2,312 | 222 | **90.4% reduction** | 91.1% reduction | **YES** (Struct, impl, fn signatures) |
180
+ | **TypeScript (EventDispatcher)** | 200L | 1,920 | 455 | **76.3% reduction** | 74.6% reduction | **YES** (Interface, class, methods) |
181
+ | **Go (HTTP Trie Router)** | 200L | 1,225 | 578 | **52.8% reduction** | 44.2% reduction | **YES** (Types, struct, methods) |
182
+
183
+ #### 2. Measured Benchmark Latency Distribution (Commodity CPU, Windows 11 AMD64)
184
+
185
+ Empirically measured across the full Agent Retrieval Bench evaluation suite:
186
+
187
+ | Component / Ranker | Mean Latency | Median ($p_{50}$) | 95th Percentile ($p_{95}$) | 99th Percentile ($p_{99}$) | Method Notes |
188
+ | :--- | :---: | :---: | :---: | :---: | :--- |
189
+ | **RepoNeedle Query Latency** | `317.7 ms` | `142.4 ms` | `827.2 ms` | `997.6 ms` | Multi-signal scoring + knapsack packing |
190
+ | **Official BM25 Query Latency** | `994.4 ms` | `1,158.3 ms` | `1,246.0 ms` | `1,305.7 ms` | Full inverted index posting scan |
191
+ | **Official RepoMap Query Latency**| `157.5 ms` | `192.1 ms` | `239.8 ms` | `250.1 ms` | Graph PageRank vector lookup |
192
+ | **Official Lexical Query Latency**| `884.1 ms` | `1,005.2 ms` | `1,150.3 ms` | `1,156.6 ms` | BM25 + subword character bigram matching |
193
+ | **RepoNeedle Index Build** | `8,622.9 ms` | `10,471.2 ms` | `11,484.8 ms` | `11,551.5 ms` | One-time AST + dependency graph per repo |
194
+
195
+ ---
196
+
197
+ ### Part E: System Architecture & Deployment Status
198
+
199
+ - **CPU Native Architecture**: RepoNeedle runs entirely in Python/NumPy/SciPy/NetworkX without requiring CUDA GPUs or heavy deep learning runtime dependencies.
200
+ - **Release Status**: **V1.1.0 source integrated on main; formal release publication pending.** Features default `legacy` ranker with backwards-compatible contract preservation, and opt-in `change_impact` ranking engine for seed-relative relationship scoring.
201
+
202
+ ---
203
+
204
+ ### Part F: Independent R6 Change-Impact Benchmark ($N=180$ Queries across 18 Repositories)
205
+
206
+ To evaluate retrieval generalizability beyond the original 25 ARB repositories, an independent benchmark cohort was constructed across **18 unseen open-source repositories** comprising 180 retrieval queries.
207
+
208
+ Statistical inference was conducted using **repository-clustered statistical models** across independent repository clusters:
209
+
210
+ | Partition | Queries ($N$) | Repositories | Baseline MRR | Champion MRR | Delta (Δ) | Repository-Clustered Inference (95% CI) | Statistical Significance |
211
+ | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
212
+ | **Training** | $N=90$ | 9 repos | 0.6213 | 0.6546 | +0.0333 | — | Training fit |
213
+ | **Validation** | $N=40$ | 4 repos | 0.6472 | 0.6708 | +0.0236 | $p = 0.5073$, 95% CI [0.0000, +0.0472] | Not Statistically Significant |
214
+ | **Held-Out** | $N=50$ | 5 repos | 0.5215 | 0.5467 | +0.0252 | $p = 0.5025$, 95% CI [0.0000, +0.0629] | Not Statistically Significant |
215
+ | **Pooled Cohort** | $N=180$ | 18 repos | 0.5994 | **0.6282** | **+0.0288** | $p = 0.0078$, 95% CI [+0.0082, +0.0524] | **Statistically Significant ($p < 0.01$)** |
216
+
217
+ > [!NOTE]
218
+ > **Methodological Context & Scope of R6 Results**:
219
+ > - **Pre-Filtered Candidate Pools**: Queries were evaluated against pre-filtered candidate pools averaging approximately **53.79 files per query**. Within these candidate pools, Candidate-Pool Recall@20 is 100%.
220
+ > - **Whole-Repository Generalization**: Whole-repository Recall@20 of 60–75% represents a projected estimate under full repository indexing, not an empirically measured whole-codebase scan.
221
+ > - **Statistical Power & Default Ranker**: While the pooled 18-repository cohort achieves statistically significant improvement under repository-clustered inference ($p = 0.0078$), the smaller isolated validation ($N=40$, $p = 0.5073$) and held-out ($N=50$, $p = 0.5025$) subsets are statistically underpowered. For this reason, the Change-Impact engine is provided as an **opt-in capability** rather than overriding the default `legacy` ranker.
222
+ > - **Aspirational Research Target**: The long-term research objective of $\text{MRR} \ge 0.80$ is an aspirational research milestone, not an achieved production metric.
223
+
224
+ ---
225
+
226
+ ## 🚀 Quickstart & Installation
227
+
228
+ RepoNeedle is self-contained and requires standard Python dependencies (`numpy`, `scipy`, `networkx`, `pydantic`, `pathspec`, `rich`, and `tomli` on Python < 3.11).
229
+
230
+ ### 1. Installation
231
+
232
+ ```bash
233
+ # Clone the verified repository
234
+ git clone https://github.com/krishika08/RepoNeedle.git
235
+ cd RepoNeedle
236
+
237
+ # Install package in editable mode
238
+ pip install -e .
239
+
240
+ # Or install with development and test dependencies
241
+ pip install -e ".[dev]"
242
+ ```
243
+
244
+ > [!TIP]
245
+ > On Python 3.10, `tomli>=2.0.1` is automatically installed via conditional dependency. On Python 3.11 and 3.12, native standard library `tomllib` is used with zero extra dependencies.
246
+
247
+ ---
248
+
249
+ ### 2. Python API
250
+
251
+ #### Standard Retrieval (Default Legacy Ranker):
252
+ ```python
253
+ from reponeedle import RepoNeedleEngine, BudgetConfig
254
+
255
+ # 1. Initialize engine on a local codebase (uses default 'legacy' ranker)
256
+ engine = RepoNeedleEngine.from_directory(
257
+ repo_dir="./my-project",
258
+ budget_config=BudgetConfig(max_tokens=4000, allow_skeletons=True, mode="auto"),
259
+ )
260
+
261
+ # 2. Retrieve context for a task (auto-resolves to compact mode for <= 4k)
262
+ result = engine.retrieve(
263
+ query="Add support for blueprint url_prefix inheritance in route registration",
264
+ budget_tokens=4000,
265
+ )
266
+
267
+ if result.abstained:
268
+ print(f"Abstained: {result.explanation}")
269
+ else:
270
+ print(f"Retrieved {len(result.selected_files)} files ({result.total_tokens} / {result.budget_tokens} tokens):")
271
+ for f in result.selected_files:
272
+ print(f"[{f.tier.value.upper()}] {f.path} (score: {f.score:.3f}, tokens: {f.token_count})")
273
+
274
+ # Access the exact fenced-markdown serialized prompt ready for LLM consumption:
275
+ llm_prompt_context = result.rendered_context
276
+ ```
277
+
278
+ #### Opt-In: Seed-Based Change-Impact Retrieval:
279
+ ```python
280
+ from reponeedle import RepoNeedleEngine, Query
281
+
282
+ # Initialize engine with Change-Impact ranking
283
+ engine = RepoNeedleEngine.from_directory(
284
+ repo_dir="./my-project",
285
+ ranker="change_impact",
286
+ )
287
+
288
+ # Populate anchor_files with the seed path to activate relationship scoring
289
+ query = Query(
290
+ text="Fix authentication session expiration",
291
+ anchor_files=["auth/session.py"],
292
+ budget_tokens=4000,
293
+ )
294
+
295
+ result = engine.retrieve(query)
296
+
297
+ for f in result.selected_files:
298
+ print(f"[{f.tier.value.upper()}] {f.path} (score: {f.score:.3f}, tokens: {f.token_count})")
299
+ if f.explanation:
300
+ print(f" Attribution: {f.explanation}")
301
+ ```
302
+
303
+ > [!NOTE]
304
+ > **Behavior of Plain-String (Seedless) Change-Impact Queries**:
305
+ > The Change-Impact ranking engine reads seed file paths from `query.anchor_files`. When `engine.retrieve()` is called with a plain string query (or without `anchor_files`):
306
+ > - **Lexical and semantic scoring remain active**: Candidate files continue to be retrieved and scored using combined BM25 lexical matching and subword semantic retrieval.
307
+ > - **Seed suppression is inactive without `anchor_files`**: Seed File Suppression (SFS) is not triggered since there are no designated seed files to down-weight.
308
+ > - **Seed-relative relationship boosts are inactive without `anchor_files`**: Relationship scoring across dependencies (static imports, symbols, calls, build manifests, test-stems, and directory proximity) is skipped.
309
+ > - **Test Intent Prior adjustments remain available according to detected query intent**: Test files receive boosts or penalties (`tip_multiplier_test` / `tip_multiplier_non_test`) based on detected test intent in the query text.
310
+ >
311
+ > To activate seed-relative relationship boosts and seed suppression, pass seed paths via `Query(text=..., anchor_files=['path/to/seed.py'])`.
312
+
313
+ ---
314
+
315
+ ### 3. Command Line Interface (CLI)
316
+
317
+ ```bash
318
+ # Default 'legacy' retrieval under a 4000 token limit
319
+ reponeedle "Fix AttributeError in SecureCookieSessionInterface cookie saving" --repo ./flask --budget 4000
320
+
321
+ # Opt-in Change-Impact retrieval (applies Test Intent Prior scoring)
322
+ reponeedle "fix token expiration in auth/session.py" --repo ./my-project --budget 4000 --ranker change_impact
323
+
324
+ # Task-conditioned retrieval for finding regression tests
325
+ reponeedle "test suite for HTTPBasicAuth" --repo ./requests --task code2test --budget 2000
326
+
327
+ # Serialize packaged markdown directly to a file
328
+ reponeedle "blueprints and route registration" --repo ./flask --budget 4000 --output-file prompt.md
329
+ ```
330
+
331
+ > [!NOTE]
332
+ > **CLI Seed-File Limitation**: The current CLI accepts query text as a positional string and does not currently expose a seed-file argument. Standard CLI queries run with `--ranker change_impact` execute as seedless queries: lexical and semantic scoring remain active, and Test Intent Prior adjustments remain available according to detected query intent, while seed suppression and seed-relative relationship boosts are inactive without `anchor_files`. Full seed-based relationship scoring is available via the Python API (`Query(anchor_files=[...])`). CLI seed-file support is planned as a separate future enhancement.
333
+
334
+ ---
335
+
336
+ ## 🧠 CUD-Pack Architecture (Capacity-Sensitive Utility-Density Packing)
337
+
338
+ RepoNeedle integrates the **CUD-Pack** context optimization engine, replacing heuristic packing with capacity-elastic utility-density optimization:
339
+
340
+ ### 1. Dual Operational Modes
341
+ - **Compact Mode ($\le 4\text{k}$ tokens, $\alpha = 0.65$)**: Prioritizes focal implementation spans (`FOCUS_SPAN`) and structural skeletons (`SKELETON`). Prevents single distractor files from consuming the budget and displacing multi-target dependencies.
342
+ - **Complete Context Mode ($\ge 8\text{k}$ tokens, $\alpha = 0.25$)**: Prioritizes whole source files (`FULL`), selectively utilizing structural outlines for oversized files ($> 500$ tokens) when capacity is tight.
343
+
344
+ ### 2. Verified Token Budget Invariants
345
+ - **Deterministic Budget Enforcement**: Evaluated across tested nominal budgets (30, 50, 100, 500, 2000, 4000 tokens), CUD-Pack strictly enforces $C_{\text{actual}} \le B_{\text{configured}}$ with zero downstream token overflows according to RepoNeedle's deterministic regex token-counting model (`regex_code_tokenizer_v1`).
346
+ - **Overhead Accounting**: Pre-computes file header fences (`# File: {path}\n```{ext}\n...\n```\n\n`) deterministically before admitting candidates into the knapsack.
347
+ - **Representation Fallback Hierarchy**: Monotonically degrades candidate representations (`FULL` $\to$ `FOCUS_SPAN` $\to$ `SKELETON`) when full files exceed available token capacity.
348
+
349
+ > [!WARNING]
350
+ > **Tokenizer Boundary Disclosure**: Budget non-exceedance is enforced strictly according to RepoNeedle's internal regex token model (`regex_code_tokenizer_v1`). This does not imply exact token-count equivalence with arbitrary third-party LLM tokenizers (e.g. OpenAI tiktoken cl100k, LLaMA sentencepiece, or Qwen) or guarantee downstream token behavior for every external provider.
351
+
352
+ ---
353
+
354
+ ## 🔬 Reproducing Benchmark Results
355
+
356
+ Run the complete deterministic test suite and benchmarks:
357
+
358
+ ```bash
359
+ # 1. Run automated test suite (271 passed tests locally, 245 in clean CI checkouts)
360
+ pytest -q -rs
361
+
362
+ # 2. Run component ablation study with 95% Bootstrap CI
363
+ python benchmarks/run_ablations.py
364
+
365
+ # 3. Verify actual BPE token payload reduction and latency
366
+ python scripts/verify_token_savings_and_latency.py
367
+
368
+ # 4. Build distribution packages
369
+ python -m build --no-isolation
370
+ ```
371
+
372
+ ---
373
+
374
+ ## 📦 Hugging Face Release Artifacts
375
+
376
+ RepoNeedle distributes its validated assets primarily via Hugging Face:
377
+
378
+ 1. **RepoNeedle-Bench Dataset**: [`hf_artifacts/dataset/`](hf_artifacts/dataset/README.md)
379
+ - Permissively licensed JSONL datasets (`train.jsonl`, `test.jsonl`), schema, and provenance documentation.
380
+ 2. **RepoNeedle Playground Space**: [`hf_artifacts/space/`](hf_artifacts/space/README.md)
381
+ - Interactive Gradio demonstration allowing side-by-side comparison of RepoNeedle against classical BM25 and RepoMap PageRank.
382
+ 3. **Automated Publishing Script**: [`scripts/prepare_hf_release.py`](scripts/prepare_hf_release.py)
383
+ - Verified local release package ready to publish with `python scripts/prepare_hf_release.py --token <HF_TOKEN>`.
384
+
385
+ ---
386
+
387
+ ## 🛡️ License & Data Provenance
388
+
389
+ - **Source Code**: [MIT License](LICENSE)
390
+ - **RepoNeedle-Bench**: [MIT License](hf_artifacts/dataset/README.md)
391
+ - **Data Provenance**: Sourced exclusively from permissively licensed open-source projects (BSD-3-Clause, Apache-2.0, MIT). **Zero CC BY-NC or copyleft share-alike data is used.** Full manifest available in [`data_provenance/PROVENANCE.md`](data_provenance/PROVENANCE.md).
392
+ - **Upstream Notices**: Agent Retrieval Bench is Copyright (c) 2026 Agent Retrieval Bench contributors (MIT License). All upstream open-source code snapshots retain their original licenses and copyright notices.
393
+
394
+ ---
395
+
396
+ ## 📚 Citation
397
+
398
+ ```bibtex
399
+ @misc{reponeedle2026,
400
+ author = {RepoNeedle Contributors},
401
+ title = {RepoNeedle: Token-Budget-Aware, Workflow-Adaptive Repository Context Retrieval for AI Coding Agents},
402
+ year = {2026},
403
+ publisher = {GitHub},
404
+ howpublished = {\url{https://github.com/krishika08/RepoNeedle}}
405
+ }
406
+ ```