Files
blackroad-operating-system/core_os/state.py
Claude e84407660d feat: scaffold BlackRoad OS Phase 2 infrastructure
Implements complete Phase 2 scaffold across 6 core modules:

## New Modules

### 1. Backend API Enhancements
- Add system router with /version, /config/public, /os/state endpoints
- Register system router in main.py
- Add comprehensive tests for system endpoints

### 2. Core OS Runtime (core_os/)
- Implement UserSession, Window, OSState models
- Add state management functions (open_window, close_window, etc.)
- Create Backend API adapter for communication
- Include full test suite for models and state

### 3. Operator Engine (operator_engine/)
- Build job registry with example jobs
- Implement simple scheduler with lifecycle management
- Optional HTTP server on port 8001
- Complete tests for jobs and scheduler

### 4. Web Client Enhancements
- Add CoreOSClient JavaScript class
- Integrate system API endpoints
- Event-driven architecture for state updates
- Zero dependencies, vanilla JavaScript

### 5. Prism Console (prism-console/)
- Modern dark-themed admin UI
- Multi-tab navigation (Overview, Jobs, Agents, Logs, System)
- Real-time metrics dashboard
- Backend API integration with auto-refresh

### 6. Documentation (codex-docs/)
- Complete MkDocs-based documentation
- Architecture guides and component docs
- Infrastructure setup guides
- API reference documentation

## CI/CD

- Add core-os-tests.yml workflow
- Add operator-tests.yml workflow
- Add docs-build.yml workflow

## Documentation

- Create BLACKROAD_OS_REPO_MAP.md cross-reference
- Add README for each module
- Comprehensive integration documentation

## Summary

- 37 new files created
- ~3,500 lines of new code
- 5 test suites with 15+ tests
- 3 new CI workflows
- 10+ documentation pages

All modules are minimal working skeletons ready for integration.
Designed to be extracted into separate repos if needed.

Phase 2 scaffold complete and ready for review.
2025-11-18 03:47:13 +00:00

171 lines
3.9 KiB
Python

"""Core OS state management"""
from typing import Optional, List
import copy
from core_os.models import OSState, Window, UserSession, WindowState
# Global in-memory state (in production, this would be in Redis/DB)
_current_state: Optional[OSState] = None
def get_initial_state() -> OSState:
"""
Get initial OS state
Returns:
Fresh OSState with default configuration
"""
global _current_state
if _current_state is None:
_current_state = OSState(
session=UserSession(display_name="BlackRoad User"),
desktop_items=[
{
"id": "my-computer",
"label": "My Computer",
"icon": "🖥️",
"app_id": "computer",
},
{
"id": "prism-console",
"label": "Prism Console",
"icon": "",
"app_id": "prism",
},
{
"id": "lucidia",
"label": "Lucidia",
"icon": "🧠",
"app_id": "lucidia",
},
],
taskbar_items=[
{"id": "start-menu", "label": "Start", "icon": "🪟"},
],
system_tray_items=[
{"id": "network", "icon": "🌐", "status": "connected"},
{"id": "volume", "icon": "🔊", "status": "on"},
{"id": "clock", "icon": "🕐", "status": "active"},
],
)
return _current_state
def get_current_state() -> OSState:
"""Get current OS state (or initialize if not exists)"""
return get_initial_state()
def open_window(app_id: str, title: Optional[str] = None) -> OSState:
"""
Open a new window for the specified app
Args:
app_id: Application identifier
title: Window title (optional, defaults to app_id)
Returns:
Updated OS state
"""
state = get_current_state()
# Create new window
window = Window(
app_id=app_id,
title=title or app_id.replace("-", " ").title(),
z_index=len(state.windows),
)
# Add to windows list
state.windows.append(window)
state.active_window_id = window.id
return state
def close_window(window_id: str) -> OSState:
"""
Close a window
Args:
window_id: Window identifier
Returns:
Updated OS state
"""
state = get_current_state()
# Find and remove window
state.windows = [w for w in state.windows if w.id != window_id]
# Update active window if needed
if state.active_window_id == window_id:
state.active_window_id = state.windows[0].id if state.windows else None
return state
def minimize_window(window_id: str) -> OSState:
"""
Minimize a window
Args:
window_id: Window identifier
Returns:
Updated OS state
"""
state = get_current_state()
for window in state.windows:
if window.id == window_id:
window.state = WindowState.MINIMIZED
break
return state
def maximize_window(window_id: str) -> OSState:
"""
Maximize a window
Args:
window_id: Window identifier
Returns:
Updated OS state
"""
state = get_current_state()
for window in state.windows:
if window.id == window_id:
window.state = WindowState.MAXIMIZED
break
return state
def set_active_window(window_id: str) -> OSState:
"""
Set the active (focused) window
Args:
window_id: Window identifier
Returns:
Updated OS state
"""
state = get_current_state()
state.active_window_id = window_id
return state
def reset_state() -> OSState:
"""Reset OS state to initial state"""
global _current_state
_current_state = None
return get_initial_state()