diff --git a/Aetheria.Rts.Web/Client/aetheria-rts-contract.ts b/Aetheria.Rts.Web/Client/aetheria-rts-contract.ts index a33ac9b09..52a63c5fc 100644 --- a/Aetheria.Rts.Web/Client/aetheria-rts-contract.ts +++ b/Aetheria.Rts.Web/Client/aetheria-rts-contract.ts @@ -417,8 +417,6 @@ export type AetheriaRtsApi = { surfaceCatalogIndex(): Promise; eveSurface(request: AetheriaEveSurfaceRequest): Promise; submitEveCommand(request: AetheriaEveCommandRequest): Promise; - debugSurface(): Promise; - watchDebugSurface(callback: (surface: AetheriaMenuSurfaceDocument) => void): () => void; windowControl(action: "minimize" | "maximize" | "close"): Promise; health(): Promise; }; diff --git a/Aetheria.Rts.Web/Electron/aetheria-rts-generated-bindings.ts b/Aetheria.Rts.Web/Electron/aetheria-rts-generated-bindings.ts index 0d0035ee3..e26263154 100644 --- a/Aetheria.Rts.Web/Electron/aetheria-rts-generated-bindings.ts +++ b/Aetheria.Rts.Web/Electron/aetheria-rts-generated-bindings.ts @@ -130,10 +130,6 @@ export const AetheriaRtsIpcChannels = { surfaceCatalogIndex: "aetheria-rts:surface-catalog-index", eveSurface: "aetheria-rts:eve-surface", submitEveCommand: "aetheria-rts:submit-eve-command", - debugSurface: "aetheria-rts:debug-surface", - debugSurfaceWatch: "aetheria-rts:debug-surface-watch", - debugSurfaceWatchStop: "aetheria-rts:debug-surface-watch-stop", - debugSurfaceChanged: "aetheria-rts:debug-surface-changed", windowControl: "aetheria-rts:window-control", health: "aetheria-rts:health", } as const; diff --git a/Aetheria.Rts.Web/Electron/main.ts b/Aetheria.Rts.Web/Electron/main.ts index 80a135246..b9b9cfc5e 100644 --- a/Aetheria.Rts.Web/Electron/main.ts +++ b/Aetheria.Rts.Web/Electron/main.ts @@ -1,16 +1,12 @@ -import { app, BrowserWindow, ipcMain, shell, type WebContents } from "electron"; +import { app, BrowserWindow, ipcMain, shell } from "electron"; import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process"; -import { createWriteStream, existsSync, mkdirSync, readdirSync, readFileSync, statSync, watch, writeFileSync, type FSWatcher } from "node:fs"; +import { createWriteStream, existsSync, mkdirSync, readdirSync, statSync, writeFileSync } from "node:fs"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { AetheriaCultMeshClient, } from "./aetheria-cultmesh.js"; -import type { - AetheriaMenuSurfaceComponent, - AetheriaMenuSurfaceDocument, -} from "./aetheria-cultmesh.js"; import { registerAetheriaRtsIpcHandlers } from "./aetheria-rts-generated-bindings.js"; const __dirname = dirname(fileURLToPath(import.meta.url)); @@ -19,7 +15,6 @@ const repoRoot = resolve(projectRoot, ".."); const logsRoot = resolve(projectRoot, "logs"); const runtimeRoot = resolve(process.env.AETHERIA_RUNTIME_ROOT ?? resolve(projectRoot, "runtime")); const runtimeStatePath = resolve(runtimeRoot, "aetheria.cc"); -const debugSurfacePath = resolve(process.env.AETHERIA_CULTUI_DEBUG_SURFACE_PATH ?? resolve(repoRoot, "GameData", "cultui-debug-surface.cultui")); const daemonDll = resolve(repoRoot, "Aetheria.State.Daemon", "bin", "Debug", "net10.0", "Aetheria.State.Daemon.dll"); const rendererIndex = resolve(projectRoot, "wwwroot", "index.html"); const clientCultMeshPort = Number.parseInt(process.env.AETHERIA_CLIENT_CULTMESH_PORT ?? "3076", 10); @@ -37,44 +32,6 @@ let daemonProcess: ChildProcessWithoutNullStreams | null = null; let mainWindow: BrowserWindow | null = null; let aetheriaClient: AetheriaCultMeshClient | null = null; let isQuitting = false; -let debugSurfaceWatcher: FSWatcher | null = null; -let debugSurfaceWatchTimer: NodeJS.Timeout | null = null; -const debugSurfaceSubscriptions = new Map(); - -type AetheriaFileSurfaceDocument = { - readonly schema?: string; - readonly providerId?: string; - readonly providerKind?: string; - readonly title?: string; - readonly version?: number; - readonly updatedAtUtc?: string; - readonly surface?: AetheriaFileSurfaceTree; - readonly commands?: readonly AetheriaFileCommand[]; -}; - -type AetheriaFileSurfaceTree = { - readonly id?: string; - readonly root?: AetheriaFileSurfaceComponent; - readonly styles?: readonly AetheriaFileStyleToken[]; -}; - -type AetheriaFileSurfaceComponent = { - readonly id?: string; - readonly kind?: string; - readonly props?: unknown; - readonly children?: readonly AetheriaFileSurfaceComponent[]; -}; - -type AetheriaFileStyleToken = { - readonly name?: string; - readonly value?: string; -}; - -type AetheriaFileCommand = { - readonly command?: string; - readonly label?: string; - readonly transport?: string; -}; app.whenReady().then(async () => { mainWindow = createWindow(); @@ -152,7 +109,6 @@ app.on("before-quit", () => { isQuitting = true; void aetheriaClient?.close(); stopChild(daemonProcess); - closeDebugSurfaceWatcher(); }); function createWindow(): BrowserWindow { @@ -356,26 +312,6 @@ function registerIpc(): void { daemonRunning: daemonProcess != null && !daemonProcess.killed, daemonMode: launchLocalDaemon ? "local" : "remote", })); - ipcMain.handle("aetheria-rts:debug-surface", () => readDebugSurface()); - ipcMain.handle("aetheria-rts:debug-surface-watch", (event, subscriptionId: string) => { - if (!subscriptionId) - throw new Error("Debug surface subscription id is required."); - - debugSurfaceSubscriptions.set(subscriptionId, event.sender); - event.sender.once("destroyed", () => { - debugSurfaceSubscriptions.delete(subscriptionId); - stopDebugSurfaceWatcherIfIdle(); - }); - ensureDebugSurfaceWatcher(); - event.sender.send("aetheria-rts:debug-surface-changed", { - subscriptionId, - surface: readDebugSurface(), - }); - }); - ipcMain.handle("aetheria-rts:debug-surface-watch-stop", (_event, subscriptionId: string) => { - debugSurfaceSubscriptions.delete(subscriptionId); - stopDebugSurfaceWatcherIfIdle(); - }); ipcMain.handle("aetheria-rts:window-control", (event, action: string) => { const window = BrowserWindow.fromWebContents(event.sender); if (!window) @@ -400,140 +336,6 @@ function registerIpc(): void { }); } -function readDebugSurface(): AetheriaMenuSurfaceDocument { - if (!existsSync(debugSurfacePath)) { - throw new Error(`CultUI debug surface file not found: ${debugSurfacePath}`); - } - - const document = JSON.parse(readFileSync(debugSurfacePath, "utf8")) as AetheriaFileSurfaceDocument; - return normalizeDebugSurface(document); -} - -function ensureDebugSurfaceWatcher(): void { - if (debugSurfaceWatcher) - return; - - debugSurfaceWatcher = watch(debugSurfacePath, { persistent: false }, () => { - if (debugSurfaceWatchTimer) - clearTimeout(debugSurfaceWatchTimer); - debugSurfaceWatchTimer = setTimeout(publishDebugSurfaceChange, 50); - }); - debugSurfaceWatcher.once("error", error => { - console.warn(`CultUI debug surface watcher failed for ${debugSurfacePath}:`, error); - closeDebugSurfaceWatcher(); - }); -} - -function publishDebugSurfaceChange(): void { - debugSurfaceWatchTimer = null; - let surface: AetheriaMenuSurfaceDocument; - try { - surface = readDebugSurface(); - } catch (error) { - console.warn(error instanceof Error ? error.message : String(error)); - return; - } - - for (const [subscriptionId, webContents] of debugSurfaceSubscriptions) { - if (webContents.isDestroyed()) { - debugSurfaceSubscriptions.delete(subscriptionId); - continue; - } - - webContents.send("aetheria-rts:debug-surface-changed", { subscriptionId, surface }); - } - stopDebugSurfaceWatcherIfIdle(); -} - -function stopDebugSurfaceWatcherIfIdle(): void { - if (debugSurfaceSubscriptions.size === 0) - closeDebugSurfaceWatcher(); -} - -function closeDebugSurfaceWatcher(): void { - if (debugSurfaceWatchTimer) { - clearTimeout(debugSurfaceWatchTimer); - debugSurfaceWatchTimer = null; - } - debugSurfaceWatcher?.close(); - debugSurfaceWatcher = null; -} - -function normalizeDebugSurface(document: AetheriaFileSurfaceDocument): AetheriaMenuSurfaceDocument { - const surfaceId = stringOr(document.surface?.id, "aetheria.debug.file_surface"); - return { - providerId: stringOr(document.providerId, "aetheria.debug"), - providerKind: stringOr(document.providerKind, "debug.file_surface"), - title: stringOr(document.title, "Aetheria Debug Surface"), - version: typeof document.version === "number" && Number.isFinite(document.version) - ? document.version - : Date.now(), - updatedAtUtc: stringOr(document.updatedAtUtc, new Date().toISOString()), - surface: { - id: surfaceId, - root: normalizeDebugComponent(document.surface?.root, `${surfaceId}.root`), - styles: Array.isArray(document.surface?.styles) - ? document.surface.styles.map(token => ({ - name: stringOr(token.name, ""), - value: stringOr(token.value, ""), - })) - : [], - }, - commands: Array.isArray(document.commands) - ? document.commands.map(command => ({ - command: stringOr(command.command, ""), - label: stringOr(command.label, command.command ?? ""), - transport: stringOr(command.transport, "debug-log"), - })) - : [], - }; -} - -function normalizeDebugComponent( - component: AetheriaFileSurfaceComponent | undefined, - fallbackId: string, -): AetheriaMenuSurfaceComponent { - if (!component) { - return { - id: fallbackId, - kind: "surface", - props: {}, - children: [], - }; - } - - return { - id: stringOr(component.id, fallbackId), - kind: stringOr(component.kind, "surface"), - props: normalizeDebugProps(component.props), - children: Array.isArray(component.children) - ? component.children.map((child, index) => normalizeDebugComponent(child, `${fallbackId}.${index}`)) - : [], - }; -} - -function normalizeDebugProps(props: unknown): Record { - if (Array.isArray(props)) { - return Object.fromEntries( - props - .map(prop => objectValue(prop)) - .filter(prop => prop && typeof prop.key === "string") - .map(prop => [String(prop!.key), stringOr(prop!.value, "")])); - } - - if (props != null && typeof props === "object") { - return Object.fromEntries( - Object.entries(props as Record) - .map(([key, value]) => [key, stringOr(value, "")])); - } - - return {}; -} - -function stringOr(value: unknown, fallback: string): string { - return typeof value === "string" ? value : fallback; -} - function requireClient(): AetheriaCultMeshClient { if (!aetheriaClient) throw new Error("Aetheria CultMesh client is not initialized."); diff --git a/Aetheria.Rts.Web/Electron/preload.cjs b/Aetheria.Rts.Web/Electron/preload.cjs index c58fc1390..f4e87bc9f 100644 --- a/Aetheria.Rts.Web/Electron/preload.cjs +++ b/Aetheria.Rts.Web/Electron/preload.cjs @@ -23,10 +23,6 @@ const channels = { surfaceCatalogIndex: "aetheria-rts:surface-catalog-index", eveSurface: "aetheria-rts:eve-surface", submitEveCommand: "aetheria-rts:submit-eve-command", - debugSurface: "aetheria-rts:debug-surface", - debugSurfaceWatch: "aetheria-rts:debug-surface-watch", - debugSurfaceWatchStop: "aetheria-rts:debug-surface-watch-stop", - debugSurfaceChanged: "aetheria-rts:debug-surface-changed", windowControl: "aetheria-rts:window-control", health: "aetheria-rts:health", }; @@ -62,21 +58,6 @@ contextBridge.exposeInMainWorld("aetheriaRts", { surfaceCatalogIndex: () => ipcRenderer.invoke(channels.surfaceCatalogIndex), eveSurface: request => ipcRenderer.invoke(channels.eveSurface, request), submitEveCommand: request => ipcRenderer.invoke(channels.submitEveCommand, request), - debugSurface: () => ipcRenderer.invoke(channels.debugSurface), - watchDebugSurface: callback => { - const subscriptionId = `debug-surface-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`; - const listener = (_event, message) => { - if (message?.subscriptionId === subscriptionId) { - callback(message.surface); - } - }; - ipcRenderer.on(channels.debugSurfaceChanged, listener); - void ipcRenderer.invoke(channels.debugSurfaceWatch, subscriptionId); - return () => { - ipcRenderer.off(channels.debugSurfaceChanged, listener); - void ipcRenderer.invoke(channels.debugSurfaceWatchStop, subscriptionId); - }; - }, windowControl: request => ipcRenderer.invoke(channels.windowControl, request), health: () => ipcRenderer.invoke(channels.health), }); diff --git a/Aetheria.Rts.Web/scripts/generate-rts-bindings.mjs b/Aetheria.Rts.Web/scripts/generate-rts-bindings.mjs index ac22fcbcf..63fa8ea52 100644 --- a/Aetheria.Rts.Web/scripts/generate-rts-bindings.mjs +++ b/Aetheria.Rts.Web/scripts/generate-rts-bindings.mjs @@ -43,10 +43,6 @@ const ipcChannels = [ ["surfaceCatalogIndex", "aetheria-rts:surface-catalog-index"], ["eveSurface", "aetheria-rts:eve-surface"], ["submitEveCommand", "aetheria-rts:submit-eve-command"], - ["debugSurface", "aetheria-rts:debug-surface"], - ["debugSurfaceWatch", "aetheria-rts:debug-surface-watch"], - ["debugSurfaceWatchStop", "aetheria-rts:debug-surface-watch-stop"], - ["debugSurfaceChanged", "aetheria-rts:debug-surface-changed"], ["windowControl", "aetheria-rts:window-control"], ["health", "aetheria-rts:health"], ]; @@ -1221,8 +1217,6 @@ export type AetheriaRtsApi = { surfaceCatalogIndex(): Promise; eveSurface(request: AetheriaEveSurfaceRequest): Promise; submitEveCommand(request: AetheriaEveCommandRequest): Promise; - debugSurface(): Promise; - watchDebugSurface(callback: (surface: AetheriaMenuSurfaceDocument) => void): () => void; windowControl(action: "minimize" | "maximize" | "close"): Promise; health(): Promise; }; @@ -1535,10 +1529,7 @@ function renderPreload() { const channelLines = renderIpcChannelLines(); const apiLines = ipcChannels .filter(([name]) => name !== "viewportFeedUpdate" && - name !== "viewportFeedStop" && - name !== "debugSurfaceWatch" && - name !== "debugSurfaceWatchStop" && - name !== "debugSurfaceChanged") + name !== "viewportFeedStop") .map(([name]) => { if (name === "viewportFeed") { return ` watchViewportFeed: (request, callback) => { @@ -1554,23 +1545,6 @@ function renderPreload() { ipcRenderer.off(channels.viewportFeedUpdate, listener); void ipcRenderer.invoke(channels.viewportFeedStop, subscriptionId); }; - },`; - } - if (name === "debugSurface") { - return ` debugSurface: () => ipcRenderer.invoke(channels.debugSurface), - watchDebugSurface: callback => { - const subscriptionId = \`debug-surface-\${Date.now().toString(36)}-\${Math.random().toString(36).slice(2)}\`; - const listener = (_event, message) => { - if (message?.subscriptionId === subscriptionId) { - callback(message.surface); - } - }; - ipcRenderer.on(channels.debugSurfaceChanged, listener); - void ipcRenderer.invoke(channels.debugSurfaceWatch, subscriptionId); - return () => { - ipcRenderer.off(channels.debugSurfaceChanged, listener); - void ipcRenderer.invoke(channels.debugSurfaceWatchStop, subscriptionId); - }; },`; } const hasNoArguments = name === "health" || diff --git a/Aetheria.Rts.Web/scripts/verify-stage7b-rts-client.ps1 b/Aetheria.Rts.Web/scripts/verify-stage7b-rts-client.ps1 index 0c0f7a521..cd2e2b236 100644 --- a/Aetheria.Rts.Web/scripts/verify-stage7b-rts-client.ps1 +++ b/Aetheria.Rts.Web/scripts/verify-stage7b-rts-client.ps1 @@ -28,6 +28,14 @@ if ($LASTEXITCODE -gt 1) { Write-Error "Stage 7B verifier could not run rg for forbidden public surfaces." } +$forbiddenFileBackedDebugSurfaceHits = & rg -n 'debugSurface|debug-surface|watchDebugSurface|AETHERIA_CULTUI_DEBUG_SURFACE_PATH|cultui-debug-surface|file_surface|debug-log' Client Electron scripts/generate-rts-bindings.mjs 2>$null +if ($LASTEXITCODE -eq 0) { + Write-Error "Stage 7B verifier failed: Electron must consume daemon Eve surfaces, not file-backed CultUI debug surfaces.`n$forbiddenFileBackedDebugSurfaceHits" +} +if ($LASTEXITCODE -gt 1) { + Write-Error "Stage 7B verifier could not run rg for file-backed debug surface checks." +} + $required = @( 'mapViewport', 'objectsViewport',