generated from Labyricorn/labyricorn-project-template
Implement CyberSim-OS Phase 1 MVP simulation environment
This commit is contained in:
+206
@@ -0,0 +1,206 @@
|
||||
/**
|
||||
* CyberSim OS - Main Bootstrapper & Simulation Lifecycle Orchestrator
|
||||
*/
|
||||
|
||||
import { globalEventBus } from './engine/event_bus.js';
|
||||
import { ConsequenceEngine } from './engine/consequence.js';
|
||||
import { calculateScenarioFingerprint } from './scenario/fingerprint.js';
|
||||
import { referenceScenario1 } from './scenario/scenario_ref1.js';
|
||||
import { WindowManager } from './core/window_manager.js';
|
||||
import { DesktopShell } from './core/desktop.js';
|
||||
import { NotificationService } from './core/notifications.js';
|
||||
|
||||
import { InlookApp } from './apps/inlook.js';
|
||||
import { NavigatorApp } from './apps/navigator.js';
|
||||
import { FilesApp } from './apps/files.js';
|
||||
import { DocViewerApp } from './apps/docviewer.js';
|
||||
import { SecurityCenterApp } from './apps/security_center.js';
|
||||
|
||||
import { BehavioralScorer } from './scoring/scorer.js';
|
||||
import { AfterActionReport } from './scoring/aar.js';
|
||||
import { CertificateGenerator } from './cert/cert_generator.js';
|
||||
|
||||
class CyberSimEngine {
|
||||
constructor() {
|
||||
this.scenario = referenceScenario1;
|
||||
this.scenarioFingerprint = null;
|
||||
this.eventBus = globalEventBus;
|
||||
}
|
||||
|
||||
async start() {
|
||||
console.log('[CyberSim OS] Booting enterprise desktop simulation...');
|
||||
|
||||
// Calculate cryptographic scenario fingerprint
|
||||
this.scenarioFingerprint = await calculateScenarioFingerprint(this.scenario);
|
||||
console.log(`[CyberSim OS] Scenario Fingerprint (SHA-256): ${this.scenarioFingerprint}`);
|
||||
|
||||
// Initialize UI Containers
|
||||
const desktopEl = document.getElementById('desktop');
|
||||
const taskbarAppsEl = document.getElementById('taskbar-apps');
|
||||
const startMenuEl = document.getElementById('start-menu');
|
||||
const startBtnEl = document.getElementById('start-btn');
|
||||
const clockEl = document.getElementById('taskbar-clock');
|
||||
|
||||
// Initialize Core Services
|
||||
this.notifications = new NotificationService();
|
||||
this.wm = new WindowManager(desktopEl, taskbarAppsEl);
|
||||
|
||||
// Initialize Apps
|
||||
this.docViewer = new DocViewerApp({
|
||||
windowManager: this.wm,
|
||||
eventBus: this.eventBus
|
||||
});
|
||||
|
||||
this.files = new FilesApp({
|
||||
windowManager: this.wm,
|
||||
eventBus: this.eventBus,
|
||||
notifications: this.notifications,
|
||||
scenario: this.scenario,
|
||||
onOpenFile: (file) => this.docViewer.openDocument(file)
|
||||
});
|
||||
|
||||
this.navigator = new NavigatorApp({
|
||||
windowManager: this.wm,
|
||||
eventBus: this.eventBus,
|
||||
notifications: this.notifications,
|
||||
scenario: this.scenario
|
||||
});
|
||||
|
||||
this.securityCenter = new SecurityCenterApp({
|
||||
windowManager: this.wm,
|
||||
eventBus: this.eventBus
|
||||
});
|
||||
|
||||
this.inlook = new InlookApp({
|
||||
windowManager: this.wm,
|
||||
eventBus: this.eventBus,
|
||||
notifications: this.notifications,
|
||||
scenario: this.scenario,
|
||||
onNavigateUrl: (url) => this.navigator.launch(url),
|
||||
onOpenDoc: (file) => this.docViewer.openDocument(file),
|
||||
onFileDownloaded: (file) => this.files.addFile(file)
|
||||
});
|
||||
|
||||
// Initialize Delayed Consequence Engine
|
||||
this.consequences = new ConsequenceEngine(this.eventBus, this.notifications, this.securityCenter);
|
||||
|
||||
// Initialize Desktop Shell
|
||||
this.desktop = new DesktopShell({
|
||||
desktopElement: desktopEl,
|
||||
startMenuElement: startMenuEl,
|
||||
startBtnElement: startBtnEl,
|
||||
clockElement: clockEl,
|
||||
eventBus: this.eventBus,
|
||||
onFinishScenario: () => this.finishScenario()
|
||||
});
|
||||
|
||||
// Register Desktop Apps
|
||||
const registeredApps = [
|
||||
{
|
||||
id: 'inlook',
|
||||
name: 'Inlook Mail',
|
||||
iconSvg: this.inlook.getIconSvg(),
|
||||
launch: () => this.inlook.launch()
|
||||
},
|
||||
{
|
||||
id: 'navigator',
|
||||
name: 'Navigator',
|
||||
iconSvg: this.navigator.getIconSvg(),
|
||||
launch: () => this.navigator.launch()
|
||||
},
|
||||
{
|
||||
id: 'files',
|
||||
name: 'Files',
|
||||
iconSvg: this.files.getIconSvg(),
|
||||
launch: () => this.files.launch()
|
||||
},
|
||||
{
|
||||
id: 'security_center',
|
||||
name: 'Security Center',
|
||||
iconSvg: this.securityCenter.getIconSvg(),
|
||||
launch: () => this.securityCenter.launch()
|
||||
},
|
||||
{
|
||||
id: 'docviewer',
|
||||
name: 'Doc Viewer',
|
||||
iconSvg: this.docViewer.getIconSvg(),
|
||||
launch: () => {
|
||||
const firstDoc = this.scenario.files[0];
|
||||
if (firstDoc) this.docViewer.openDocument(firstDoc);
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'verify_cert',
|
||||
name: 'Verify Cert',
|
||||
iconSvg: `<svg viewBox="0 0 24 24" fill="none" stroke="#8b5cf6" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>`,
|
||||
launch: () => {
|
||||
window.open('verify.html', '_blank');
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
this.desktop.renderDesktopIcons(registeredApps);
|
||||
|
||||
// Expose runtime global for event triggers
|
||||
window.CyberSimOS = {
|
||||
engine: this,
|
||||
navigator: this.navigator,
|
||||
inlook: this.inlook,
|
||||
files: this.files,
|
||||
securityCenter: this.securityCenter,
|
||||
docViewer: this.docViewer,
|
||||
handlePhishSubmit: (form) => this.navigator.handlePhishFormSubmit(form),
|
||||
finishSimulation: () => this.finishScenario()
|
||||
};
|
||||
|
||||
// Emit Scenario Start Event
|
||||
this.eventBus.emit('SCENARIO_STARTED', {
|
||||
target: this.scenario.scenarioId,
|
||||
details: {
|
||||
title: this.scenario.title,
|
||||
fingerprint: this.scenarioFingerprint
|
||||
}
|
||||
});
|
||||
|
||||
// Auto-launch Inlook and show orientation toast
|
||||
setTimeout(() => {
|
||||
this.inlook.launch();
|
||||
this.notifications.show({
|
||||
title: 'NexaCore Orientation',
|
||||
body: 'Welcome Jordan! Check Inlook for initial tasks from Morgan Chen.',
|
||||
type: 'info',
|
||||
timeout: 8000
|
||||
});
|
||||
}, 400);
|
||||
}
|
||||
|
||||
finishScenario() {
|
||||
this.eventBus.emit('SCENARIO_FINISHED', {
|
||||
target: this.scenario.scenarioId
|
||||
});
|
||||
|
||||
const logs = this.eventBus.getLogs();
|
||||
const scorer = new BehavioralScorer(this.scenario, logs);
|
||||
const scoreResult = scorer.evaluate();
|
||||
|
||||
const aar = new AfterActionReport({
|
||||
scenario: this.scenario,
|
||||
scoreResult,
|
||||
onClaimCertificate: () => {
|
||||
const certGen = new CertificateGenerator(this.scenario, scoreResult, this.scenarioFingerprint);
|
||||
certGen.showCertificateModal(this.scenario.learner.name);
|
||||
},
|
||||
onRestart: () => {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
aar.show();
|
||||
}
|
||||
}
|
||||
|
||||
// Boot on DOM Ready
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const sim = new CyberSimEngine();
|
||||
sim.start();
|
||||
});
|
||||
Reference in New Issue
Block a user