mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
feat(console): add icon based perspective swarm motion and live topology depth
This commit is contained in:
1 parent
38da0805a8
commit
bfcbfc2acf
4 files changed
+61
-17
No files matched your search
@@ -111,7 +111,7 @@ export function orbitalGlobe(columns: number, rows: number, timeMs: number): Gri
|
||||
/** Fixed-height header: red scan line, travelling ASCII pulse and an orbit marker. */
|
||||
export function orbitalHeader(label: string, columns: number, timeMs: number): Grid {
|
||||
const swarm = /swarm/i.test(label)
|
||||
const grid = blank(columns, swarm ? 8 : 4)
|
||||
const grid = blank(columns, swarm ? 12 : 4)
|
||||
const tick = Math.floor((Number.isFinite(timeMs) ? timeMs : 0) / 160)
|
||||
const title = ` RUFLO / ${label.toUpperCase()} `
|
||||
grid.text(0, 0, title.slice(0, grid.columns), RED)
|
||||
@@ -128,26 +128,42 @@ export function orbitalHeader(label: string, columns: number, timeMs: number): G
|
||||
if (swarm) {
|
||||
// A decorative routing motif, separate from the page's measured swarm topology.
|
||||
for (let y = 1; y < grid.rows; y++) grid.text(0, y, ' '.repeat(grid.columns), DIM)
|
||||
const center = { x: Math.floor(grid.columns / 2), y: 3 }
|
||||
const spread = Math.max(4, Math.floor(grid.columns * 0.34))
|
||||
const nodes = [-1, 1].flatMap(side => [1, 3, 5].map(y => ({ x: center.x + side * spread, y })))
|
||||
const center = { x: Math.floor(grid.columns / 2), y: 5 }
|
||||
const ms = Number.isFinite(timeMs) ? timeMs : 0
|
||||
nodes.forEach((node, index) => {
|
||||
const phase = ms / 12000 * TAU
|
||||
const icons = ['◇', '□', '△', '◎', '◇', '□']
|
||||
const nodes = icons.map((icon, index) => {
|
||||
const angle = phase + index * TAU / icons.length
|
||||
const z = Math.sin(angle)
|
||||
const perspective = 2.8 / (2.8 - z * 0.5)
|
||||
return { icon, index, z, x: Math.round(center.x + Math.cos(angle) * grid.columns * 0.32 * perspective), y: Math.round(center.y + (Math.sin(angle) * 2.3 + Math.cos(angle) * 0.7) * perspective) }
|
||||
}).sort((a, b) => a.z - b.z)
|
||||
const drawHub = () => {
|
||||
grid.text(center.x - 2, center.y + 1, ' ░░░ ', 0x4b2924)
|
||||
grid.text(center.x - 2, center.y, '[ ◈ ]', INK)
|
||||
}
|
||||
let hubDrawn = false
|
||||
nodes.forEach(node => {
|
||||
if (!hubDrawn && node.z >= 0) { drawHub(); hubDrawn = true }
|
||||
const dx = node.x - center.x
|
||||
const dy = node.y - center.y
|
||||
const steps = Math.max(Math.abs(dx), Math.abs(dy))
|
||||
const pulse = ((ms / 1400 + index / nodes.length) % 1 + 1) % 1
|
||||
for (let step = 1; step < steps; step++) {
|
||||
const pulse = ((ms / 1700 + node.index / icons.length) % 1 + 1) % 1
|
||||
for (let step = 3; step < steps; step++) {
|
||||
const f = step / steps
|
||||
const x = Math.round(center.x + dx * f)
|
||||
const y = Math.round(center.y + dy * f)
|
||||
const distance = pulse - f
|
||||
grid.set(x, y, distance >= 0 && distance < 0.12 ? (dx < 0 ? '<' : '>') : '.', distance >= 0 && distance < 0.12 ? GREEN : 0x35413c)
|
||||
const lit = pulse - f >= 0 && pulse - f < 0.14
|
||||
grid.set(x, y, lit ? '•' : '·', lit ? GREEN : node.z < 0 ? 0x29342f : 0x58675e)
|
||||
}
|
||||
grid.text(node.x - 1, node.y, '[o]', pulse > 0.8 ? INK : RED)
|
||||
if (node.z > 0) {
|
||||
grid.text(node.x, node.y + 1, '░░', 0x4b2924)
|
||||
grid.text(node.x - 1, node.y, `[${node.icon}]`, pulse > 0.8 ? INK : RED)
|
||||
} else grid.set(node.x, node.y, node.icon, DIM)
|
||||
})
|
||||
grid.text(center.x - 2, center.y, '[ + ]', INK)
|
||||
grid.text(1, 7, ' Decorative routing / live topology below', DIM)
|
||||
if (!hubDrawn) drawHub()
|
||||
grid.text(1, 10, ' ◈ HUB ◇ WORKER □ TOOL ◎ MEMORY', DIM)
|
||||
grid.text(1, 11, ' Decorative orbit / live topology below', DIM)
|
||||
} else if (grid.columns >= 30) grid.text(0, 3, ' ruvnet / agent swarm console', DIM)
|
||||
return grid
|
||||
}
|
||||
|
||||
@@ -95,10 +95,22 @@ export function edges(model: TopoModel): [number, number][] {
|
||||
* A dot runs from the leader to a node once each time the console sees an event about that agent (data); the leader's
|
||||
* slow heartbeat is decoration.
|
||||
*/
|
||||
export function topologyPicture(model: TopoModel, columns: number, rows: number, t: number): Grid {
|
||||
export function topologyPicture(model: TopoModel, columns: number, rows: number, t: number, depth = false, motionTime = t): Grid {
|
||||
const grid = new Grid(columns, rows)
|
||||
const canvas = new Braille(columns, rows)
|
||||
const points = layout(model, canvas.width, canvas.height)
|
||||
// Gentle perspective rocking preserves the model's real edges and labels.
|
||||
if (depth) {
|
||||
const yaw = Math.sin(motionTime / 2400) * 0.42
|
||||
for (const point of points) {
|
||||
const nx = (point.x - canvas.width / 2) / (canvas.width / 2)
|
||||
const ny = (point.y - canvas.height / 2) / (canvas.height / 2)
|
||||
const z = nx * Math.sin(yaw) + ny * 0.18
|
||||
const scale = 2.5 / (2.5 - z)
|
||||
point.x = canvas.width / 2 + nx * Math.cos(yaw) * scale * canvas.width * 0.4
|
||||
point.y = canvas.height / 2 + ny * scale * canvas.height * 0.4
|
||||
}
|
||||
}
|
||||
const links = edges(model)
|
||||
const leader = points[0]
|
||||
|
||||
@@ -155,7 +167,8 @@ export function topologyPicture(model: TopoModel, columns: number, rows: number,
|
||||
const breath = !node.isLeader && isBusy(node.status) ? 0.45 * Math.sin(t / 330 + i) ** 2 : 0
|
||||
const color = flash ? 0xffffff : node.isLeader ? mix(COLOR.accent, 0xffffff, heartbeat) : mix(nodeColor(node), 0xffffff, breath)
|
||||
|
||||
grid.set(cx, cy, node.isLeader ? '★' : isBusy(node.status) ? '◉' : '●', color)
|
||||
if (depth) grid.set(cx + 1, cy + 1, '░', 0x49332c)
|
||||
grid.set(cx, cy, depth ? (node.isLeader ? '◈' : isDown(node.status) ? '×' : isBusy(node.status) ? '◉' : '◇') : node.isLeader ? '★' : isBusy(node.status) ? '◉' : '●', color)
|
||||
|
||||
if (room >= 5 || node.isLeader) {
|
||||
const label = node.label.slice(0, Math.max(3, room - 1))
|
||||
|
||||
@@ -226,7 +226,7 @@ export function picturesOf(state: State, columns: number, nowMs: number, t: numb
|
||||
case 'swarm': {
|
||||
const model = topoModelOf(snapshot, recentByAgent(state.events, nowMs, PULSE_MS + 600), nowMs)
|
||||
|
||||
if (model !== null) pictures.set('topology', topologyPicture(model, width, topologyRows(width, model.nodes.length), t))
|
||||
if (model !== null) pictures.set('topology', topologyPicture(model, width, topologyRows(width, model.nodes.length), t, state.options.look === 'orbital', state.options.fps > 0 ? t : 0))
|
||||
break
|
||||
}
|
||||
case 'hive':
|
||||
|
||||
@@ -116,9 +116,24 @@ it('gives swarm control its own bounded routing animation', () => {
|
||||
for (const width of [20, 44, 72]) {
|
||||
const first = orbitalHeader('swarm control', width, 0)
|
||||
const later = orbitalHeader('swarm control', width, 500)
|
||||
expect([first.columns, first.rows]).toEqual([width, 8])
|
||||
expect([first.columns, first.rows]).toEqual([width, 12])
|
||||
expect(first.cells).not.toEqual(later.cells)
|
||||
expect(gridText(first)).toContain('[ + ]')
|
||||
expect(gridText(first)).toContain('◈')
|
||||
expect(gridText(first)).not.toContain('agents online')
|
||||
}
|
||||
})
|
||||
|
||||
import { topologyPicture } from '../hooks/gfx/pictures'
|
||||
it('preserves real topology labels and statuses in the depth view', () => {
|
||||
const model = { topology: 'hierarchical', nodes: [
|
||||
{ id: 'hub', label: 'queen', status: 'leader', isLeader: true },
|
||||
{ id: 'a', label: 'worker', status: 'busy', isLeader: false },
|
||||
{ id: 'b', label: 'down', status: 'offline', isLeader: false },
|
||||
] }
|
||||
const before = JSON.stringify(model)
|
||||
const first = topologyPicture(model, 72, 16, 0, true)
|
||||
const next = topologyPicture(model, 72, 16, 1200, true)
|
||||
for (const label of ['queen', 'worker', 'down', '◈', '◉', '×']) expect(gridText(next)).toContain(label)
|
||||
expect(first.cells).not.toEqual(next.cells)
|
||||
expect(JSON.stringify(model)).toBe(before)
|
||||
})
|
||||
Reference in new issue
Block a user