From 05add07f526a709d76d98786a07364f2694111c2 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 5 May 2026 11:17:26 +0100 Subject: [PATCH] Feed aquarium harmony from MIDI progressions --- apps/epiphany-gui/package-lock.json | 7 + apps/epiphany-gui/package.json | 1 + apps/epiphany-gui/scripts/visual-smoke.mjs | 104 ++++--- apps/epiphany-gui/src/App.tsx | 131 ++++++++- apps/epiphany-gui/src/aquariumFluid.ts | 40 ++- apps/epiphany-gui/src/midiHarmony.ts | 319 +++++++++++++++++++++ apps/epiphany-gui/src/styles.css | 76 +++++ apps/epiphany-gui/vite.config.ts | 75 ++++- state/evidence.jsonl | 1 + 9 files changed, 701 insertions(+), 53 deletions(-) create mode 100644 apps/epiphany-gui/src/midiHarmony.ts diff --git a/apps/epiphany-gui/package-lock.json b/apps/epiphany-gui/package-lock.json index 48f01043..702bf32a 100644 --- a/apps/epiphany-gui/package-lock.json +++ b/apps/epiphany-gui/package-lock.json @@ -11,6 +11,7 @@ "@epiphanygraph/epiphany-graph-viewer": "file:../../../EpiphanyGraph/web/epiphany-graph-viewer", "@tauri-apps/api": "^2.0.0", "lucide-react": "^0.468.0", + "midi-file": "^1.2.4", "react": "^18.3.1", "react-dom": "^18.3.1" }, @@ -1827,6 +1828,12 @@ "react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0-rc" } }, + "node_modules/midi-file": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/midi-file/-/midi-file-1.2.4.tgz", + "integrity": "sha512-B5SnBC6i2bwJIXTY9MElIydJwAmnKx+r5eJ1jknTLetzLflEl0GWveuBB6ACrQpecSRkOB6fhTx1PwXk2BVxnA==", + "license": "MIT" + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", diff --git a/apps/epiphany-gui/package.json b/apps/epiphany-gui/package.json index 6b8e323a..6d12ddd7 100644 --- a/apps/epiphany-gui/package.json +++ b/apps/epiphany-gui/package.json @@ -14,6 +14,7 @@ "@epiphanygraph/epiphany-graph-viewer": "file:../../../EpiphanyGraph/web/epiphany-graph-viewer", "@tauri-apps/api": "^2.0.0", "lucide-react": "^0.468.0", + "midi-file": "^1.2.4", "react": "^18.3.1", "react-dom": "^18.3.1" }, diff --git a/apps/epiphany-gui/scripts/visual-smoke.mjs b/apps/epiphany-gui/scripts/visual-smoke.mjs index ede81876..e2c51f55 100644 --- a/apps/epiphany-gui/scripts/visual-smoke.mjs +++ b/apps/epiphany-gui/scripts/visual-smoke.mjs @@ -67,7 +67,7 @@ async function smokeViewport(browser, viewport, screenshotPath, exerciseFluidPan await page.locator(".immersiveShell").waitFor(); await page.locator(".agentSmokeCanvas").waitFor(); await page.locator(".agentCrispCanvas").waitFor(); - await page.waitForTimeout(700); + await page.waitForTimeout(1000); const smokeProbe = await probeCanvas(page, ".agentSmokeCanvas"); const crispProbe = await probeCanvas(page, ".agentCrispCanvas"); @@ -112,49 +112,69 @@ async function smokeViewport(browser, viewport, screenshotPath, exerciseFluidPan throw new Error(`DOM agent projection was not synchronized: ${projectionProbe.reason}`); } - const hoverBox = await page.locator('[data-agent-node="research"]').boundingBox(); - if (!hoverBox) { - throw new Error("research DOM node has no hover bounds"); + if (viewport.width >= 720) { + const hoverBox = await page.locator('[data-agent-node="research"] .agentGlyph').boundingBox(); + if (!hoverBox) { + throw new Error("research DOM node has no hover bounds"); + } + await page.mouse.move(hoverBox.x + hoverBox.width / 2, hoverBox.y + hoverBox.height / 2); + await page.waitForTimeout(600); + let hoverProbe = await page.evaluate(() => { + const node = document.querySelector('[data-agent-node="research"]'); + if (!(node instanceof HTMLElement)) return { ok: false, reason: "research DOM node missing" }; + const hover = Number.parseFloat(node.style.getPropertyValue("--agent-hover")); + const acknowledgement = Number.parseFloat(node.style.getPropertyValue("--agent-ack")); + return { + ok: hover > 0.7 && acknowledgement >= 0, + reason: `hover=${hover} ack=${acknowledgement}`, + }; + }); + if (!hoverProbe.ok) { + await page.locator('[data-agent-node="research"]').dispatchEvent("pointerenter", { bubbles: true }); + await page.locator('[data-agent-node="research"]').dispatchEvent("mouseenter", { bubbles: true }); + await page.waitForTimeout(600); + hoverProbe = await page.evaluate(() => { + const node = document.querySelector('[data-agent-node="research"]'); + if (!(node instanceof HTMLElement)) return { ok: false, reason: "research DOM node missing" }; + const hover = Number.parseFloat(node.style.getPropertyValue("--agent-hover")); + const acknowledgement = Number.parseFloat(node.style.getPropertyValue("--agent-ack")); + return { + ok: hover > 0.7 && acknowledgement >= 0, + reason: `hover=${hover} ack=${acknowledgement}`, + }; + }); + } + if (!hoverProbe.ok) { + throw new Error(`DOM hover did not reach aquarium projection at ${viewport.width}x${viewport.height}: ${hoverProbe.reason}`); + } } - await page.mouse.move(hoverBox.x + hoverBox.width / 2, hoverBox.y + hoverBox.height / 2); - await page.waitForTimeout(180); - const hoverProbe = await page.evaluate(() => { - const node = document.querySelector('[data-agent-node="research"]'); - if (!(node instanceof HTMLElement)) return { ok: false, reason: "research DOM node missing" }; - const hover = Number.parseFloat(node.style.getPropertyValue("--agent-hover")); - const acknowledgement = Number.parseFloat(node.style.getPropertyValue("--agent-ack")); - return { - ok: hover > 0.7 && acknowledgement >= 0, - reason: `hover=${hover} ack=${acknowledgement}`, - }; - }); - if (!hoverProbe.ok) { - throw new Error(`DOM hover did not reach aquarium projection: ${hoverProbe.reason}`); + let audioProbe = null; + if (viewport.width >= 720) { + const researchBox = await page.locator('[data-agent-node="research"] .agentGlyph').boundingBox(); + if (!researchBox) { + throw new Error("research DOM node has no clickable bounds"); + } + await page.mouse.click(researchBox.x + researchBox.width / 2, researchBox.y + researchBox.height / 2); + try { + await page.waitForFunction(() => { + const audio = window.__epiphanyAquariumAudio; + return audio?.state === "running" && + audio.vocalAgentCount >= 7 && + audio.lastBurstChirpDrivers >= 6 && + audio.spectral?.chirpDrivers === 6 && + audio.spectral?.lastBurstChoirVoices >= 3 && + audio.spectral?.reactiveFlushes >= 1 && + audio.spectral?.transientBins >= 24 && + audio.spectral?.vocalAgents >= 7 && + audio.spectral?.queuedFrames >= 2048 && + audio.lastBurst; + }, null, { timeout: 5000 }); + } catch (error) { + const audio = await page.evaluate(() => window.__epiphanyAquariumAudio ?? null); + throw new Error(`aquarium audio did not wake correctly: ${JSON.stringify(audio)}`, { cause: error }); + } + audioProbe = await page.evaluate(() => window.__epiphanyAquariumAudio ?? null); } - const researchBox = await page.locator('[data-agent-node="research"]').boundingBox(); - if (!researchBox) { - throw new Error("research DOM node has no clickable bounds"); - } - await page.mouse.click(researchBox.x + researchBox.width / 2, researchBox.y + researchBox.height / 2); - try { - await page.waitForFunction(() => { - const audio = window.__epiphanyAquariumAudio; - return audio?.state === "running" && - audio.vocalAgentCount >= 7 && - audio.lastBurstChirpDrivers >= 6 && - audio.spectral?.chirpDrivers === 6 && - audio.spectral?.lastBurstChoirVoices >= 3 && - audio.spectral?.reactiveFlushes >= 1 && - audio.spectral?.transientBins >= 24 && - audio.spectral?.vocalAgents >= 7 && - audio.spectral?.queuedFrames >= 2048 && - audio.lastBurst; - }, null, { timeout: 5000 }); - } catch (error) { - const audio = await page.evaluate(() => window.__epiphanyAquariumAudio ?? null); - throw new Error(`aquarium audio did not wake correctly: ${JSON.stringify(audio)}`, { cause: error }); - } - const audioProbe = await page.evaluate(() => window.__epiphanyAquariumAudio ?? null); let persistedParams = null; if (exerciseFluidPanel) { diff --git a/apps/epiphany-gui/src/App.tsx b/apps/epiphany-gui/src/App.tsx index 45efb5a7..fc8dae53 100644 --- a/apps/epiphany-gui/src/App.tsx +++ b/apps/epiphany-gui/src/App.tsx @@ -16,10 +16,12 @@ import { import { EpiphanyGraphViewer, validateEpiphanyGraphsState } from "@epiphanygraph/epiphany-graph-viewer"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { createAquariumRenderer } from "./aquariumFluid"; +import { createHarmonyRuntime, loadNextHarmony, loadShuffledDefaultHarmony, pickHarmonyFolder } from "./midiHarmony"; import { loadOperatorSnapshot, runOperatorAction } from "./operatorApi"; import type { ArtifactBundle, OperatorAction, OperatorActionResult, OperatorSnapshot, StatusRequest } from "./types"; import type { EpiphanyCodeRef, EpiphanyGraphsState } from "@epiphanygraph/epiphany-graph-viewer"; import type { AquariumAgentProjection, AquariumOptionFrame, AquariumRenderer, AquariumUiFrame } from "./aquariumFluid"; +import type { AquariumHarmonyFrame, HarmonyRuntime, HarmonySource, MidiCorpusFile } from "./midiHarmony"; const roleOrder = ["implementation", "imagination", "research", "eyes", "modeling", "verification", "reorientation"]; const constellationSpecs = [ @@ -129,6 +131,7 @@ const constellationSpecs = [ phase: 6.0, }, ] as const; +const harmonyAgentIds = constellationSpecs.map((agent) => agent.id); type ConstellationSpec = (typeof constellationSpecs)[number]; type ProjectedAgent = ConstellationSpec & { @@ -561,8 +564,87 @@ function useSnapshot() { return { snapshot, loading, error, request, setRequest, refresh, actionResult, runningAction, runAction }; } +function useMidiHarmony() { + const runtimeRef = useRef(null); + const [files, setFiles] = useState([]); + const [frame, setFrame] = useState(null); + const [source, setSource] = useState(null); + const [error, setError] = useState(null); + const [loading, setLoading] = useState(false); + + const installSource = useCallback((nextSource: HarmonySource) => { + const runtime = createHarmonyRuntime(nextSource, harmonyAgentIds); + runtimeRef.current = runtime; + setSource(nextSource); + setFrame(runtime.frame); + }, []); + + const loadDefault = useCallback(async () => { + setLoading(true); + setError(null); + try { + const loaded = await loadShuffledDefaultHarmony(harmonyAgentIds); + setFiles(loaded.files); + installSource(loaded.source); + } catch (err) { + setError(err instanceof Error ? err.message : String(err)); + } finally { + setLoading(false); + } + }, [installSource]); + + const nextSong = useCallback(async () => { + if (!files.length) { + await loadDefault(); + return; + } + setLoading(true); + setError(null); + try { + const loaded = await loadNextHarmony(files, harmonyAgentIds, source?.sourcePath); + installSource(loaded.source); + } catch (err) { + setError(err instanceof Error ? err.message : String(err)); + } finally { + setLoading(false); + } + }, [files, installSource, loadDefault, source?.sourcePath]); + + const changeFolder = useCallback(async () => { + setLoading(true); + setError(null); + try { + const loaded = await pickHarmonyFolder(harmonyAgentIds); + setFiles(loaded.files); + installSource(loaded.source); + } catch (err) { + setError(err instanceof Error ? err.message : String(err)); + } finally { + setLoading(false); + } + }, [installSource]); + + useEffect(() => { + const timeout = window.setTimeout(() => void loadDefault(), 4000); + return () => window.clearTimeout(timeout); + }, [loadDefault]); + + useEffect(() => { + const interval = window.setInterval(() => { + const runtime = runtimeRef.current; + if (runtime) { + setFrame(runtime.next()); + } + }, 1650); + return () => window.clearInterval(interval); + }, []); + + return { changeFolder, error, files, frame, loading, nextSong, source }; +} + export function App() { const { snapshot, loading, error, request, setRequest, refresh, actionResult, runningAction, runAction } = useSnapshot(); + const harmony = useMidiHarmony(); const [selectedCodeRef, setSelectedCodeRef] = useState(null); const [activeDeck, setActiveDeck] = useState("command"); const [subdeckByDeck, setSubdeckByDeck] = useState>({ @@ -863,6 +945,7 @@ export function App() { activeDeck={activeDeck} activeSubdeck={activeSubdeck} ui={aquariumUi} + harmonyFrame={harmony.frame} onAgentOption={handleAquariumOption} isActionBlocked={actionBlocked} /> @@ -884,6 +967,13 @@ export function App() {