Run code linting tools with agent-appropriate guidance.
(arguments: dict[str, Any], project_root: Path)
| 1462 | |
| 1463 | |
| 1464 | async def lint_code(arguments: dict[str, Any], project_root: Path) -> CallToolResult: |
| 1465 | """Run code linting tools with agent-appropriate guidance.""" |
| 1466 | tool = arguments.get("tool", "bash_lint") |
| 1467 | agent_type = arguments.get("agent_type", "foreground") |
| 1468 | fix = arguments.get("fix", False) |
| 1469 | |
| 1470 | results: list[str] = [] |
| 1471 | |
| 1472 | # Provide guidance based on agent type |
| 1473 | if agent_type == "foreground" and tool != "bash_lint": |
| 1474 | guidance = "⚠️ FOREGROUND AGENT GUIDANCE:\n" |
| 1475 | guidance += "For comprehensive linting, foreground agents should use 'bash_lint' tool option.\n" |
| 1476 | guidance += "This ensures all linting (Python, C++, JavaScript) runs in proper sequence.\n\n" |
| 1477 | results.append(guidance) |
| 1478 | |
| 1479 | # Handle different tool options |
| 1480 | if tool == "bash_lint" or tool == "all": |
| 1481 | # Use the comprehensive bash lint script |
| 1482 | lint_script = project_root / "lint" |
| 1483 | if lint_script.exists(): |
| 1484 | result = await run_command(["bash", "lint"], project_root) |
| 1485 | results.append(f"🚀 Comprehensive Linting Results (bash lint):\n{result}") |
| 1486 | else: |
| 1487 | return CallToolResult( |
| 1488 | content=[ |
| 1489 | TextContent(type="text", text="[ERROR] bash lint script not found") |
| 1490 | ], |
| 1491 | isError=True, |
| 1492 | ) |
| 1493 | |
| 1494 | elif tool == "ruff": |
| 1495 | # Python-only linting for background agents |
| 1496 | cmd = ["uv", "run", "ruff", "check"] |
| 1497 | if fix: |
| 1498 | cmd.append("--fix") |
| 1499 | result = await run_command(cmd, project_root) |
| 1500 | results.append(f"📝 Python Linting (ruff):\n{result}") |
| 1501 | |
| 1502 | if agent_type == "background": |
| 1503 | results.append( |
| 1504 | "\n💡 Background Agent: Consider running 'bash_lint' for comprehensive coverage." |
| 1505 | ) |
| 1506 | |
| 1507 | elif tool == "javascript": |
| 1508 | # JavaScript-only linting for background agents |
| 1509 | lint_js_script = project_root / "ci" / "js" / "lint-js" |
| 1510 | check_js_script = project_root / "ci" / "js" / "check-js" |
| 1511 | |
| 1512 | if lint_js_script.exists(): |
| 1513 | result = await run_command(["ci/js/lint-js"], project_root) |
| 1514 | results.append(f"🌐 JavaScript Linting:\n{result}") |
| 1515 | |
| 1516 | if check_js_script.exists(): |
| 1517 | result = await run_command(["ci/js/check-js"], project_root) |
| 1518 | results.append(f"🔍 JavaScript Type Checking:\n{result}") |
| 1519 | else: |
| 1520 | results.append( |
| 1521 | "[ERROR] JavaScript linting tools not found. Run: uv run ci/setup-js-linting.py" |
no test coverage detected