Files
blackroad-operating-system/backend/static/js/core-os-client.js
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

145 lines
3.4 KiB
JavaScript

/**
* BlackRoad Core OS Client
*
* JavaScript client for interacting with the Core OS Runtime via the backend API.
* Provides OS state management, window control, and real-time updates.
*
* @version 0.1.0
*/
class CoreOSClient {
constructor(baseUrl = '') {
this.baseUrl = baseUrl;
this.state = null;
this.listeners = {};
}
/**
* Get system version information
* @returns {Promise<Object>} Version info
*/
async getVersion() {
const response = await fetch(`${this.baseUrl}/api/system/version`);
if (!response.ok) {
throw new Error(`Failed to get version: ${response.statusText}`);
}
return response.json();
}
/**
* Get public configuration
* @returns {Promise<Object>} Public config
*/
async getPublicConfig() {
const response = await fetch(`${this.baseUrl}/api/system/config/public`);
if (!response.ok) {
throw new Error(`Failed to get config: ${response.statusText}`);
}
return response.json();
}
/**
* Get current OS state
* @returns {Promise<Object>} OS state
*/
async getOSState() {
const response = await fetch(`${this.baseUrl}/api/system/os/state`);
if (!response.ok) {
throw new Error(`Failed to get OS state: ${response.statusText}`);
}
this.state = await response.json();
this.emit('state:updated', this.state);
return this.state;
}
/**
* Initialize the OS (get initial state and config)
* @returns {Promise<Object>} Initialization result
*/
async initialize() {
try {
const [version, config, state] = await Promise.all([
this.getVersion(),
this.getPublicConfig(),
this.getOSState(),
]);
const result = {
version,
config,
state,
initialized: true,
};
this.emit('os:initialized', result);
return result;
} catch (error) {
console.error('Failed to initialize Core OS:', error);
this.emit('os:error', { error: error.message });
throw error;
}
}
/**
* Check if backend is healthy
* @returns {Promise<boolean>} Health status
*/
async healthCheck() {
try {
const response = await fetch(`${this.baseUrl}/health`);
return response.ok;
} catch (error) {
return false;
}
}
/**
* Event listener registration
* @param {string} event - Event name
* @param {Function} callback - Callback function
*/
on(event, callback) {
if (!this.listeners[event]) {
this.listeners[event] = [];
}
this.listeners[event].push(callback);
}
/**
* Remove event listener
* @param {string} event - Event name
* @param {Function} callback - Callback function
*/
off(event, callback) {
if (!this.listeners[event]) return;
this.listeners[event] = this.listeners[event].filter(cb => cb !== callback);
}
/**
* Emit event to listeners
* @param {string} event - Event name
* @param {*} data - Event data
*/
emit(event, data) {
if (!this.listeners[event]) return;
this.listeners[event].forEach(callback => callback(data));
}
/**
* Get local OS state (cached)
* @returns {Object|null} Cached state
*/
getLocalState() {
return this.state;
}
}
// Export for use in other modules
window.CoreOSClient = CoreOSClient;
// Create global instance
window.coreOS = new CoreOSClient();
// Log when loaded
console.log('Core OS Client loaded (v0.1.0)');