Spaces:
Sleeping
Sleeping
dixiebone13-a11y commited on
Commit ·
82e6bed
0
Parent(s):
v2.5: Full rewrite - Vite+React+Tailwind build, all 13 audit fixes
Browse files- .gitignore +4 -0
- Dockerfile +26 -0
- README.md +54 -0
- index.html +12 -0
- package.json +23 -0
- postcss.config.js +6 -0
- src/App.jsx +403 -0
- src/components/AgentBar.jsx +44 -0
- src/components/Icons.jsx +65 -0
- src/components/MiniGraph.jsx +58 -0
- src/components/UI.jsx +46 -0
- src/index.css +3 -0
- src/main.jsx +10 -0
- tailwind.config.js +6 -0
- vite.config.js +7 -0
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules
|
| 2 |
+
dist
|
| 3 |
+
.DS_Store
|
| 4 |
+
*.local
|
Dockerfile
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:20-slim AS build
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY package*.json ./
|
| 4 |
+
RUN npm install
|
| 5 |
+
COPY . .
|
| 6 |
+
RUN npm run build
|
| 7 |
+
|
| 8 |
+
FROM nginx:alpine
|
| 9 |
+
COPY --from=build /app/dist /usr/share/nginx/html
|
| 10 |
+
EXPOSE 7860
|
| 11 |
+
COPY <<'EOF' /etc/nginx/nginx.conf
|
| 12 |
+
worker_processes auto;
|
| 13 |
+
events { worker_connections 1024; }
|
| 14 |
+
http {
|
| 15 |
+
include /etc/nginx/mime.types;
|
| 16 |
+
server {
|
| 17 |
+
listen 7860;
|
| 18 |
+
root /usr/share/nginx/html;
|
| 19 |
+
index index.html;
|
| 20 |
+
location / {
|
| 21 |
+
try_files $uri $uri/ /index.html;
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
EOF
|
| 26 |
+
CMD ["nginx", "-g", "daemon off;"]
|
README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: NeuroSort Memory Agent Demo
|
| 3 |
+
emoji: 🧠
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
+
short_description: Stochastic vs memory-augmented AI agents
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# 🧠 NeuroSort: Memory-Augmented Agent Simulation
|
| 14 |
+
|
| 15 |
+
**A real-time visualization comparing two AI agent strategies for navigating obstacle-rich environments.**
|
| 16 |
+
|
| 17 |
+
## What Is This?
|
| 18 |
+
|
| 19 |
+
NeuroSort demonstrates a key concept in AI agent design: **frustration memory**.
|
| 20 |
+
|
| 21 |
+
When agents encounter obstacles that cause failures (and penalties), a naive stochastic agent keeps trying randomly—wasting time and resources. A memory-augmented agent *learns from frustration* and adapts its behavior, avoiding repeated mistakes.
|
| 22 |
+
|
| 23 |
+
## The Two Agents
|
| 24 |
+
|
| 25 |
+
| Agent | Strategy | Color |
|
| 26 |
+
|-------|----------|-------|
|
| 27 |
+
| **THREAD_A::BASELINE** | Pure stochastic (random) decisions | 🔵 Cyan |
|
| 28 |
+
| **THREAD_B::MEMORY** | Frustration-aware adaptive logic | 🟣 Fuchsia |
|
| 29 |
+
|
| 30 |
+
## How It Works
|
| 31 |
+
|
| 32 |
+
1. **The Task**: Both agents try to sort an array (bubble sort style)
|
| 33 |
+
2. **The Catch**: Some elements are "heavy" obstacles (gray bars) with 90% failure rate
|
| 34 |
+
3. **Failure Penalty**: When an agent fails, it gets *stunned* for several cycles (amber glow)
|
| 35 |
+
4. **Memory Advantage**: The memory agent tracks frustration per element—high frustration = skip and try elsewhere
|
| 36 |
+
|
| 37 |
+
## Controls
|
| 38 |
+
|
| 39 |
+
- **Obstacle Density**: % of heavy elements (requires reset)
|
| 40 |
+
- **Stun Penalty**: How long agents are frozen after failure
|
| 41 |
+
- **Memory Decay**: How fast frustration fades (higher = longer memory)
|
| 42 |
+
|
| 43 |
+
## Key Insight
|
| 44 |
+
|
| 45 |
+
Over time, the **Memory Agent (fuchsia)** consistently achieves:
|
| 46 |
+
- ✅ More successful moves
|
| 47 |
+
- ✅ Fewer crashes
|
| 48 |
+
- ✅ Smarter resource allocation
|
| 49 |
+
|
| 50 |
+
## Tech
|
| 51 |
+
|
| 52 |
+
React 18 + Vite + Tailwind CSS, deployed as Docker on HuggingFace Spaces.
|
| 53 |
+
|
| 54 |
+
*Part of the [Harmonic Field Consciousness](https://github.com/vfd-org/harmonic-field-consciousness) research project*
|
index.html
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>NeuroSort - Memory Agent Demo</title>
|
| 7 |
+
</head>
|
| 8 |
+
<body class="bg-slate-950">
|
| 9 |
+
<div id="root"></div>
|
| 10 |
+
<script type="module" src="/src/main.jsx"></script>
|
| 11 |
+
</body>
|
| 12 |
+
</html>
|
package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "memory-agent-demo",
|
| 3 |
+
"private": true,
|
| 4 |
+
"version": "2.5.0",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "vite",
|
| 8 |
+
"build": "vite build",
|
| 9 |
+
"preview": "vite preview"
|
| 10 |
+
},
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"lucide-react": "^0.454.0",
|
| 13 |
+
"react": "^18.3.1",
|
| 14 |
+
"react-dom": "^18.3.1"
|
| 15 |
+
},
|
| 16 |
+
"devDependencies": {
|
| 17 |
+
"@vitejs/plugin-react": "^4.3.4",
|
| 18 |
+
"autoprefixer": "^10.4.20",
|
| 19 |
+
"postcss": "^8.4.49",
|
| 20 |
+
"tailwindcss": "^3.4.15",
|
| 21 |
+
"vite": "^6.0.2"
|
| 22 |
+
}
|
| 23 |
+
}
|
postcss.config.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default {
|
| 2 |
+
plugins: {
|
| 3 |
+
tailwindcss: {},
|
| 4 |
+
autoprefixer: {},
|
| 5 |
+
},
|
| 6 |
+
};
|
src/App.jsx
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
| 2 |
+
import { Play, Pause, RotateCcw, Zap, Brain, Settings, Activity, Cpu } from './components/Icons';
|
| 3 |
+
import { NeoCard, NeoBadge, Slider } from './components/UI';
|
| 4 |
+
import AgentBar from './components/AgentBar';
|
| 5 |
+
import MiniGraph from './components/MiniGraph';
|
| 6 |
+
|
| 7 |
+
const ARRAY_SIZE = 50;
|
| 8 |
+
const HISTORY_LENGTH = 100;
|
| 9 |
+
|
| 10 |
+
// --- Data Generation (fix #7: flat .map instead of JSON round-trip) ---
|
| 11 |
+
const generateData = (size, heavyChance) =>
|
| 12 |
+
Array.from({ length: size }, (_, i) => ({
|
| 13 |
+
id: i,
|
| 14 |
+
value: Math.floor(Math.random() * 90) + 10,
|
| 15 |
+
isHeavy: Math.random() < heavyChance,
|
| 16 |
+
frustration: 0,
|
| 17 |
+
lastAction: null,
|
| 18 |
+
recovery: 0,
|
| 19 |
+
}));
|
| 20 |
+
|
| 21 |
+
const cloneData = (data) =>
|
| 22 |
+
data.map(d => ({ ...d }));
|
| 23 |
+
|
| 24 |
+
// --- Fix #6: Unified agent step logic ---
|
| 25 |
+
// Returns { data, moves, attempts, wasted, stunned }
|
| 26 |
+
const runAgentStep = (prevData, params, useMemory) => {
|
| 27 |
+
const next = prevData.map(d => ({ ...d }));
|
| 28 |
+
let moves = 0, attempts = 0, wasted = 0, stunned = 0;
|
| 29 |
+
|
| 30 |
+
// Decay frustration & tick recovery for memory agent
|
| 31 |
+
if (useMemory) {
|
| 32 |
+
for (let i = 0; i < next.length; i++) {
|
| 33 |
+
next[i].frustration = Math.max(0, next[i].frustration * params.memoryDecay);
|
| 34 |
+
if (next[i].recovery > 0) {
|
| 35 |
+
next[i].recovery--;
|
| 36 |
+
next[i].lastAction = 'stun';
|
| 37 |
+
stunned++;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
} else {
|
| 41 |
+
for (let i = 0; i < next.length; i++) {
|
| 42 |
+
if (next[i].recovery > 0) {
|
| 43 |
+
next[i].recovery--;
|
| 44 |
+
next[i].lastAction = 'stun';
|
| 45 |
+
stunned++;
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
for (let i = 0; i < next.length - 1; i++) {
|
| 51 |
+
if (next[i].recovery > 0) continue;
|
| 52 |
+
|
| 53 |
+
if (next[i].value > next[i + 1].value) {
|
| 54 |
+
if (next[i + 1].recovery > 0) {
|
| 55 |
+
next[i].lastAction = 'wait';
|
| 56 |
+
continue;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
// Memory agent: frustration reduces willingness to attempt
|
| 60 |
+
let effectiveTemp = params.initialTemp;
|
| 61 |
+
if (useMemory) {
|
| 62 |
+
const frustPenalty = next[i].frustration * 0.25;
|
| 63 |
+
effectiveTemp = Math.max(0.01, Math.min(1.0, params.initialTemp - frustPenalty));
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
if (Math.random() < effectiveTemp) {
|
| 67 |
+
attempts++;
|
| 68 |
+
const failureChance = (next[i].isHeavy || next[i + 1].isHeavy) ? 0.9 : 0.0;
|
| 69 |
+
|
| 70 |
+
if (Math.random() > failureChance) {
|
| 71 |
+
// Successful swap
|
| 72 |
+
const tmp = next[i];
|
| 73 |
+
next[i] = next[i + 1];
|
| 74 |
+
next[i + 1] = tmp;
|
| 75 |
+
moves++;
|
| 76 |
+
next[i].lastAction = 'swap';
|
| 77 |
+
next[i + 1].lastAction = 'swap';
|
| 78 |
+
if (useMemory) {
|
| 79 |
+
next[i].frustration *= 0.5;
|
| 80 |
+
next[i + 1].frustration *= 0.5;
|
| 81 |
+
}
|
| 82 |
+
} else {
|
| 83 |
+
// Failed
|
| 84 |
+
wasted++;
|
| 85 |
+
next[i].lastAction = 'fail';
|
| 86 |
+
next[i].recovery = params.stunPenalty;
|
| 87 |
+
if (useMemory) {
|
| 88 |
+
next[i].frustration += 1.0;
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
} else {
|
| 92 |
+
next[i].lastAction = useMemory ? 'skip' : 'wait';
|
| 93 |
+
}
|
| 94 |
+
} else {
|
| 95 |
+
next[i].lastAction = null;
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
return { data: next, moves, attempts, wasted, stunned };
|
| 100 |
+
};
|
| 101 |
+
|
| 102 |
+
// ============================================================
|
| 103 |
+
export default function App() {
|
| 104 |
+
const [params, setParams] = useState({
|
| 105 |
+
heavyChance: 0.25,
|
| 106 |
+
stunPenalty: 12,
|
| 107 |
+
memoryDecay: 0.95,
|
| 108 |
+
initialTemp: 0.8,
|
| 109 |
+
});
|
| 110 |
+
|
| 111 |
+
const [baselineData, setBaselineData] = useState([]);
|
| 112 |
+
const [memoryData, setMemoryData] = useState([]);
|
| 113 |
+
const [isPlaying, setIsPlaying] = useState(false);
|
| 114 |
+
const [frame, setFrame] = useState(0);
|
| 115 |
+
const [stats, setStats] = useState({
|
| 116 |
+
baseline: { moves: 0, attempts: 0, wasted: 0, stunned: 0 },
|
| 117 |
+
memory: { moves: 0, attempts: 0, wasted: 0, stunned: 0 },
|
| 118 |
+
});
|
| 119 |
+
const [history, setHistory] = useState([]);
|
| 120 |
+
|
| 121 |
+
// Refs for the simulation loop (fix #5, #11: single timer source of truth)
|
| 122 |
+
const timerRef = useRef(null);
|
| 123 |
+
const paramsRef = useRef(params);
|
| 124 |
+
const baselineRef = useRef(baselineData);
|
| 125 |
+
const memoryRef = useRef(memoryData);
|
| 126 |
+
const statsRef = useRef(stats);
|
| 127 |
+
const frameRef = useRef(0);
|
| 128 |
+
|
| 129 |
+
// Keep refs synced
|
| 130 |
+
useEffect(() => { paramsRef.current = params; }, [params]);
|
| 131 |
+
|
| 132 |
+
// Init on mount
|
| 133 |
+
useEffect(() => { resetSim(); }, []); // eslint-disable-line react-hooks/exhaustive-deps
|
| 134 |
+
|
| 135 |
+
// Fix #9: Stable callbacks
|
| 136 |
+
const resetSim = useCallback(() => {
|
| 137 |
+
clearInterval(timerRef.current);
|
| 138 |
+
const data = generateData(ARRAY_SIZE, paramsRef.current.heavyChance);
|
| 139 |
+
const b = cloneData(data);
|
| 140 |
+
const m = cloneData(data);
|
| 141 |
+
setBaselineData(b);
|
| 142 |
+
setMemoryData(m);
|
| 143 |
+
baselineRef.current = b;
|
| 144 |
+
memoryRef.current = m;
|
| 145 |
+
const s = {
|
| 146 |
+
baseline: { moves: 0, attempts: 0, wasted: 0, stunned: 0 },
|
| 147 |
+
memory: { moves: 0, attempts: 0, wasted: 0, stunned: 0 },
|
| 148 |
+
};
|
| 149 |
+
setStats(s);
|
| 150 |
+
statsRef.current = s;
|
| 151 |
+
setHistory([]);
|
| 152 |
+
setFrame(0);
|
| 153 |
+
frameRef.current = 0;
|
| 154 |
+
setIsPlaying(false);
|
| 155 |
+
}, []);
|
| 156 |
+
|
| 157 |
+
const togglePlay = useCallback(() => {
|
| 158 |
+
setIsPlaying(prev => !prev);
|
| 159 |
+
}, []);
|
| 160 |
+
|
| 161 |
+
// Fix #5: Flat step — no nested state updaters
|
| 162 |
+
const step = useCallback(() => {
|
| 163 |
+
const p = paramsRef.current;
|
| 164 |
+
frameRef.current++;
|
| 165 |
+
const f = frameRef.current;
|
| 166 |
+
|
| 167 |
+
// Run both agents
|
| 168 |
+
const bResult = runAgentStep(baselineRef.current, p, false);
|
| 169 |
+
const mResult = runAgentStep(memoryRef.current, p, true);
|
| 170 |
+
|
| 171 |
+
// Update refs
|
| 172 |
+
baselineRef.current = bResult.data;
|
| 173 |
+
memoryRef.current = mResult.data;
|
| 174 |
+
|
| 175 |
+
// Accumulate stats
|
| 176 |
+
const prev = statsRef.current;
|
| 177 |
+
const nextStats = {
|
| 178 |
+
baseline: {
|
| 179 |
+
moves: prev.baseline.moves + bResult.moves,
|
| 180 |
+
attempts: prev.baseline.attempts + bResult.attempts,
|
| 181 |
+
wasted: prev.baseline.wasted + bResult.wasted,
|
| 182 |
+
stunned: prev.baseline.stunned + bResult.stunned,
|
| 183 |
+
},
|
| 184 |
+
memory: {
|
| 185 |
+
moves: prev.memory.moves + mResult.moves,
|
| 186 |
+
attempts: prev.memory.attempts + mResult.attempts,
|
| 187 |
+
wasted: prev.memory.wasted + mResult.wasted,
|
| 188 |
+
stunned: prev.memory.stunned + mResult.stunned,
|
| 189 |
+
},
|
| 190 |
+
};
|
| 191 |
+
statsRef.current = nextStats;
|
| 192 |
+
|
| 193 |
+
// Batch all state updates (flat, no nesting)
|
| 194 |
+
setBaselineData(bResult.data);
|
| 195 |
+
setMemoryData(mResult.data);
|
| 196 |
+
setStats(nextStats);
|
| 197 |
+
setFrame(f);
|
| 198 |
+
|
| 199 |
+
if (f % 5 === 0) {
|
| 200 |
+
setHistory(prev => {
|
| 201 |
+
const point = { frame: f, baseline: nextStats.baseline.moves, memory: nextStats.memory.moves };
|
| 202 |
+
const next = [...prev, point];
|
| 203 |
+
if (next.length > HISTORY_LENGTH) next.shift();
|
| 204 |
+
return next;
|
| 205 |
+
});
|
| 206 |
+
}
|
| 207 |
+
}, []);
|
| 208 |
+
|
| 209 |
+
// Fix #11: Single timer source of truth — only useEffect manages the interval
|
| 210 |
+
useEffect(() => {
|
| 211 |
+
if (isPlaying) {
|
| 212 |
+
timerRef.current = setInterval(step, 40);
|
| 213 |
+
} else {
|
| 214 |
+
clearInterval(timerRef.current);
|
| 215 |
+
}
|
| 216 |
+
return () => clearInterval(timerRef.current);
|
| 217 |
+
}, [isPlaying, step]);
|
| 218 |
+
|
| 219 |
+
// Fix #12: Stable slider handlers
|
| 220 |
+
const onHeavyChance = useCallback((e) => setParams(p => ({ ...p, heavyChance: parseFloat(e.target.value) / 100 })), []);
|
| 221 |
+
const onStunPenalty = useCallback((e) => setParams(p => ({ ...p, stunPenalty: parseFloat(e.target.value) })), []);
|
| 222 |
+
const onMemoryDecay = useCallback((e) => setParams(p => ({ ...p, memoryDecay: parseFloat(e.target.value) })), []);
|
| 223 |
+
|
| 224 |
+
return (
|
| 225 |
+
<div className="min-h-screen bg-slate-950 p-6 font-sans text-slate-200 selection:bg-cyan-900 selection:text-cyan-100">
|
| 226 |
+
{/* Grid background */}
|
| 227 |
+
<div
|
| 228 |
+
className="fixed inset-0 pointer-events-none opacity-20"
|
| 229 |
+
style={{
|
| 230 |
+
backgroundImage: 'linear-gradient(#1e293b 1px, transparent 1px), linear-gradient(90deg, #1e293b 1px, transparent 1px)',
|
| 231 |
+
backgroundSize: '40px 40px',
|
| 232 |
+
}}
|
| 233 |
+
/>
|
| 234 |
+
|
| 235 |
+
<div className="max-w-6xl mx-auto space-y-6 relative z-10">
|
| 236 |
+
{/* Header */}
|
| 237 |
+
<div className="flex flex-col md:flex-row justify-between items-start md:items-end gap-6 border-b border-slate-800 pb-6">
|
| 238 |
+
<div>
|
| 239 |
+
<h1 className="text-3xl font-black tracking-tighter text-white flex items-center gap-3 uppercase">
|
| 240 |
+
<Cpu className="w-8 h-8 text-cyan-500 animate-pulse" />
|
| 241 |
+
<span className="bg-gradient-to-r from-cyan-400 to-fuchsia-500 text-transparent bg-clip-text">
|
| 242 |
+
NeuroSort
|
| 243 |
+
</span>
|
| 244 |
+
<span className="text-xs font-mono text-slate-500 border border-slate-800 px-2 py-1 rounded">V2.5.0</span>
|
| 245 |
+
</h1>
|
| 246 |
+
<p className="text-slate-500 mt-2 font-mono text-sm max-w-lg">
|
| 247 |
+
Comparative simulation of Stochastic Agents vs. Memory-Augmented Frustration Logic in obstacle-rich environments.
|
| 248 |
+
</p>
|
| 249 |
+
</div>
|
| 250 |
+
|
| 251 |
+
<div className="flex gap-3">
|
| 252 |
+
<button
|
| 253 |
+
onClick={togglePlay}
|
| 254 |
+
className={`flex items-center gap-2 px-6 py-3 rounded-none font-bold tracking-widest uppercase transition-all border border-transparent shadow-lg hover:shadow-cyan-500/20 ${
|
| 255 |
+
isPlaying
|
| 256 |
+
? 'bg-amber-500/10 text-amber-500 border-amber-500/50 hover:bg-amber-500/20'
|
| 257 |
+
: 'bg-cyan-600 hover:bg-cyan-500 text-black'
|
| 258 |
+
}`}
|
| 259 |
+
>
|
| 260 |
+
{isPlaying ? <><Pause /> HALT</> : <><Play /> EXECUTE</>}
|
| 261 |
+
</button>
|
| 262 |
+
<button
|
| 263 |
+
onClick={resetSim}
|
| 264 |
+
className="p-3 text-cyan-500 border border-slate-700 hover:border-cyan-500/50 hover:bg-slate-800 transition-all bg-slate-900"
|
| 265 |
+
title="Reset Simulation"
|
| 266 |
+
aria-label="Reset simulation"
|
| 267 |
+
>
|
| 268 |
+
<RotateCcw />
|
| 269 |
+
</button>
|
| 270 |
+
</div>
|
| 271 |
+
</div>
|
| 272 |
+
|
| 273 |
+
<div className="grid grid-cols-1 lg:grid-cols-4 gap-6">
|
| 274 |
+
{/* Left Column — Controls */}
|
| 275 |
+
<div className="lg:col-span-1 space-y-6">
|
| 276 |
+
<NeoCard className="p-5">
|
| 277 |
+
<div className="flex items-center gap-2 mb-6 text-cyan-400 border-b border-slate-800 pb-2">
|
| 278 |
+
<Settings />
|
| 279 |
+
<h3 className="font-bold uppercase tracking-widest text-sm">Sys.Config</h3>
|
| 280 |
+
</div>
|
| 281 |
+
|
| 282 |
+
<Slider
|
| 283 |
+
label="Obstacle Density"
|
| 284 |
+
value={Math.round(params.heavyChance * 100)}
|
| 285 |
+
min={5} max={50} step={5} unit="%"
|
| 286 |
+
onChange={onHeavyChance}
|
| 287 |
+
/>
|
| 288 |
+
<div className="text-[10px] text-slate-500 mb-4 text-right">*Requires Reset</div>
|
| 289 |
+
|
| 290 |
+
<Slider
|
| 291 |
+
label="Stun Penalty"
|
| 292 |
+
value={params.stunPenalty}
|
| 293 |
+
min={0} max={30} step={2} unit="ms"
|
| 294 |
+
onChange={onStunPenalty}
|
| 295 |
+
/>
|
| 296 |
+
|
| 297 |
+
<Slider
|
| 298 |
+
label="Memory Decay"
|
| 299 |
+
value={params.memoryDecay}
|
| 300 |
+
min={0.80} max={0.99} step={0.01} unit=""
|
| 301 |
+
onChange={onMemoryDecay}
|
| 302 |
+
/>
|
| 303 |
+
</NeoCard>
|
| 304 |
+
|
| 305 |
+
<NeoCard className="p-5 h-64 flex flex-col">
|
| 306 |
+
<div className="flex items-center justify-between gap-2 mb-4 text-fuchsia-400 border-b border-slate-800 pb-2">
|
| 307 |
+
<div className="flex items-center gap-2">
|
| 308 |
+
<Activity />
|
| 309 |
+
<h3 className="font-bold uppercase tracking-widest text-sm">Throughput</h3>
|
| 310 |
+
</div>
|
| 311 |
+
<span className="text-[10px] text-slate-500 font-mono">MOVES / TIME</span>
|
| 312 |
+
</div>
|
| 313 |
+
<div className="flex-1 w-full relative">
|
| 314 |
+
<MiniGraph data={history} />
|
| 315 |
+
</div>
|
| 316 |
+
<div className="flex justify-between text-[10px] font-mono mt-2">
|
| 317 |
+
<span className="text-cyan-400">● BASELINE</span>
|
| 318 |
+
<span className="text-fuchsia-400">● MEMORY</span>
|
| 319 |
+
</div>
|
| 320 |
+
</NeoCard>
|
| 321 |
+
</div>
|
| 322 |
+
|
| 323 |
+
{/* Right Column — Agent Visualizations */}
|
| 324 |
+
<div className="lg:col-span-3 space-y-6">
|
| 325 |
+
{/* Baseline Agent */}
|
| 326 |
+
<div className="space-y-2">
|
| 327 |
+
<div className="flex justify-between items-center px-1">
|
| 328 |
+
<div className="flex items-center gap-2">
|
| 329 |
+
<Zap className="w-4 h-4 text-cyan-400" />
|
| 330 |
+
<span className="font-mono text-sm tracking-wider text-cyan-100">THREAD_A::BASELINE</span>
|
| 331 |
+
<NeoBadge color="cyan">STOCHASTIC</NeoBadge>
|
| 332 |
+
</div>
|
| 333 |
+
<div className="font-mono text-xs flex gap-4">
|
| 334 |
+
<span className="text-slate-400">MOVES: <span className="text-cyan-400 text-lg">{stats.baseline.moves}</span></span>
|
| 335 |
+
<span className="text-slate-400">CRASH: <span className="text-red-400 text-lg">{stats.baseline.wasted}</span></span>
|
| 336 |
+
</div>
|
| 337 |
+
</div>
|
| 338 |
+
<NeoCard className="h-48 p-4 flex items-end bg-slate-900/50" aria-label="Baseline agent sorting visualization">
|
| 339 |
+
{baselineData.map((item) => (
|
| 340 |
+
<AgentBar
|
| 341 |
+
key={item.id}
|
| 342 |
+
value={item.value}
|
| 343 |
+
isHeavy={item.isHeavy}
|
| 344 |
+
lastAction={item.lastAction}
|
| 345 |
+
frustration={item.frustration}
|
| 346 |
+
isMemoryAgent={false}
|
| 347 |
+
/>
|
| 348 |
+
))}
|
| 349 |
+
</NeoCard>
|
| 350 |
+
</div>
|
| 351 |
+
|
| 352 |
+
{/* Memory Agent */}
|
| 353 |
+
<div className="space-y-2">
|
| 354 |
+
<div className="flex justify-between items-center px-1">
|
| 355 |
+
<div className="flex items-center gap-2">
|
| 356 |
+
<Brain className="w-4 h-4 text-fuchsia-400" />
|
| 357 |
+
<span className="font-mono text-sm tracking-wider text-fuchsia-100">THREAD_B::MEMORY</span>
|
| 358 |
+
<NeoBadge color="pink">ADAPTIVE</NeoBadge>
|
| 359 |
+
</div>
|
| 360 |
+
<div className="font-mono text-xs flex gap-4">
|
| 361 |
+
<span className="text-slate-400">MOVES: <span className="text-fuchsia-400 text-lg">{stats.memory.moves}</span></span>
|
| 362 |
+
<span className="text-slate-400">CRASH: <span className="text-green-400 text-lg">{stats.memory.wasted}</span></span>
|
| 363 |
+
</div>
|
| 364 |
+
</div>
|
| 365 |
+
<NeoCard className="h-48 p-4 flex items-end bg-slate-900/50 border-fuchsia-900/50" aria-label="Memory agent sorting visualization">
|
| 366 |
+
{memoryData.map((item) => (
|
| 367 |
+
<AgentBar
|
| 368 |
+
key={item.id}
|
| 369 |
+
value={item.value}
|
| 370 |
+
isHeavy={item.isHeavy}
|
| 371 |
+
lastAction={item.lastAction}
|
| 372 |
+
frustration={item.frustration}
|
| 373 |
+
isMemoryAgent={true}
|
| 374 |
+
/>
|
| 375 |
+
))}
|
| 376 |
+
</NeoCard>
|
| 377 |
+
</div>
|
| 378 |
+
|
| 379 |
+
{/* Legend */}
|
| 380 |
+
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-xs font-mono text-slate-500 pt-4 border-t border-slate-800">
|
| 381 |
+
<div className="flex items-center gap-2">
|
| 382 |
+
<div className="w-3 h-3 bg-slate-700 border border-slate-600" />
|
| 383 |
+
<span>OBSTACLE (HEAVY)</span>
|
| 384 |
+
</div>
|
| 385 |
+
<div className="flex items-center gap-2">
|
| 386 |
+
<div className="w-3 h-3 bg-amber-500 animate-pulse" />
|
| 387 |
+
<span>STUNNED (PENALTY)</span>
|
| 388 |
+
</div>
|
| 389 |
+
<div className="flex items-center gap-2">
|
| 390 |
+
<span className="text-fuchsia-500">██</span>
|
| 391 |
+
<span>FRUSTRATION MEMORY</span>
|
| 392 |
+
</div>
|
| 393 |
+
<div className="flex items-center gap-2">
|
| 394 |
+
<span className="text-slate-500 border border-slate-700 px-1 rounded">WAIT</span>
|
| 395 |
+
<span>SKIPPING (SMART)</span>
|
| 396 |
+
</div>
|
| 397 |
+
</div>
|
| 398 |
+
</div>
|
| 399 |
+
</div>
|
| 400 |
+
</div>
|
| 401 |
+
</div>
|
| 402 |
+
);
|
| 403 |
+
}
|
src/components/AgentBar.jsx
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react';
|
| 2 |
+
|
| 3 |
+
// Fix #4: Memoized bar component — only re-renders when its own data changes
|
| 4 |
+
const AgentBar = React.memo(({ value, isHeavy, lastAction, frustration, isMemoryAgent }) => {
|
| 5 |
+
const f = Math.min(5, frustration) / 5;
|
| 6 |
+
|
| 7 |
+
let barColor = isMemoryAgent
|
| 8 |
+
? 'bg-fuchsia-500 shadow-[0_0_8px_#d946ef]'
|
| 9 |
+
: 'bg-cyan-500 shadow-[0_0_8px_#06b6d4]';
|
| 10 |
+
let opacity = 'opacity-100';
|
| 11 |
+
|
| 12 |
+
if (isHeavy) barColor = 'bg-slate-700 border border-slate-600';
|
| 13 |
+
if (lastAction === 'stun') barColor = 'bg-amber-500 shadow-[0_0_10px_#f59e0b] animate-pulse';
|
| 14 |
+
if (lastAction === 'fail') barColor = 'bg-red-500 shadow-[0_0_15px_#ef4444]';
|
| 15 |
+
if (lastAction === 'skip') opacity = 'opacity-40';
|
| 16 |
+
|
| 17 |
+
return (
|
| 18 |
+
<div
|
| 19 |
+
className="flex-1 flex flex-col justify-end items-center group relative mx-[1px]"
|
| 20 |
+
style={{ height: '140px' }}
|
| 21 |
+
role="img"
|
| 22 |
+
aria-label={`Value ${value}, ${isHeavy ? 'obstacle' : 'normal'}${lastAction ? `, ${lastAction}` : ''}`}
|
| 23 |
+
>
|
| 24 |
+
{isMemoryAgent && frustration > 0.1 && lastAction !== 'stun' && (
|
| 25 |
+
<div
|
| 26 |
+
className="w-full absolute bottom-0 z-10 pointer-events-none transition-all duration-200 bg-red-600 mix-blend-overlay"
|
| 27 |
+
style={{ height: `${value}%`, opacity: f }}
|
| 28 |
+
/>
|
| 29 |
+
)}
|
| 30 |
+
<div className="absolute -top-6 flex flex-col items-center h-6 justify-end pointer-events-none">
|
| 31 |
+
{lastAction === 'fail' && <span className="text-red-500 font-bold text-[10px]">✕</span>}
|
| 32 |
+
{lastAction === 'skip' && <span className="text-slate-500 font-mono text-[10px]">WAIT</span>}
|
| 33 |
+
{lastAction === 'stun' && <span className="text-amber-400 font-bold text-[10px]">ERR</span>}
|
| 34 |
+
</div>
|
| 35 |
+
<div
|
| 36 |
+
className={`w-full rounded-sm transition-all duration-75 ${barColor} ${opacity}`}
|
| 37 |
+
style={{ height: `${value}%` }}
|
| 38 |
+
/>
|
| 39 |
+
</div>
|
| 40 |
+
);
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
AgentBar.displayName = 'AgentBar';
|
| 44 |
+
export default AgentBar;
|
src/components/Icons.jsx
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react';
|
| 2 |
+
|
| 3 |
+
// Fix #3: All icons accept and spread props (className, size, etc.)
|
| 4 |
+
export const Play = (props) => (
|
| 5 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"
|
| 6 |
+
fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
|
| 7 |
+
<polygon points="5 3 19 12 5 21 5 3" />
|
| 8 |
+
</svg>
|
| 9 |
+
);
|
| 10 |
+
|
| 11 |
+
export const Pause = (props) => (
|
| 12 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"
|
| 13 |
+
fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
|
| 14 |
+
<rect x="6" y="4" width="4" height="16" /><rect x="14" y="4" width="4" height="16" />
|
| 15 |
+
</svg>
|
| 16 |
+
);
|
| 17 |
+
|
| 18 |
+
export const RotateCcw = (props) => (
|
| 19 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"
|
| 20 |
+
fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
|
| 21 |
+
<polyline points="1 4 1 10 7 10" /><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10" />
|
| 22 |
+
</svg>
|
| 23 |
+
);
|
| 24 |
+
|
| 25 |
+
export const Zap = (props) => (
|
| 26 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"
|
| 27 |
+
fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
|
| 28 |
+
<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2" />
|
| 29 |
+
</svg>
|
| 30 |
+
);
|
| 31 |
+
|
| 32 |
+
export const Brain = (props) => (
|
| 33 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"
|
| 34 |
+
fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
|
| 35 |
+
<path d="M9.5 2A2.5 2.5 0 0 1 12 4.5v15a2.5 2.5 0 0 1-4.96.44 2.5 2.5 0 0 1-2.96-3.08 3 3 0 0 1-.34-5.58 2.5 2.5 0 0 1 1.32-4.24 2.5 2.5 0 0 1 1.98-3A2.5 2.5 0 0 1 9.5 2Z" />
|
| 36 |
+
<path d="M14.5 2A2.5 2.5 0 0 0 12 4.5v15a2.5 2.5 0 0 0 4.96.44 2.5 2.5 0 0 0 2.96-3.08 3 3 0 0 0 .34-5.58 2.5 2.5 0 0 0-1.32-4.24 2.5 2.5 0 0 0-1.98-3A2.5 2.5 0 0 0 14.5 2Z" />
|
| 37 |
+
</svg>
|
| 38 |
+
);
|
| 39 |
+
|
| 40 |
+
export const Settings = (props) => (
|
| 41 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"
|
| 42 |
+
fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
|
| 43 |
+
<circle cx="12" cy="12" r="3" />
|
| 44 |
+
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z" />
|
| 45 |
+
</svg>
|
| 46 |
+
);
|
| 47 |
+
|
| 48 |
+
export const Activity = (props) => (
|
| 49 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"
|
| 50 |
+
fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
|
| 51 |
+
<polyline points="22 12 18 12 15 21 9 3 6 12 2 12" />
|
| 52 |
+
</svg>
|
| 53 |
+
);
|
| 54 |
+
|
| 55 |
+
export const Cpu = (props) => (
|
| 56 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"
|
| 57 |
+
fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...props}>
|
| 58 |
+
<rect x="4" y="4" width="16" height="16" rx="2" ry="2" />
|
| 59 |
+
<rect x="9" y="9" width="6" height="6" />
|
| 60 |
+
<line x1="9" y1="1" x2="9" y2="4" /><line x1="15" y1="1" x2="15" y2="4" />
|
| 61 |
+
<line x1="9" y1="20" x2="9" y2="23" /><line x1="15" y1="20" x2="15" y2="23" />
|
| 62 |
+
<line x1="20" y1="9" x2="23" y2="9" /><line x1="20" y1="14" x2="23" y2="14" />
|
| 63 |
+
<line x1="1" y1="9" x2="4" y2="9" /><line x1="1" y1="14" x2="4" y2="14" />
|
| 64 |
+
</svg>
|
| 65 |
+
);
|
src/components/MiniGraph.jsx
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useMemo } from 'react';
|
| 2 |
+
|
| 3 |
+
// Fix #10: Memoized graph with computed max
|
| 4 |
+
const MiniGraph = React.memo(({ data }) => {
|
| 5 |
+
const maxVal = useMemo(() => {
|
| 6 |
+
let m = 10;
|
| 7 |
+
for (let i = 0; i < data.length; i++) {
|
| 8 |
+
if (data[i].baseline > m) m = data[i].baseline;
|
| 9 |
+
if (data[i].memory > m) m = data[i].memory;
|
| 10 |
+
}
|
| 11 |
+
return m;
|
| 12 |
+
}, [data]);
|
| 13 |
+
|
| 14 |
+
if (data.length < 2) {
|
| 15 |
+
return (
|
| 16 |
+
<div className="h-full w-full flex items-center justify-center text-slate-700 text-xs font-mono">
|
| 17 |
+
WAITING FOR DATA...
|
| 18 |
+
</div>
|
| 19 |
+
);
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
const width = 100;
|
| 23 |
+
const height = 100;
|
| 24 |
+
|
| 25 |
+
const makePath = (key) => {
|
| 26 |
+
let points = '';
|
| 27 |
+
for (let i = 0; i < data.length; i++) {
|
| 28 |
+
const x = (i / (data.length - 1)) * width;
|
| 29 |
+
const y = height - (data[i][key] / maxVal) * height;
|
| 30 |
+
if (i > 0) points += ' ';
|
| 31 |
+
points += `${x},${y}`;
|
| 32 |
+
}
|
| 33 |
+
return points;
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
return (
|
| 37 |
+
<svg viewBox={`0 0 ${width} ${height}`} className="w-full h-full overflow-visible" role="img" aria-label="Throughput comparison graph">
|
| 38 |
+
<line x1="0" y1="25" x2="100" y2="25" stroke="#334155" strokeWidth="0.5" strokeDasharray="2" />
|
| 39 |
+
<line x1="0" y1="50" x2="100" y2="50" stroke="#334155" strokeWidth="0.5" strokeDasharray="2" />
|
| 40 |
+
<line x1="0" y1="75" x2="100" y2="75" stroke="#334155" strokeWidth="0.5" strokeDasharray="2" />
|
| 41 |
+
<polyline
|
| 42 |
+
points={makePath('baseline')}
|
| 43 |
+
fill="none" stroke="#06b6d4" strokeWidth="2"
|
| 44 |
+
vectorEffect="non-scaling-stroke"
|
| 45 |
+
style={{ filter: 'drop-shadow(0 0 3px rgba(6,182,212,0.8))' }}
|
| 46 |
+
/>
|
| 47 |
+
<polyline
|
| 48 |
+
points={makePath('memory')}
|
| 49 |
+
fill="none" stroke="#d946ef" strokeWidth="2"
|
| 50 |
+
vectorEffect="non-scaling-stroke"
|
| 51 |
+
style={{ filter: 'drop-shadow(0 0 3px rgba(217,70,239,0.8))' }}
|
| 52 |
+
/>
|
| 53 |
+
</svg>
|
| 54 |
+
);
|
| 55 |
+
});
|
| 56 |
+
|
| 57 |
+
MiniGraph.displayName = 'MiniGraph';
|
| 58 |
+
export default MiniGraph;
|
src/components/UI.jsx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react';
|
| 2 |
+
|
| 3 |
+
export const NeoCard = ({ children, className = '', noBorder = false }) => (
|
| 4 |
+
<div className={`bg-slate-900/80 backdrop-blur-sm rounded-none border ${noBorder ? 'border-transparent' : 'border-slate-700'} shadow-lg relative overflow-hidden ${className}`}>
|
| 5 |
+
{!noBorder && (
|
| 6 |
+
<>
|
| 7 |
+
<div className="absolute top-0 left-0 w-2 h-2 border-t border-l border-cyan-500/50" />
|
| 8 |
+
<div className="absolute top-0 right-0 w-2 h-2 border-t border-r border-cyan-500/50" />
|
| 9 |
+
<div className="absolute bottom-0 left-0 w-2 h-2 border-b border-l border-cyan-500/50" />
|
| 10 |
+
<div className="absolute bottom-0 right-0 w-2 h-2 border-b border-r border-cyan-500/50" />
|
| 11 |
+
</>
|
| 12 |
+
)}
|
| 13 |
+
{children}
|
| 14 |
+
</div>
|
| 15 |
+
);
|
| 16 |
+
|
| 17 |
+
export const NeoBadge = ({ children, color = 'cyan' }) => {
|
| 18 |
+
const styles = {
|
| 19 |
+
cyan: 'bg-cyan-900/30 text-cyan-400 border-cyan-500/30 shadow-[0_0_10px_rgba(34,211,238,0.2)]',
|
| 20 |
+
pink: 'bg-fuchsia-900/30 text-fuchsia-400 border-fuchsia-500/30 shadow-[0_0_10px_rgba(232,121,249,0.2)]',
|
| 21 |
+
red: 'bg-red-900/30 text-red-400 border-red-500/30',
|
| 22 |
+
amber: 'bg-amber-900/30 text-amber-400 border-amber-500/30',
|
| 23 |
+
};
|
| 24 |
+
return (
|
| 25 |
+
<span className={`px-2 py-1 rounded-none border text-xs font-mono tracking-wider ${styles[color] || styles.cyan}`}>
|
| 26 |
+
{children}
|
| 27 |
+
</span>
|
| 28 |
+
);
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
// Fix #12: Stable slider component — onChange receives raw float, no inline closure needed
|
| 32 |
+
export const Slider = ({ label, value, onChange, min, max, step, unit }) => (
|
| 33 |
+
<div className="flex flex-col gap-1 mb-3">
|
| 34 |
+
<label className="flex justify-between text-xs font-mono text-slate-400">
|
| 35 |
+
<span className="uppercase tracking-widest">{label}</span>
|
| 36 |
+
<span className="text-cyan-400">{value}{unit}</span>
|
| 37 |
+
</label>
|
| 38 |
+
<input
|
| 39 |
+
type="range"
|
| 40 |
+
min={min} max={max} step={step}
|
| 41 |
+
value={value}
|
| 42 |
+
onChange={onChange}
|
| 43 |
+
className="w-full h-1 bg-slate-700 rounded-lg appearance-none cursor-pointer accent-cyan-500 hover:accent-cyan-400"
|
| 44 |
+
/>
|
| 45 |
+
</div>
|
| 46 |
+
);
|
src/index.css
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@tailwind base;
|
| 2 |
+
@tailwind components;
|
| 3 |
+
@tailwind utilities;
|
src/main.jsx
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react';
|
| 2 |
+
import ReactDOM from 'react-dom/client';
|
| 3 |
+
import App from './App';
|
| 4 |
+
import './index.css';
|
| 5 |
+
|
| 6 |
+
ReactDOM.createRoot(document.getElementById('root')).render(
|
| 7 |
+
<React.StrictMode>
|
| 8 |
+
<App />
|
| 9 |
+
</React.StrictMode>
|
| 10 |
+
);
|
tailwind.config.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** @type {import('tailwindcss').Config} */
|
| 2 |
+
export default {
|
| 3 |
+
content: ['./index.html', './src/**/*.{js,jsx}'],
|
| 4 |
+
theme: { extend: {} },
|
| 5 |
+
plugins: [],
|
| 6 |
+
};
|
vite.config.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { defineConfig } from 'vite';
|
| 2 |
+
import react from '@vitejs/plugin-react';
|
| 3 |
+
|
| 4 |
+
export default defineConfig({
|
| 5 |
+
plugins: [react()],
|
| 6 |
+
server: { host: '0.0.0.0', port: 7860 },
|
| 7 |
+
});
|