fix: make CLI robust to missing coordinator dependencies

- Replace hardcoded absolute paths with project-relative resolution
- Add AITBC_SERVICES_PATH environment variable override
- Wrap service imports in try/except with graceful degradation
- Add aiohttp to CLI requirements
- Create missing README.md for aitbc-agent-sdk to fix poetry build
- Make run_all_tests.sh portable with PROJECT_ROOT calculation
- Fix enterprise_integration.py path handling

CLI now loads successfully even when coordinator-api services
are not installed. Advanced commands fail with helpful hints
instead of crashing the entire CLI.
This commit is contained in:
aitbc1
2026-03-13 11:34:30 +00:00
parent 3a711d4e33
commit 1feeadf8d2
9 changed files with 280 additions and 55 deletions

View File

@@ -10,14 +10,52 @@ import json
from typing import Optional, List, Dict, Any
from datetime import datetime
# Import AI surveillance system
# Import AI surveillance system with robust path resolution
import os
import sys
sys.path.append('/home/oib/windsurf/aitbc/apps/coordinator-api/src/app/services')
from ai_surveillance import (
start_ai_surveillance, stop_ai_surveillance, get_surveillance_summary,
get_user_risk_profile, list_active_alerts, analyze_behavior_patterns,
ai_surveillance, SurveillanceType, RiskLevel, AlertPriority
)
_services_path = os.environ.get('AITBC_SERVICES_PATH')
if _services_path:
if os.path.isdir(_services_path):
if _services_path not in sys.path:
sys.path.insert(0, _services_path)
else:
print(f"Warning: AITBC_SERVICES_PATH set but not a directory: {_services_path}", file=sys.stderr)
else:
_project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
_computed_services = os.path.join(_project_root, 'apps', 'coordinator-api', 'src', 'app', 'services')
if os.path.isdir(_computed_services) and _computed_services not in sys.path:
sys.path.insert(0, _computed_services)
else:
_fallback = '/home/oib/windsurf/aitbc/apps/coordinator-api/src/app/services'
if os.path.isdir(_fallback) and _fallback not in sys.path:
sys.path.insert(0, _fallback)
try:
from ai_surveillance import (
start_ai_surveillance, stop_ai_surveillance, get_surveillance_summary,
get_user_risk_profile, list_active_alerts, analyze_behavior_patterns,
ai_surveillance, SurveillanceType, RiskLevel, AlertPriority
)
_import_error = None
except ImportError as e:
_import_error = e
def _missing(*args, **kwargs):
raise ImportError(
f"Required service module 'ai_surveillance' could not be imported: {_import_error}. "
"Ensure coordinator-api dependencies are installed or set AITBC_SERVICES_PATH."
)
start_ai_surveillance = stop_ai_surveillance = get_surveillance_summary = _missing
get_user_risk_profile = list_active_alerts = analyze_behavior_patterns = _missing
ai_surveillance = None
class SurveillanceType:
pass
class RiskLevel:
pass
class AlertPriority:
pass
@click.group()
def ai_surveillance_group():