From c80bb28bfca3bf3200320025cee953a80c5adf43 Mon Sep 17 00:00:00 2001 From: Harshit Sharma <66710144+harshitethic@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:53:55 -0400 Subject: [PATCH 1/8] fix(index): include environment example templates in repository index --- backend/services/github.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/services/github.py b/backend/services/github.py index 3e28e49..420a511 100644 --- a/backend/services/github.py +++ b/backend/services/github.py @@ -427,7 +427,7 @@ def iter_files(root: Path): try: size = p.stat().st_size except OSError: continue if size > 300_000: continue - if p.suffix.lower() in TEXT_EXTENSIONS or p.name.lower() in {"dockerfile","makefile",".gitignore"}: + if p.suffix.lower() in TEXT_EXTENSIONS or p.name.lower().endswith(".env.example") or p.name.lower() in {"dockerfile","makefile",".gitignore"}: yield p def read_text(path: Path): return path.read_text(encoding="utf-8", errors="replace") From 5ddcf3bb295bc6710fe05f1d94a06918353664c7 Mon Sep 17 00:00:00 2001 From: Harshit Sharma <66710144+harshitethic@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:53:57 -0400 Subject: [PATCH 2/8] test(index): cover environment examples without indexing private env files --- backend/tests/test_repository_safety.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backend/tests/test_repository_safety.py b/backend/tests/test_repository_safety.py index 4e3b728..5c960e4 100644 --- a/backend/tests/test_repository_safety.py +++ b/backend/tests/test_repository_safety.py @@ -192,6 +192,19 @@ def test_zip_slip_is_refused_without_writing_outside(self): github.extract_zip(z) self.assertFalse((self.root / "escape.py").exists()) + def test_environment_examples_are_indexed_without_loading_env_secrets(self): + imported = self.repos / ("a" * 12) + imported.mkdir() + (imported / ".env.example").write_text("SAMPLE_OPTION=placeholder") + (imported / "service.env.example").write_text("SERVICE_OPTION=example") + (imported / ".env").write_text("REAL_PRIVATE_SETTING=secret") + listed = {p.name for p in github.iter_files(imported)} + self.assertIn(".env.example", listed) + self.assertIn("service.env.example", listed) + self.assertNotIn(".env", listed) + self.assertIn("SAMPLE_OPTION", build_context(imported, "SAMPLE_OPTION")) + self.assertNotIn("REAL_PRIVATE_SETTING", str(analyze(imported))) + if __name__ == "__main__": unittest.main() \ No newline at end of file From 6f2ae11f41762c3e291c24d8da8fadbc8e72103a Mon Sep 17 00:00:00 2001 From: Harshit Sharma <66710144+harshitethic@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:54:00 -0400 Subject: [PATCH 3/8] fix(analysis): prevent test-like directory names from inflating quality score --- backend/services/analyzer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/services/analyzer.py b/backend/services/analyzer.py index ae17858..d894d3f 100644 --- a/backend/services/analyzer.py +++ b/backend/services/analyzer.py @@ -14,7 +14,12 @@ def analyze(root): paths={e["path"].lower() for e in entries}; names={Path(e["path"]).name.lower() for e in entries} signals={ "readme":any(n.startswith("readme") for n in names), - "tests":any("/test" in p or p.startswith("test") or "/tests/" in p or p.startswith("tests/") for p in paths), + "tests":any( + any(part in {"test", "tests", "__tests__"} for part in p.split("/")[:-1]) + or Path(p).name.startswith(("test_", "test.")) + or Path(p).name.endswith(("_test.py", "_test.go", ".test.js", ".spec.js", ".test.ts", ".spec.ts", ".test.tsx", ".spec.tsx")) + for p in paths + ), "gitignore":".gitignore" in names, "manifest":any(n in names for n in ["package.json","requirements.txt","pyproject.toml","pom.xml","cargo.toml","go.mod","composer.json","gemfile"]), "ci":any(p.startswith(".github/workflows/") for p in paths), From 9fb3481268400f50ead8403ac39b201ff3e12e3a Mon Sep 17 00:00:00 2001 From: Harshit Sharma <66710144+harshitethic@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:54:19 -0400 Subject: [PATCH 4/8] test(analysis): distinguish actual tests from similarly named source files --- backend/tests/test_repository_safety.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/tests/test_repository_safety.py b/backend/tests/test_repository_safety.py index 5c960e4..1579c76 100644 --- a/backend/tests/test_repository_safety.py +++ b/backend/tests/test_repository_safety.py @@ -206,5 +206,16 @@ def test_environment_examples_are_indexed_without_loading_env_secrets(self): self.assertNotIn("REAL_PRIVATE_SETTING", str(analyze(imported))) + def test_test_signal_ignores_unrelated_source_names(self): + imported = self.repos / ("b" * 12) + imported.mkdir() + (imported / "src").mkdir() + (imported / "src" / "testimonials.py").write_text("def describe(): pass") + (imported / "src" / "contest.py").write_text("def compete(): pass") + self.assertFalse(analyze(imported)["signals"]["tests"]) + (imported / "src" / "feature.test.ts").write_text("it('works', () => {})") + self.assertTrue(analyze(imported)["signals"]["tests"]) + + if __name__ == "__main__": unittest.main() \ No newline at end of file From 16e75a2c2c4d0b0b6e7060a505cb9d4b486b4c75 Mon Sep 17 00:00:00 2001 From: Harshit Sharma <66710144+harshitethic@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:54:28 -0400 Subject: [PATCH 5/8] fix(context): rank only content actually included in model excerpts --- backend/services/analyzer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/services/analyzer.py b/backend/services/analyzer.py index d894d3f..64960a8 100644 --- a/backend/services/analyzer.py +++ b/backend/services/analyzer.py @@ -75,7 +75,7 @@ def build_context(root,q,max_files=8,max_chars=18000): tokens={x for x in re.findall(r"[\w-]+", q.casefold()) if len(x)>2}; ranked=[] for p in iter_files(root): text=read_text(p); rel=str(p.relative_to(root)).replace("\\","/") - low=(rel+"\n"+text[:30000]).casefold() + low=(rel+"\n"+text[:4000]).casefold() matched=sum(t in low for t in tokens) bonus=sum(k in rel.casefold() for k in ["readme","app.","main.","index.","route","api"]) if matched or bonus: ranked.append((matched,bonus,rel,text)) From 870d72a4b5b0e0d3bfe6a5c5790f414816836ca0 Mon Sep 17 00:00:00 2001 From: Harshit Sharma <66710144+harshitethic@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:54:38 -0400 Subject: [PATCH 6/8] test(context): selected source must expose its actual matching line --- backend/tests/test_analyzer_edge_cases.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/tests/test_analyzer_edge_cases.py b/backend/tests/test_analyzer_edge_cases.py index 569b845..941ec60 100644 --- a/backend/tests/test_analyzer_edge_cases.py +++ b/backend/tests/test_analyzer_edge_cases.py @@ -103,5 +103,14 @@ def test_context_budget_counts_included_not_considered_files(self): self.assertNotIn("--- FILE: a_large.py", context) + def test_context_selected_file_exposes_the_query_match(self): + self.write("a_hidden.py", "x" * 5000 + "needle_for_context") + self.write("z_visible.py", "needle_for_context = 42") + context = build_context(self.root, "needle_for_context", max_files=1) + self.assertIn("z_visible.py", context) + self.assertIn("needle_for_context = 42", context) + self.assertNotIn("a_hidden.py", context) + + if __name__ == "__main__": unittest.main() From 9a2fb56e476d7bfff58f79514d53a49222026c34 Mon Sep 17 00:00:00 2001 From: Harshit Sharma <66710144+harshitethic@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:54:46 -0400 Subject: [PATCH 7/8] fix(context): avoid irrelevant filename-based fallback for missing query tokens --- backend/services/analyzer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/services/analyzer.py b/backend/services/analyzer.py index 64960a8..e1a946a 100644 --- a/backend/services/analyzer.py +++ b/backend/services/analyzer.py @@ -78,7 +78,7 @@ def build_context(root,q,max_files=8,max_chars=18000): low=(rel+"\n"+text[:4000]).casefold() matched=sum(t in low for t in tokens) bonus=sum(k in rel.casefold() for k in ["readme","app.","main.","index.","route","api"]) - if matched or bonus: ranked.append((matched,bonus,rel,text)) + if matched or (not q.strip() and bonus): ranked.append((matched,bonus,rel,text)) ranked.sort(key=lambda x: (-x[0], -x[1], x[2].casefold(), x[2])); out=""; used=0; selected=0 for _,_,rel,text in ranked: block=f"\n--- FILE: {rel} ---\n{text[:4000]}\n" From 72b917a7b94921f23d7817847840ff051b272bea Mon Sep 17 00:00:00 2001 From: Harshit Sharma <66710144+harshitethic@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:54:55 -0400 Subject: [PATCH 8/8] test(context): no unrelated readme leakage on unmatched queries --- backend/tests/test_analyzer_edge_cases.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/tests/test_analyzer_edge_cases.py b/backend/tests/test_analyzer_edge_cases.py index 941ec60..9f2fcd0 100644 --- a/backend/tests/test_analyzer_edge_cases.py +++ b/backend/tests/test_analyzer_edge_cases.py @@ -112,5 +112,13 @@ def test_context_selected_file_exposes_the_query_match(self): self.assertNotIn("a_hidden.py", context) + def test_unmatched_question_does_not_return_unrelated_readme(self): + self.write("README.md", "setup notes without the requested identifier") + self.write("app.py", "def start(): pass") + context = build_context(self.root, "nonexistent_unique_identifier") + self.assertIn("No strongly matching files", context) + self.assertNotIn("setup notes", context) + + if __name__ == "__main__": unittest.main()