CarlBot

Instructions for Future AI Coding Agents

Mission

Build and extend a deterministic, safe CCTV technical-support lab with a production-grade Operations console. Never connect to production or customer infrastructure.


Core Rules Before Modifying Code

  1. Read README.md, AUTONOMOUS_AGENT_LAB.md, SETUP_AND_DEVELOPMENT.md, and this file.
  2. Inspect existing backend APIs (services/*/app.py) and frontend clients (frontend/src/api/*.ts) before modifying behavior.
  3. Keep simulator state fake and local under data/runtime/.
  4. Run full validation after every change:
    python -m pytest -q
    python -m ruff check .
    cd frontend && npm test && npm run build
    

Backend Architecture Rules


Frontend Architecture Rules


Adding a New Fault

  1. Add the fault identifier to SUPPORTED_FAULTS in services/portal/app.py.
  2. Add its state transformation in _effective_state() in services/portal/app.py.
  3. Add diagnosis logic in diagnose() and investigate_single_asset() in services/agent/agent.py.
  4. If auto-recoverable, add it to FAULT_TO_ACTION and FAULT_VERIFICATION.
  5. If auto-recoverable, add the corresponding action to ALLOWED_ACTIONS in the portal.
  6. Categorize the safety class using services/agent/policy.py.
  7. Add runbook documentation in data/knowledge/troubleshooting.md.
  8. Add frontend fault simulation shortcut in frontend/src/components/layout/LabControlsModal.tsx.
  9. Add regression and recovery/escalation tests in tests/test_lab.py and frontend tests if applicable.

Adding a New Frontend Page

  1. Create page component in frontend/src/pages/YourPage.tsx.
  2. Register route in frontend/src/App.tsx.
  3. Add navigation link with Lucide icon in frontend/src/components/layout/Sidebar.tsx.
  4. Write test in frontend/src/test/ to verify rendering and data display.

Key Files Reference

File Purpose
services/common/config.py Central configuration and ports
services/common/models.py Shared Pydantic models and enums
services/helpdesk/app.py Helpdesk REST API (Port 8001)
services/portal/app.py Operations Portal REST API (Port 8002)
services/agent/agent.py Autonomous agent core loop & single asset investigation
services/agent/policy.py Safety policy engine (Authoritative)
services/agent/knowledge.py Knowledge retrieval layer & doc endpoints
services/agent/reasoning.py LLM boundary contract
services/agent/app.py Agent API endpoints (Port 8003)
frontend/src/App.tsx Frontend routes and layout container
frontend/src/context/LabContext.tsx Real-time telemetry, polling, and fault management
frontend/src/components/timeline/InvestigationTimeline.tsx Diagnostic evidence and step breakdown
frontend/src/components/topology/TopologyGraph.tsx Network hierarchy and correlated outage visualizer
frontend/src/components/chat/ChatContainer.tsx AI Assistant conversational console & slash parser
tests/test_lab.py Backend comprehensive test suite (60 tests)
frontend/src/test/ Frontend Vitest test suites (19 tests)
data/knowledge/ Authoritative troubleshooting documents (Markdown)
data/runtime/ Generated simulator state files (gitignored)