Paint agent interface into aquarium buffer

This commit is contained in:
Meta Vens 2026-05-05 01:13:09 +01:00
commit a995062b64
2 changed files with 555 additions and 285 deletions

View file

@ -157,6 +157,12 @@ type ProjectedAgent = ConstellationSpec & {
jobs: number;
review: string;
};
type AquariumOption = {
label: string;
deck?: DeckId;
subdeck?: string;
action?: OperatorAction;
};
const deckSubmenus = {
command: ["run", "connection", "signals"],
state: ["environment", "planning", "graph"],
@ -170,6 +176,46 @@ const deckLabels: Record<keyof typeof deckSubmenus, string> = {
artifacts: "Artifacts",
};
type DeckId = keyof typeof deckSubmenus;
const aquariumOptionsByAgent: Record<string, AquariumOption[]> = {
coordinator: [
{ label: "Signals", deck: "command", subdeck: "signals" },
{ label: "Run", deck: "command", subdeck: "run" },
{ label: "Checkpoint", action: "prepareCheckpoint" },
],
imagination: [
{ label: "Planning", deck: "state", subdeck: "planning" },
{ label: "Launch", action: "launchImagination" },
{ label: "Read", action: "readImaginationResult" },
{ label: "Accept", action: "acceptImagination" },
],
research: [
{ label: "State", deck: "state", subdeck: "graph" },
{ label: "Artifacts", deck: "artifacts", subdeck: "bundles" },
],
modeling: [
{ label: "Graph", deck: "state", subdeck: "graph" },
{ label: "Launch", action: "launchModeling" },
{ label: "Read", action: "readModelingResult" },
{ label: "Accept", action: "acceptModeling" },
],
implementation: [
{ label: "Run", deck: "command", subdeck: "run" },
{ label: "Continue", action: "continueImplementation" },
{ label: "Artifacts", deck: "artifacts", subdeck: "bundles" },
],
verification: [
{ label: "Findings", deck: "agents", subdeck: "findings" },
{ label: "Launch", action: "launchVerification" },
{ label: "Read", action: "readVerificationResult" },
{ label: "Accept", action: "acceptVerification" },
],
reorientation: [
{ label: "Continuity", deck: "command", subdeck: "signals" },
{ label: "Launch", action: "launchReorient" },
{ label: "Read", action: "readReorientResult" },
{ label: "Accept", action: "acceptReorient" },
],
};
const actionButtons: Array<{
action: OperatorAction;
label: string;
@ -615,6 +661,35 @@ export function App() {
setSubdeckByDeck((current) => ({ ...current, [deck]: subdeck }));
}
function actionBlocked(action: OperatorAction) {
const button = actionButtons.find((item) => item.action === action);
if (!button) return true;
return Boolean(
runningAction !== null ||
(button.requiresThread && !currentThreadId) ||
(button.requiresReadyState && !readyState) ||
(button.requiresImaginationPatch && !canAcceptImagination) ||
(button.requiresModelingPatch && !canAcceptModeling) ||
(button.requiresVerificationResult && !canAcceptVerification) ||
(button.requiresReorientResult && !canAcceptReorient) ||
(button.requiresPlanningDraft && !canAdoptDraft) ||
(button.requiresContinueImplementation && !canContinueImplementation) ||
(button.requiresContinueImplementation && implementationNoDiffPending),
);
}
function handleAquariumOption(option: AquariumOption) {
if (option.deck) {
selectDeck(option.deck);
if (option.subdeck) {
selectSubdeck(option.deck, option.subdeck);
}
}
if (option.action && !actionBlocked(option.action)) {
void runAction(option.action);
}
}
const actionControls = actionButtons.map((button) => {
const needsThread = button.requiresThread && !currentThreadId;
const needsState = button.requiresReadyState && !readyState;
@ -695,6 +770,10 @@ export function App() {
reorient={reorient}
jobs={jobs}
variant="fullscreen"
activeDeck={activeDeck}
activeSubdeck={activeSubdeck}
onAgentOption={handleAquariumOption}
isActionBlocked={actionBlocked}
/>
<div className="hudGrid" aria-hidden="true" />
@ -1134,6 +1213,10 @@ function AgentConstellation({
reorient,
jobs,
variant = "band",
activeDeck,
activeSubdeck,
onAgentOption,
isActionBlocked,
}: {
roles: any[];
roleResults: any;
@ -1144,9 +1227,15 @@ function AgentConstellation({
reorient: any;
jobs: any[];
variant?: "band" | "fullscreen";
activeDeck?: DeckId;
activeSubdeck?: string;
onAgentOption?: (option: AquariumOption) => void;
isActionBlocked?: (action: OperatorAction) => boolean;
}) {
const rootRef = useRef<HTMLDivElement | null>(null);
const canvasRef = useRef<HTMLCanvasElement | null>(null);
const pointerRef = useRef({ active: false, x: 0, y: 0 });
const hotZonesRef = useRef<Array<{ x: number; y: number; radius: number; option: AquariumOption }>>([]);
const latestProjectedRef = useRef<Array<ProjectedAgent & { x: number; y: number }>>([]);
const [selectedAgentId, setSelectedAgentId] = useState("coordinator");
const agents = useMemo<ProjectedAgent[]>(() => {
return constellationSpecs.map((spec) => {
@ -1206,53 +1295,32 @@ function AgentConstellation({
useEffect(() => {
const canvas = canvasRef.current;
const root = rootRef.current;
if (!canvas || !root) return;
if (!canvas) return;
const canvasElement = canvas;
const rootElement = root;
const screen = canvasElement.getContext("2d", { alpha: false });
if (!screen) return;
const colorBuffer = document.createElement("canvas");
const scratchBuffer = document.createElement("canvas");
const color = colorBuffer.getContext("2d", { alpha: false });
const scratch = scratchBuffer.getContext("2d", { alpha: false });
if (!color || !scratch) return;
const screenContext = screen;
const colorContext = color;
const scratchContext = scratch;
let frame = 0;
const agentData = agents.map((agent) => ({
id: agent.id,
baseX: agent.baseX,
baseY: agent.baseY,
driftX: agent.driftX,
driftY: agent.driftY,
phase: agent.phase,
activity: agent.activity,
color: hexToRgb(agent.color),
let tick = 0;
const motion = new globalThis.Map<string, {
x: number;
y: number;
vx: number;
vy: number;
lastTextTick: number;
}>();
const agentData = agents.map((agent, index) => ({
...agent,
index,
}));
function projectAgent(agent: (typeof agentData)[number], time: number, width: number, height: number) {
const compactPosition = width < 540 ? compactConstellationPositions[agent.id] : undefined;
const fullscreenPosition = variant === "fullscreen" ? fullscreenConstellationPositions[agent.id] : undefined;
const baseY = compactPosition?.y ?? fullscreenPosition?.y ?? agent.baseY;
const resolvedBaseX = compactPosition?.x ?? fullscreenPosition?.x ?? agent.baseX;
const x =
(resolvedBaseX / 100) * width +
Math.sin(time * 0.42 + agent.phase) * agent.driftX * 2.8 +
Math.cos(time * 0.19 + agent.phase * 0.7) * agent.activity * 4.5;
const y =
(baseY / 100) * height +
Math.cos(time * 0.35 + agent.phase) * agent.driftY * 3.1 +
Math.sin(time * 0.23 + agent.phase * 0.9) * agent.activity * 4;
return { ...agent, x, y };
}
function updateProjectedDom(time: number, width: number, height: number) {
return agentData.map((agent) => {
const projected = projectAgent(agent, time, width, height);
const node = rootElement.querySelector<HTMLElement>(`[data-agent-node="${agent.id}"]`);
const thought = rootElement.querySelector<HTMLElement>(`[data-agent-thought="${agent.id}"]`);
const tilt = Math.sin(time * 0.7 + agent.phase) * 4;
for (const element of [node, thought]) {
element?.style.setProperty("--agent-x", `${projected.x}px`);
element?.style.setProperty("--agent-y", `${projected.y}px`);
element?.style.setProperty("--agent-tilt", `${tilt}deg`);
}
return projected;
});
}
function resizeCanvas() {
const bounds = canvasElement.getBoundingClientRect();
const dpr = Math.min(window.devicePixelRatio || 1, 2);
@ -1262,167 +1330,389 @@ function AgentConstellation({
canvasElement.width = width;
canvasElement.height = height;
}
return { cssWidth: bounds.width, cssHeight: bounds.height, width, height, dpr };
}
const gl = canvasElement.getContext("webgl2", { alpha: true, antialias: false, preserveDrawingBuffer: true });
if (!gl) {
const context = canvasElement.getContext("2d");
if (!context) return;
const drawFallback = (millis: number) => {
const time = millis / 1000;
const { cssWidth, cssHeight, width, height, dpr } = resizeCanvas();
const projected = updateProjectedDom(time, cssWidth, cssHeight);
context.setTransform(dpr, 0, 0, dpr, 0, 0);
context.clearRect(0, 0, cssWidth, cssHeight);
const haze = context.createLinearGradient(0, 0, cssWidth, cssHeight);
haze.addColorStop(0, "rgba(38, 53, 46, 0.66)");
haze.addColorStop(0.45, "rgba(30, 36, 60, 0.44)");
haze.addColorStop(1, "rgba(80, 57, 35, 0.48)");
context.fillStyle = haze;
context.fillRect(0, 0, cssWidth, cssHeight);
for (const agent of projected) {
context.strokeStyle = `rgba(${agent.color.map((channel) => Math.floor(channel * 255)).join(", ")}, ${0.18 + agent.activity * 0.22})`;
context.lineWidth = 1.2;
for (let ring = 0; ring < 3; ring += 1) {
context.beginPath();
context.arc(agent.x, agent.y, 26 + ring * 34 + Math.sin(time * 2 + ring + agent.phase) * 8, 0, Math.PI * 2);
context.stroke();
}
}
frame = requestAnimationFrame(drawFallback);
};
frame = requestAnimationFrame(drawFallback);
return () => cancelAnimationFrame(frame);
}
const vertexSource = `#version 300 es
precision highp float;
out vec2 v_uv;
const vec2 positions[3] = vec2[3](
vec2(-1.0, -1.0),
vec2(3.0, -1.0),
vec2(-1.0, 3.0)
);
void main() {
vec2 position = positions[gl_VertexID];
v_uv = position * 0.5 + 0.5;
gl_Position = vec4(position, 0.0, 1.0);
}`;
const fragmentSource = `#version 300 es
precision highp float;
in vec2 v_uv;
out vec4 out_color;
uniform vec2 u_resolution;
uniform float u_time;
uniform vec2 u_agents[7];
uniform float u_activity[7];
uniform vec3 u_colors[7];
uniform int u_count;
float hash(vec2 p) {
p = fract(p * vec2(123.34, 456.21));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float noise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(hash(i + vec2(0.0, 0.0)), hash(i + vec2(1.0, 0.0)), u.x),
mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x),
u.y
);
}
float fbm(vec2 p) {
float value = 0.0;
float amplitude = 0.5;
for (int octave = 0; octave < 5; octave += 1) {
value += amplitude * noise(p);
p *= 2.04;
amplitude *= 0.52;
}
return value;
}
void main() {
vec2 uv = v_uv;
vec2 aspect = vec2(u_resolution.x / max(u_resolution.y, 1.0), 1.0);
float slow = fbm(uv * vec2(2.4, 1.8) + vec2(u_time * 0.026, -u_time * 0.018));
float fine = fbm(uv * 8.0 + slow + vec2(-u_time * 0.055, u_time * 0.04));
vec3 color = mix(vec3(0.045, 0.075, 0.068), vec3(0.17, 0.12, 0.18), slow);
color += vec3(0.05, 0.045, 0.028) * fine;
float alpha = 0.88;
for (int i = 0; i < 7; i += 1) {
if (i >= u_count) {
break;
}
vec2 agent = u_agents[i] / u_resolution;
vec2 delta = (uv - agent) * aspect;
float radius = length(delta);
float pulse = sin(radius * 46.0 - u_time * (2.0 + u_activity[i] * 2.4) + float(i) * 0.9);
float wake = smoothstep(0.34, 0.0, radius) * (0.45 + 0.55 * pulse) * u_activity[i];
float ember = exp(-radius * 18.0) * (0.45 + u_activity[i] * 0.72);
color += u_colors[i] * (wake * 0.13 + ember * 0.42);
alpha += wake * 0.03;
}
float vignette = smoothstep(0.82, 0.18, distance(uv, vec2(0.5)));
color *= 0.78 + vignette * 0.44;
out_color = vec4(color, clamp(alpha, 0.0, 0.96));
}`;
const program = createConstellationProgram(gl, vertexSource, fragmentSource);
if (!program) return;
const resolutionLocation = gl.getUniformLocation(program, "u_resolution");
const timeLocation = gl.getUniformLocation(program, "u_time");
const agentsLocation = gl.getUniformLocation(program, "u_agents");
const activityLocation = gl.getUniformLocation(program, "u_activity");
const colorsLocation = gl.getUniformLocation(program, "u_colors");
const countLocation = gl.getUniformLocation(program, "u_count");
const vao = gl.createVertexArray();
const colorBuffer = new Float32Array(7 * 3);
for (let index = 0; index < agentData.length; index += 1) {
colorBuffer.set(agentData[index].color, index * 3);
}
const activityBuffer = new Float32Array(7);
const positionBuffer = new Float32Array(7 * 2);
const draw = (millis: number) => {
const time = millis / 1000;
const { cssWidth, cssHeight, width, height, dpr } = resizeCanvas();
const projected = updateProjectedDom(time, cssWidth, cssHeight);
for (let index = 0; index < projected.length; index += 1) {
positionBuffer[index * 2] = projected[index].x * dpr;
positionBuffer[index * 2 + 1] = (cssHeight - projected[index].y) * dpr;
activityBuffer[index] = projected[index].activity;
if (colorBuffer.width !== width || colorBuffer.height !== height) {
colorBuffer.width = width;
colorBuffer.height = height;
scratchBuffer.width = width;
scratchBuffer.height = height;
colorContext.fillStyle = "#07110e";
colorContext.fillRect(0, 0, width, height);
}
gl.viewport(0, 0, width, height);
gl.clearColor(0, 0, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.useProgram(program);
gl.bindVertexArray(vao);
gl.uniform2f(resolutionLocation, width, height);
gl.uniform1f(timeLocation, time);
gl.uniform1i(countLocation, projected.length);
gl.uniform2fv(agentsLocation, positionBuffer);
gl.uniform1fv(activityLocation, activityBuffer);
gl.uniform3fv(colorsLocation, colorBuffer);
gl.drawArrays(gl.TRIANGLES, 0, 3);
frame = requestAnimationFrame(draw);
};
return { width, height, dpr };
}
frame = requestAnimationFrame(draw);
function basePoint(agent: (typeof agentData)[number], width: number, height: number) {
const compactPosition = width < 540 ? compactConstellationPositions[agent.id] : undefined;
const fullscreenPosition = variant === "fullscreen" ? fullscreenConstellationPositions[agent.id] : undefined;
const baseY = compactPosition?.y ?? fullscreenPosition?.y ?? agent.baseY;
const resolvedBaseX = compactPosition?.x ?? fullscreenPosition?.x ?? agent.baseX;
return {
x: (resolvedBaseX / 100) * width,
y: (baseY / 100) * height,
};
}
function updateMotion(time: number, width: number, height: number) {
return agentData.map((agent) => {
const base = basePoint(agent, width, height);
const state = motion.get(agent.id) ?? {
x: base.x,
y: base.y,
vx: 0,
vy: 0,
lastTextTick: -999,
};
const liveliness = Math.max(0.05, agent.activity);
const hoverPull = pointerRef.current.active ? pointerPull(agent, state.x, state.y) : { x: 0, y: 0 };
const swim = variant === "fullscreen" ? 46 + liveliness * 92 : 10 + liveliness * 24;
const speed = 0.010 + liveliness * 0.034;
const targetX = base.x + Math.sin(time * (0.42 + liveliness * 0.52) + agent.phase) * swim + hoverPull.x;
const targetY = base.y + Math.cos(time * (0.36 + liveliness * 0.44) + agent.phase * 1.7) * swim * 0.62 + hoverPull.y;
state.vx = state.vx * 0.88 + (targetX - state.x) * speed;
state.vy = state.vy * 0.88 + (targetY - state.y) * speed;
state.x = clamp(state.x + state.vx, 44, width - 44);
state.y = clamp(state.y + state.vy, 56, height - 56);
motion.set(agent.id, state);
return { ...agent, ...state, speed: Math.hypot(state.vx, state.vy) };
});
}
function pointerPull(agent: ProjectedAgent, x: number, y: number) {
const pointer = pointerRef.current;
const dx = pointer.x - x;
const dy = pointer.y - y;
const distance = Math.hypot(dx, dy);
if (distance > 180 || distance < 1) return { x: 0, y: 0 };
const strength = (1 - distance / 180) * (18 + agent.activity * 38);
return { x: (dx / distance) * strength, y: (dy / distance) * strength };
}
function drawFrame(millis: number) {
const time = millis / 1000;
tick += 1;
const { width, height } = resizeCanvas();
const projected = updateMotion(time, width, height);
latestProjectedRef.current = projected;
const hovered = pointerRef.current.active ? nearestAgent(projected, pointerRef.current.x, pointerRef.current.y) : null;
const activeAgent = hovered ?? projected.find((agent) => agent.id === selectedAgentId) ?? projected[0];
scratchContext.globalCompositeOperation = "source-over";
scratchContext.globalAlpha = 1;
scratchContext.filter = "none";
scratchContext.fillStyle = "rgba(4, 9, 7, 0.16)";
scratchContext.fillRect(0, 0, width, height);
scratchContext.globalAlpha = 0.972;
scratchContext.filter = "blur(1.4px) saturate(1.045)";
const driftX = Math.sin(time * 0.17) * 6;
const driftY = Math.cos(time * 0.13) * 5;
scratchContext.drawImage(colorBuffer, -8 + driftX, -6 + driftY, width + 16, height + 12);
scratchContext.filter = "none";
colorContext.globalAlpha = 1;
colorContext.drawImage(scratchBuffer, 0, 0);
drawBackgroundTint(colorContext, width, height, time);
drawWakes(colorContext, projected, time);
for (const agent of projected) {
const isHot = agent.id === hovered?.id || agent.id === selectedAgentId;
const state = motion.get(agent.id);
if (state && (isHot || tick - state.lastTextTick > 60 + agent.index * 19)) {
drawThought(colorContext, agent, width, height, isHot);
state.lastTextTick = tick;
}
drawAgent(colorContext, agent, isHot);
}
if (activeAgent) {
drawOptions(colorContext, activeAgent, width, height);
}
drawActiveDeckGlyph(colorContext, width, height);
screenContext.imageSmoothingEnabled = true;
screenContext.drawImage(colorBuffer, 0, 0);
frame = requestAnimationFrame(drawFrame);
}
frame = requestAnimationFrame(drawFrame);
return () => {
cancelAnimationFrame(frame);
gl.deleteVertexArray(vao);
gl.deleteProgram(program);
};
}, [agents, variant]);
}, [activeDeck, activeSubdeck, agents, isActionBlocked, selectedAgentId, variant]);
function canvasPoint(event: React.PointerEvent<HTMLCanvasElement>) {
const canvas = canvasRef.current;
if (!canvas) return { x: 0, y: 0 };
const rect = canvas.getBoundingClientRect();
return {
x: ((event.clientX - rect.left) / rect.width) * canvas.width,
y: ((event.clientY - rect.top) / rect.height) * canvas.height,
};
}
function handlePointerMove(event: React.PointerEvent<HTMLCanvasElement>) {
const point = canvasPoint(event);
pointerRef.current = { active: true, ...point };
}
function handlePointerLeave() {
pointerRef.current = { active: false, x: 0, y: 0 };
}
function handleCanvasClick() {
const pointer = pointerRef.current;
const hit = hotZonesRef.current.find((zone) => Math.hypot(zone.x - pointer.x, zone.y - pointer.y) <= zone.radius);
if (hit) {
onAgentOption?.(hit.option);
return;
}
const agent = nearestAgent(latestProjectedRef.current, pointer.x, pointer.y, 96);
if (agent) {
setSelectedAgentId(agent.id);
}
}
function nearestAgent<T extends ProjectedAgent & { x: number; y: number }>(projected: T[], x: number, y: number, limit = 180) {
let best: T | null = null;
let bestDistance = limit;
for (const agent of projected) {
const distance = Math.hypot(agent.x - x, agent.y - y);
if (distance < bestDistance) {
best = agent;
bestDistance = distance;
}
}
return best;
}
function drawBackgroundTint(ctx: CanvasRenderingContext2D, width: number, height: number, time: number) {
ctx.save();
ctx.globalCompositeOperation = "source-over";
ctx.globalAlpha = 0.42;
const gradient = ctx.createRadialGradient(
width * (0.42 + Math.sin(time * 0.11) * 0.05),
height * (0.44 + Math.cos(time * 0.09) * 0.04),
80,
width * 0.5,
height * 0.5,
Math.max(width, height) * 0.82,
);
gradient.addColorStop(0, "rgba(52, 84, 70, 0.22)");
gradient.addColorStop(0.46, "rgba(23, 17, 36, 0.14)");
gradient.addColorStop(1, "rgba(5, 10, 8, 0.34)");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, width, height);
ctx.restore();
}
function drawWakes(ctx: CanvasRenderingContext2D, projected: Array<ProjectedAgent & { x: number; y: number; vx: number; vy: number; speed: number }>, time: number) {
ctx.save();
ctx.globalCompositeOperation = "lighter";
for (const agent of projected) {
const speed = Math.min(1, agent.speed / 8);
const radius = 42 + agent.activity * 62 + speed * 80;
const glow = ctx.createRadialGradient(agent.x, agent.y, 5, agent.x, agent.y, radius);
glow.addColorStop(0, hexAlpha(agent.glow, 0.28 + agent.activity * 0.22));
glow.addColorStop(0.38, hexAlpha(agent.color, 0.12 + speed * 0.18));
glow.addColorStop(1, "rgba(0, 0, 0, 0)");
ctx.fillStyle = glow;
ctx.beginPath();
ctx.arc(agent.x, agent.y, radius, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = hexAlpha(agent.color, 0.08 + agent.activity * 0.12);
ctx.lineWidth = 1.4 + agent.activity * 2.2;
for (let ring = 0; ring < 3; ring += 1) {
ctx.beginPath();
ctx.arc(
agent.x - agent.vx * (5 + ring * 4),
agent.y - agent.vy * (5 + ring * 4),
24 + ring * 32 + Math.sin(time * 2.3 + ring + agent.phase) * 7,
0,
Math.PI * 2,
);
ctx.stroke();
}
}
ctx.restore();
}
function drawAgent(ctx: CanvasRenderingContext2D, agent: ProjectedAgent & { x: number; y: number; vx: number; vy: number; speed: number }, hot: boolean) {
const size = 34 + agent.activity * 18 + (hot ? 8 : 0);
const tilt = Math.atan2(agent.vy, agent.vx || 0.001) * 0.16;
ctx.save();
ctx.translate(agent.x, agent.y);
ctx.rotate(tilt);
ctx.globalCompositeOperation = "lighter";
ctx.shadowColor = agent.glow;
ctx.shadowBlur = 18 + agent.activity * 26;
ctx.fillStyle = agent.color;
drawAgentPath(ctx, agent.shape, size);
ctx.fill();
ctx.shadowBlur = 0;
ctx.strokeStyle = "rgba(255, 255, 255, 0.72)";
ctx.lineWidth = hot ? 2.4 : 1.2;
ctx.stroke();
ctx.globalCompositeOperation = "source-over";
ctx.fillStyle = "#fffaf0";
ctx.font = `800 ${Math.max(14, size * 0.42)}px Inter, system-ui, sans-serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(agent.glyph, 0, 1);
ctx.restore();
ctx.save();
ctx.globalCompositeOperation = "source-over";
ctx.fillStyle = "rgba(5, 12, 9, 0.72)";
ctx.strokeStyle = hexAlpha(agent.color, 0.52);
roundedRect(ctx, agent.x - 42, agent.y + size * 0.64, 84, 36, 7);
ctx.fill();
ctx.stroke();
ctx.fillStyle = "rgba(247, 255, 247, 0.92)";
ctx.font = "800 11px Inter, system-ui, sans-serif";
ctx.textAlign = "center";
ctx.fillText(agent.name, agent.x, agent.y + size * 0.64 + 14);
ctx.fillStyle = "rgba(226, 245, 225, 0.74)";
ctx.font = "800 9px Inter, system-ui, sans-serif";
ctx.fillText(agent.status.slice(0, 16).toUpperCase(), agent.x, agent.y + size * 0.64 + 28);
ctx.restore();
}
function drawAgentPath(ctx: CanvasRenderingContext2D, shape: string, size: number) {
const r = size / 2;
ctx.beginPath();
if (shape === "kite" || shape === "diamond") {
ctx.moveTo(0, -r);
ctx.lineTo(r * 0.9, 0);
ctx.lineTo(0, r);
ctx.lineTo(-r * 0.9, 0);
ctx.closePath();
} else if (shape === "hex") {
for (let index = 0; index < 6; index += 1) {
const angle = Math.PI / 6 + index * (Math.PI / 3);
const x = Math.cos(angle) * r;
const y = Math.sin(angle) * r;
if (index === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.closePath();
} else if (shape === "capsule") {
roundedRect(ctx, -r * 1.18, -r * 0.74, r * 2.36, r * 1.48, r * 0.54);
} else if (shape === "lens") {
ctx.ellipse(0, 0, r * 1.08, r * 0.76, Math.PI / 4, 0, Math.PI * 2);
} else if (shape === "seed") {
ctx.ellipse(0, 0, r * 0.82, r * 1.08, Math.PI / 4, 0, Math.PI * 2);
} else {
ctx.arc(0, 0, r, 0, Math.PI * 2);
}
}
function drawThought(ctx: CanvasRenderingContext2D, agent: ProjectedAgent & { x: number; y: number }, width: number, height: number, hot: boolean) {
const boxWidth = Math.min(280, Math.max(180, width * 0.2));
const x = clamp(agent.x + (agent.x > width * 0.7 ? -boxWidth - 44 : 44), 16, width - boxWidth - 16);
const y = clamp(agent.y - 86, 16, height - 132);
ctx.save();
ctx.globalCompositeOperation = "lighter";
ctx.shadowColor = agent.glow;
ctx.shadowBlur = hot ? 18 : 8;
ctx.fillStyle = hexAlpha(agent.color, hot ? 0.22 : 0.12);
roundedRect(ctx, x - 6, y - 6, boxWidth + 12, 104, 10);
ctx.fill();
ctx.globalCompositeOperation = "source-over";
ctx.shadowBlur = 0;
ctx.fillStyle = hot ? "rgba(248, 252, 242, 0.86)" : "rgba(248, 252, 242, 0.52)";
ctx.strokeStyle = hexAlpha(agent.color, hot ? 0.82 : 0.38);
roundedRect(ctx, x, y, boxWidth, 92, 9);
ctx.fill();
ctx.stroke();
ctx.fillStyle = agent.color;
ctx.font = "900 12px Inter, system-ui, sans-serif";
ctx.textAlign = "left";
ctx.textBaseline = "top";
ctx.fillText(agent.name.toUpperCase(), x + 12, y + 10);
ctx.fillStyle = "rgba(23, 32, 24, 0.78)";
ctx.font = "700 13px Inter, system-ui, sans-serif";
wrapCanvasText(ctx, agent.thought, x + 12, y + 30, boxWidth - 24, 17, 3);
ctx.restore();
}
function drawOptions(ctx: CanvasRenderingContext2D, agent: ProjectedAgent & { x: number; y: number }, width: number, height: number) {
const options = aquariumOptionsByAgent[agent.id] ?? [];
hotZonesRef.current = [];
if (!options.length) return;
const radius = width < 540 ? 74 : 96;
const arc = Math.min(Math.PI * 1.25, Math.max(Math.PI * 0.72, options.length * 0.36));
const start = -Math.PI / 2 - arc / 2;
ctx.save();
ctx.font = "900 11px Inter, system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
for (let index = 0; index < options.length; index += 1) {
const option = options[index];
const angle = start + (arc * (index + 0.5)) / options.length;
const x = clamp(agent.x + Math.cos(angle) * radius, 48, width - 48);
const y = clamp(agent.y + Math.sin(angle) * radius, 56, height - 56);
const disabled = option.action ? Boolean(isActionBlocked?.(option.action)) : false;
const hot = pointerRef.current.active && Math.hypot(pointerRef.current.x - x, pointerRef.current.y - y) < 34;
if (!disabled) {
hotZonesRef.current.push({ x, y, radius: 36, option });
}
ctx.globalCompositeOperation = "lighter";
ctx.fillStyle = hexAlpha(agent.glow, hot ? 0.32 : 0.16);
ctx.beginPath();
ctx.arc(x, y, hot ? 42 : 34, 0, Math.PI * 2);
ctx.fill();
ctx.globalCompositeOperation = "source-over";
ctx.fillStyle = disabled ? "rgba(8, 14, 12, 0.52)" : hot ? hexAlpha(agent.color, 0.8) : "rgba(8, 14, 12, 0.74)";
ctx.strokeStyle = disabled ? "rgba(226, 245, 225, 0.18)" : hexAlpha(agent.glow, hot ? 0.92 : 0.54);
roundedRect(ctx, x - 38, y - 17, 76, 34, 17);
ctx.fill();
ctx.stroke();
ctx.fillStyle = disabled ? "rgba(236, 246, 235, 0.34)" : "#fbfff8";
ctx.fillText(option.label.toUpperCase(), x, y + 1);
}
ctx.restore();
}
function drawActiveDeckGlyph(ctx: CanvasRenderingContext2D, width: number, height: number) {
if (!activeDeck) return;
ctx.save();
ctx.globalCompositeOperation = "lighter";
ctx.fillStyle = "rgba(247, 189, 88, 0.08)";
ctx.font = `900 ${Math.max(48, Math.min(width, height) * 0.09)}px Inter, system-ui, sans-serif`;
ctx.textAlign = "right";
ctx.textBaseline = "bottom";
ctx.fillText(`${deckLabels[activeDeck]} / ${activeSubdeck ?? ""}`.toUpperCase(), width - 24, height - 22);
ctx.restore();
}
function roundedRect(ctx: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, radius: number) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function wrapCanvasText(ctx: CanvasRenderingContext2D, value: string, x: number, y: number, maxWidth: number, lineHeight: number, maxLines: number) {
const words = value.split(/\s+/);
let line = "";
let lineCount = 0;
for (const word of words) {
const test = line ? `${line} ${word}` : word;
if (ctx.measureText(test).width > maxWidth && line) {
ctx.fillText(lineCount + 1 === maxLines ? `${line}...` : line, x, y + lineCount * lineHeight);
line = word;
lineCount += 1;
if (lineCount >= maxLines) return;
} else {
line = test;
}
}
if (line && lineCount < maxLines) {
ctx.fillText(line, x, y + lineCount * lineHeight);
}
}
return (
<section className={`${variant === "fullscreen" ? "immersiveConstellation" : "sectionBand agentConstellation"}`} aria-label="Agent state overview">
@ -1438,113 +1728,85 @@ void main() {
</div>
</div>
)}
<div className="agentStage" ref={rootRef}>
<canvas ref={canvasRef} className="agentSmokeCanvas" aria-hidden="true" />
<div className="agentStage">
<canvas
ref={canvasRef}
className="agentSmokeCanvas"
aria-hidden="true"
onPointerMove={handlePointerMove}
onPointerLeave={handlePointerLeave}
onClick={handleCanvasClick}
/>
<div className="agentStageVignette" aria-hidden="true" />
{agents.map((agent) => (
<button
className={`agentCharacter ${agent.shape} ${agent.tone} ${selectedAgentId === agent.id ? "selected" : ""}`}
key={agent.id}
type="button"
data-agent-node={agent.id}
onClick={() => setSelectedAgentId(agent.id)}
title={`${agent.name}: ${agent.thought}`}
style={
{
"--agent-x": `${agent.baseX}%`,
"--agent-y": `${agent.baseY}%`,
"--agent-color": agent.color,
"--agent-glow": agent.glow,
"--agent-activity": agent.activity,
"--agent-bubble-opacity": 0.38 + agent.activity * 0.28,
} as React.CSSProperties
}
>
<span className="agentGlyph" aria-hidden="true">{agent.glyph}</span>
<span className="agentCaption">
<strong>{agent.name}</strong>
<span>{agent.status}</span>
</span>
</button>
))}
{agents.map((agent) => (
<div
className={`thoughtBubble ${agent.tone} ${selectedAgentId === agent.id ? "selected" : ""}`}
key={`${agent.id}-thought`}
data-agent-thought={agent.id}
style={
{
"--agent-x": `${agent.baseX}%`,
"--agent-y": `${agent.baseY}%`,
"--agent-color": agent.color,
"--agent-glow": agent.glow,
"--agent-activity": agent.activity,
"--agent-bubble-opacity": 0.38 + agent.activity * 0.28,
} as React.CSSProperties
}
>
<strong>{agent.name}</strong>
<span>{agent.thought}</span>
{variant === "band" ? (
agents.map((agent) => (
<button
className={`agentCharacter ${agent.shape} ${agent.tone} ${selectedAgentId === agent.id ? "selected" : ""}`}
key={agent.id}
type="button"
data-agent-node={agent.id}
onClick={() => setSelectedAgentId(agent.id)}
title={`${agent.name}: ${agent.thought}`}
style={
{
"--agent-x": `${agent.baseX}%`,
"--agent-y": `${agent.baseY}%`,
"--agent-color": agent.color,
"--agent-glow": agent.glow,
"--agent-activity": agent.activity,
"--agent-bubble-opacity": 0.38 + agent.activity * 0.28,
} as React.CSSProperties
}
>
<span className="agentGlyph" aria-hidden="true">{agent.glyph}</span>
<span className="agentCaption">
<strong>{agent.name}</strong>
<span>{agent.status}</span>
</span>
</button>
))
) : (
<div className="simulationOnlyControls">
{agents.map((agent) => (
<button
type="button"
key={agent.id}
onClick={() => setSelectedAgentId(agent.id)}
aria-label={`${agent.name} ${agent.status}`}
/>
))}
</div>
))}
<div className="constellationInspector">
<div>
<span>{selectedAgent.title}</span>
<strong>{selectedAgent.name}</strong>
<p>{selectedAgent.thought}</p>
)}
{variant === "band" && (
<div className="constellationInspector">
<div>
<span>{selectedAgent.title}</span>
<strong>{selectedAgent.name}</strong>
<p>{selectedAgent.thought}</p>
</div>
<dl className="facts compact">
<div><dt>Status</dt><dd><Pill tone={selectedAgent.tone}>{selectedAgent.status}</Pill></dd></div>
<div><dt>Detail</dt><dd>{selectedAgent.detail}</dd></div>
<div><dt>Jobs</dt><dd>{selectedAgent.jobs}</dd></div>
<div><dt>Review</dt><dd>{selectedAgent.review}</dd></div>
</dl>
</div>
<dl className="facts compact">
<div><dt>Status</dt><dd><Pill tone={selectedAgent.tone}>{selectedAgent.status}</Pill></dd></div>
<div><dt>Detail</dt><dd>{selectedAgent.detail}</dd></div>
<div><dt>Jobs</dt><dd>{selectedAgent.jobs}</dd></div>
<div><dt>Review</dt><dd>{selectedAgent.review}</dd></div>
</dl>
</div>
)}
</div>
</section>
);
}
function createConstellationProgram(gl: WebGL2RenderingContext, vertexSource: string, fragmentSource: string) {
const vertexShader = compileConstellationShader(gl, gl.VERTEX_SHADER, vertexSource);
const fragmentShader = compileConstellationShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
if (!vertexShader || !fragmentShader) return null;
const program = gl.createProgram();
if (!program) return null;
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
gl.deleteShader(vertexShader);
gl.deleteShader(fragmentShader);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
gl.deleteProgram(program);
return null;
}
return program;
function clamp(value: number, min: number, max: number) {
return Math.min(max, Math.max(min, value));
}
function compileConstellationShader(gl: WebGL2RenderingContext, type: number, source: string) {
const shader = gl.createShader(type);
if (!shader) return null;
gl.shaderSource(shader, source);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
gl.deleteShader(shader);
return null;
}
return shader;
}
function hexToRgb(hex: string): [number, number, number] {
function hexAlpha(hex: string, alpha: number) {
const normalized = hex.replace("#", "");
const value = Number.parseInt(normalized.length === 3
? normalized.split("").map((char) => `${char}${char}`).join("")
: normalized, 16);
return [
((value >> 16) & 255) / 255,
((value >> 8) & 255) / 255,
(value & 255) / 255,
];
return `rgba(${(value >> 16) & 255}, ${(value >> 8) & 255}, ${value & 255}, ${clamp(alpha, 0, 1)})`;
}
function SectionHeader({ title, icon }: { title: string; icon: React.ReactNode }) {

View file

@ -449,10 +449,7 @@ body:has(.immersiveShell) {
}
.immersiveConstellation .agentStageVignette {
background:
linear-gradient(90deg, rgba(5, 10, 8, 0.62), transparent 32%, transparent 64%, rgba(5, 10, 8, 0.58)),
linear-gradient(180deg, rgba(6, 11, 9, 0.64), transparent 22%, rgba(3, 7, 6, 0.72)),
radial-gradient(circle at 50% 48%, transparent 26%, rgba(3, 7, 6, 0.38) 100%);
display: none;
}
.immersiveConstellation .constellationInspector {
@ -834,6 +831,17 @@ body:has(.immersiveShell) {
.agentSmokeCanvas {
z-index: 0;
display: block;
cursor: crosshair;
}
.simulationOnlyControls {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
clip-path: inset(50%);
white-space: nowrap;
}
.agentStageVignette {