refactor: codebase optimization - module decomposition, test dedup, type safety#28
Merged
dimakis merged 7 commits intorefactor/large-file-decompositionfrom Feb 14, 2026
Conversation
Move BaseAgent and AgentContext to agents/base.py (canonical location). Add LibrarianAgent to agents/librarian.py alongside LibrarianWorkflow. Slim agents/__init__.py from 502 to ~50 lines of pure re-exports. Update test patch targets from src.agents -> src.agents.base. Co-authored-by: Cursor <cursoragent@cursor.com>
Move get_all_tools() and get_architect_tools() with caching logic to tools/registry.py. Slim tools/__init__.py from 212 to ~100 lines of pure imports and re-exports. Co-authored-by: Cursor <cursoragent@cursor.com>
Create tests/helpers/auth.py with make_test_settings() and make_test_jwt() to replace duplicated _make_settings/_make_jwt across 12 test files. Eliminates ~360 lines of copy-pasted auth setup code. Co-authored-by: Cursor <cursoragent@cursor.com>
Use asyncio.Event that is never set instead of asyncio.sleep(10) to simulate slow tools. This avoids risking the 10s pytest timeout if the timeout mechanism itself fails, while achieving the same blocking behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
…ride list Add proper type annotations to registry.py (list -> list[Any]). Import from canonical source modules to fix attr-defined errors. Remove 5 modules from mypy overrides that now pass strict checking (settings, llm, tracing.mlflow). 0 mypy errors across 271 files. Co-authored-by: Cursor <cursoragent@cursor.com>
Auto-fix ruff I001 import sorting across 7 files. Add list_automations and render_template to tools/__init__.py __all__. Co-authored-by: Cursor <cursoragent@cursor.com>
Update 5 agent sub-modules to import BaseAgent from src.agents.base instead of src.agents (the package __init__). This breaks the circular dependency chain: __init__ imports sub-modules, sub-modules imported from __init__. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BaseAgent/AgentContexttoagents/base.pyand mergeLibrarianAgentintoagents/librarian.py; slimagents/__init__.pyfrom 502 to ~50 lines of pure re-exportsget_all_tools,get_architect_tools) totools/registry.py; slimtools/__init__.pyfrom 212 to ~100 linestests/helpers/auth.pyeliminating ~360 lines of duplicated auth setup across 12 test filesasyncio.sleep(10)in timeout tests withasyncio.Event().wait()patternregistry.py, remove 5 modules from mypy strict override listMotivation
Architecture review identified bloated
__init__.pyfiles with substantial logic, duplicated test helpers, unsafe test patterns, and mypy debt. This PR addresses the highest-impact structural issues.Type of Change
refactor— Code restructuring (no feature or fix)test— Adding or updating testsfix— Bug fix (circular import, asyncio.sleep safety)Changes
BaseAgent(431 lines) andAgentContextto canonicalagents/base.py. AddedLibrarianAgentto existingagents/librarian.py. Updated 5 agent sub-modules to import fromagents.basedirectly, breaking circular import chain.get_all_tools()andget_architect_tools()(with caching) totools/registry.py. Fixed mypy type annotations (list->list[Any]). Fixedattr-definederrors by importing from canonical source modules.make_test_settings()andmake_test_jwt(). Updated 12 test files to use shared helpers.asyncio.sleep(10)withasyncio.Event().wait()in 2 timeout test files.Testing
Security Considerations
Checklist
Made with Cursor