From 9b198ec793e877b586b9e46658da82ed10ed8c9d Mon Sep 17 00:00:00 2001 From: gszep Date: Mon, 16 Feb 2026 22:10:47 +0900 Subject: [PATCH] fix: validate file extensions in python_check before running linters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reject non-Python files (.ts, .js, etc.) upfront in PythonChecker.check_files() instead of feeding them to ruff/pyright. When called on TypeScript files, linters produced 228K+ chars of garbage output that exhausted the Claude CLI context budget. Non-Python files now get a clear info-level message while directories and .py/.pyi files pass through normally. The validation sits in the shared checker code path, protecting all callers (tool, hook, CLI). 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com> --- src/amplifier_bundle_python_dev/checker.py | 48 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/amplifier_bundle_python_dev/checker.py b/src/amplifier_bundle_python_dev/checker.py index 7f64a85..55af209 100644 --- a/src/amplifier_bundle_python_dev/checker.py +++ b/src/amplifier_bundle_python_dev/checker.py @@ -36,9 +36,55 @@ def check_files(self, paths: list[str | Path], fix: bool = False) -> CheckResult if not paths: paths = [Path.cwd()] - path_strs = [str(p) for p in paths] + # Filter out non-Python files to prevent running linters on wrong file types. + # When called on e.g. TypeScript files, ruff/pyright produce massive garbage + # output (228K+ chars) that can exhaust context budgets. + python_extensions = {".py", ".pyi"} + valid_paths: list[str] = [] + skipped_files: list[str] = [] + for p in paths: + path = Path(p) + if path.is_dir() or path.suffix in python_extensions: + valid_paths.append(str(path)) + else: + skipped_files.append(str(path)) + + if not valid_paths: + return CheckResult( + issues=[ + Issue( + file="", + line=0, + column=0, + code="NON-PYTHON", + message=( + f"No Python files to check. " + f"Skipped {len(skipped_files)} non-Python file(s): " + f"{', '.join(skipped_files)}. " + f"python_check only supports .py and .pyi files." + ), + severity=Severity.INFO, + source="python-check", + ) + ], + ) + + path_strs = valid_paths results = CheckResult(files_checked=self._count_python_files(path_strs)) + if skipped_files: + results.issues.append( + Issue( + file="", + line=0, + column=0, + code="NON-PYTHON", + message=(f"Skipped {len(skipped_files)} non-Python file(s): {', '.join(skipped_files)}"), + severity=Severity.INFO, + source="python-check", + ) + ) + if self.config.enable_ruff_format: format_result = self._run_ruff_format(path_strs, fix=fix) results = results.merge(format_result)