mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-02-02 07:23:35 +00:00
refactor: optimize token usage, deduplicate code, fix bugs across agents
Token reduction (~40% per session, ~2.3M fewer tokens per 200-feature project): - Agent-type-specific tool lists: coding 9, testing 5, init 5 (was 19 for all) - Right-sized max_turns: coding 300, testing 100 (was 1000 for all) - Trimmed coding prompt template (~150 lines removed) - Streamlined testing prompt with batch support - YOLO mode now strips browser testing instructions from prompt - Added Grep, WebFetch, WebSearch to expand project session Performance improvements: - Rate limit retries start at ~15s with jitter (was fixed 60s) - Post-spawn delay reduced to 0.5s (was 2s) - Orchestrator consolidated to 1 DB query per loop (was 5-7) - Testing agents batch 3 features per session (was 1) - Smart context compaction preserves critical state, discards noise Bug fixes: - Removed ghost feature_release_testing MCP tool (wasted tokens every test session) - Forward all 9 Vertex AI env vars to chat sessions (was missing 3) - Fix DetachedInstanceError risk in test batch ORM access - Prevent duplicate testing of same features in parallel mode Code deduplication: - _get_project_path(): 9 copies -> 1 shared utility (project_helpers.py) - validate_project_name(): 9 copies -> 2 variants in 1 file (validation.py) - ROOT_DIR: 10 copies -> 1 definition (chat_constants.py) - API_ENV_VARS: 4 copies -> 1 source of truth (env_constants.py) Security hardening: - Unified sensitive directory blocklist (14 dirs, was two divergent lists) - Cached get_blocked_paths() for O(1) directory listing checks - Terminal security warning when ALLOW_REMOTE=1 exposes WebSocket - 20 new security tests for EXTRA_READ_PATHS blocking - Extracted _validate_command_list() and _validate_pkill_processes() helpers Type safety: - 87 mypy errors -> 0 across 58 source files - Installed types-PyYAML for proper yaml stub types - Fixed SQLAlchemy Column[T] coercions across all routers Dead code removed: - 13 files deleted (~2,679 lines): unused UI components, debug logs, outdated docs - 7 unused npm packages removed (Radix UI components with 0 imports) - AgentAvatar.tsx reduced from 615 -> 119 lines (SVGs extracted to mascotData.tsx) New CLI options: - --testing-batch-size (1-5) for parallel mode test batching - --testing-feature-ids for direct multi-feature testing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
32
server/utils/project_helpers.py
Normal file
32
server/utils/project_helpers.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
Project Helper Utilities
|
||||
========================
|
||||
|
||||
Shared project path lookup used across all server routers and websocket handlers.
|
||||
Consolidates the previously duplicated _get_project_path() function.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Ensure the project root is on sys.path so `registry` can be imported.
|
||||
# This is necessary because `registry.py` lives at the repository root,
|
||||
# outside the `server` package.
|
||||
_root = Path(__file__).parent.parent.parent
|
||||
if str(_root) not in sys.path:
|
||||
sys.path.insert(0, str(_root))
|
||||
|
||||
from registry import get_project_path as _registry_get_project_path
|
||||
|
||||
|
||||
def get_project_path(project_name: str) -> Path | None:
|
||||
"""Look up a project's filesystem path from the global registry.
|
||||
|
||||
Args:
|
||||
project_name: The registered name of the project.
|
||||
|
||||
Returns:
|
||||
The resolved ``Path`` to the project directory, or ``None`` if the
|
||||
project is not found in the registry.
|
||||
"""
|
||||
return _registry_get_project_path(project_name)
|
||||
@@ -1,26 +1,52 @@
|
||||
"""
|
||||
Shared validation utilities for the server.
|
||||
Shared Validation Utilities
|
||||
============================
|
||||
|
||||
Project name validation used across REST endpoints and WebSocket handlers.
|
||||
Two variants are provided:
|
||||
|
||||
* ``is_valid_project_name`` -- returns ``bool``, suitable for WebSocket
|
||||
handlers where raising an HTTPException is not appropriate.
|
||||
* ``validate_project_name`` -- raises ``HTTPException(400)`` on failure,
|
||||
suitable for REST endpoint handlers.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
# Compiled once; reused by both variants.
|
||||
_PROJECT_NAME_RE = re.compile(r'^[a-zA-Z0-9_-]{1,50}$')
|
||||
|
||||
|
||||
def is_valid_project_name(name: str) -> bool:
|
||||
"""Check whether *name* is a valid project name.
|
||||
|
||||
Allows only ASCII letters, digits, hyphens, and underscores (1-50 chars).
|
||||
Returns ``True`` if valid, ``False`` otherwise.
|
||||
|
||||
Use this in WebSocket handlers where you need to close the socket
|
||||
yourself rather than raise an HTTP error.
|
||||
"""
|
||||
return bool(_PROJECT_NAME_RE.match(name))
|
||||
|
||||
|
||||
def validate_project_name(name: str) -> str:
|
||||
"""
|
||||
Validate and sanitize project name to prevent path traversal.
|
||||
"""Validate and return *name*, or raise ``HTTPException(400)``.
|
||||
|
||||
Suitable for REST endpoint handlers where FastAPI will convert the
|
||||
exception into an HTTP 400 response automatically.
|
||||
|
||||
Args:
|
||||
name: Project name to validate
|
||||
name: Project name to validate.
|
||||
|
||||
Returns:
|
||||
The validated project name
|
||||
The validated project name (unchanged).
|
||||
|
||||
Raises:
|
||||
HTTPException: If name is invalid
|
||||
HTTPException: If *name* is invalid.
|
||||
"""
|
||||
if not re.match(r'^[a-zA-Z0-9_-]{1,50}$', name):
|
||||
if not _PROJECT_NAME_RE.match(name):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Invalid project name. Use only letters, numbers, hyphens, and underscores (1-50 chars)."
|
||||
|
||||
Reference in New Issue
Block a user