Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

feat(ruflo-swarm): show ruOS-hosted agents and hosts (ruflo-ruos contract); keep pane state per folder

ruv8ceed8810b9b
diff --git a/plugins/ruflo-swarm/hooks/commands.ts b/plugins/ruflo-swarm/hooks/commands.ts
index 2c39bf38b6..348fd9e6f7 100644
--- a/plugins/ruflo-swarm/hooks/commands.ts
+++ b/plugins/ruflo-swarm/hooks/commands.ts
@@ -42,6 +42,7 @@ export function statusText(state: State, nowMs: number, asJson: boolean): string
tasks: model.board,
claims: snapshot.claims,
hive: snapshot.hive,
+ ruos: snapshot.ruos,
route: state.route,
usage: state.usage,
missing: snapshot.missing,
@@ -61,6 +62,7 @@ export function statusText(state: State, nowMs: number, asJson: boolean): string
`agents: ${model.counts.map(entry => `${entry.state} ${entry.count}`).join(', ') || 'none'}`,
...model.members.slice(0, 20).map(member => ` ${member.isLeader ? '★' : '·'} ${member.label} (${member.source}) ${member.word}`),
`tasks: ${b.pending} pending, ${b.claimed} claimed, ${b.done} done${b.failed > 0 ? `, ${b.failed} failed` : ''}`,
+ ...(model.remote.length > 0 ? ['ruOS hosts:', ...model.remote.map(line => ` ${line}`)] : []),
model.route,
model.usage,
]
diff --git a/plugins/ruflo-swarm/hooks/model/members.ts b/plugins/ruflo-swarm/hooks/model/members.ts
index 3c790e8ee4..f80161711d 100644
--- a/plugins/ruflo-swarm/hooks/model/members.ts
+++ b/plugins/ruflo-swarm/hooks/model/members.ts
@@ -1,3 +1,4 @@
+import { runWord, type RunEventType } from '../reader/ruos'
import type { Snapshot } from '../reader/snapshot'
/** How a tile is coloured: the five states the pane names. */
@@ -174,6 +175,7 @@ export function noteListed(activity: Activity, listed: readonly { id: string; ty
}
const RUFLO_STATES: Record<string, MemberState> = { idle: 'idle', busy: 'working', terminated: 'done' }
+const RUN_STATES: Partial<Record<RunEventType, MemberState>> = { 'run.started': 'working', 'run.output': 'working', 'run.completed': 'done', 'run.failed': 'failed', 'run.stopped': 'done' }
const LOOP_STATES: Record<string, MemberState> = { running: 'working', pending: 'working', completed: 'done', failed: 'failed', killed: 'failed' }
/**
@@ -192,17 +194,23 @@ export function membersOf(snapshot: Snapshot | null, activity: Activity, nowMs:
const coordinator = (snapshot?.agents ?? []).find(agent => /coordinator|queen/.test(agent.type) && agent.status !== 'terminated')
+ const events = snapshot?.ruos.events ?? []
+
for (const agent of snapshot?.agents ?? []) {
const held = claimsOf(agent.id)
const isBlocked = held.some(claim => claim.status === 'blocked')
+ const remote = agent.remote
+ // On a ruOS desktop the newest lifecycle event for its run (or the agent) says where it stands.
+ const run = remote === undefined ? undefined : events.filter(event => event.type !== 'desktop.state' && ((remote.runId !== undefined && event.runId === remote.runId) || event.agentId === agent.id)).sort((a, b) => b.ts - a.ts)[0]
+ const runState = run === undefined ? undefined : RUN_STATES[run.type]
members.push({
id: agent.id,
- label: agent.type,
+ label: remote === undefined ? agent.type : `${agent.type} @${remote.desktopName}`,
role: agent.type,
source: 'ruflo',
- state: isBlocked ? 'blocked' : (RUFLO_STATES[agent.status] ?? 'idle'),
- word: isBlocked ? 'blocked' : agent.status,
+ state: isBlocked ? 'blocked' : (runState ?? RUFLO_STATES[agent.status] ?? 'idle'),
+ word: isBlocked ? 'blocked' : run !== undefined ? runWord(run) : agent.status,
isLeader: queen === undefined && coordinator?.id === agent.id,
claims: held.length,
calls: 0,
diff --git a/plugins/ruflo-swarm/hooks/reader/parse.ts b/plugins/ruflo-swarm/hooks/reader/parse.ts
index e9a7150607..4facd17008 100644
--- a/plugins/ruflo-swarm/hooks/reader/parse.ts
+++ b/plugins/ruflo-swarm/hooks/reader/parse.ts
@@ -3,6 +3,7 @@
* Every one takes text from disk that another process wrote, so each tolerates any shape: what it cannot read
* is left out, never guessed. Nothing here reads, keeps or returns the hive's `hiveToken`.
*/
+import { remoteHostOf, type RemoteHost } from './ruos'
/** Text longer than this is not read: a store that size is not one the CLI wrote, and parsing it would stall a hook. */
export const MAX_TEXT = 4_000_000
@@ -28,6 +29,8 @@ export type AgentRecord = {
taskCount?: number
model?: string
createdAt?: string
+ /** Where the agent runs, when ruflo-ruos placed it on a ruOS desktop (`config.host`, see ./ruos). */
+ remote?: RemoteHost
}
export type TaskRecord = {
@@ -182,6 +185,7 @@ export function parseAgents(text: string | null): AgentRecord[] {
...(numberOf(agent.taskCount) !== undefined && { taskCount: numberOf(agent.taskCount) }),
...(stringOf(agent.model, 40) !== undefined && { model: stringOf(agent.model, 40) }),
...(stringOf(agent.createdAt, 40) !== undefined && { createdAt: stringOf(agent.createdAt, 40) }),
+ ...(remoteHostOf(agent.config) !== null && { remote: remoteHostOf(agent.config) as RemoteHost }),
},
]
})
diff --git a/plugins/ruflo-swarm/hooks/reader/ruos.ts b/plugins/ruflo-swarm/hooks/reader/ruos.ts
new file mode 100644
index 0000000000..a5f4c82cc6
--- /dev/null
+++ b/plugins/ruflo-swarm/hooks/reader/ruos.ts
@@ -0,0 +1,153 @@
+/**
+ * The ruOS remote-host contract agreed with the ruflo-ruos plugin: swarm agents that run on ruOS cloud desktops.
+ * - `.claude-flow/agents/store.json`: `agents[id].config.host = { kind: 'ruos', desktopId, desktopName, transport, runId }`
+ * - `.claude-flow/ruos/hosts.json`: `{ updatedAt, hosts: [{ desktopId, name, state, heartbeatAt, agents: [agentId] }] }`
+ * - `.claude-flow/ruos/events.jsonl`: one lifecycle event per line, ids and sizes only
+ * Every field is text another process wrote: ids must match ruflo's id shape, names are cleaned and bounded, and
+ * free text (`error`, `lastResult`) is never read.
+ */
+import { idOf, jsonObject, MAX_RECORDS, plain } from './parse'
+
+export const RUOS_HOSTS = '.claude-flow/ruos/hosts.json'
+export const RUOS_EVENTS = '.claude-flow/ruos/events.jsonl'
+/** Only the tail of the event log is parsed: the newest events say where each run stands. */
+export const EVENTS_TAIL = 64 * 1024
+/** An event log bigger than this is not read at all (there is no ranged read), and the pane says so. */
+export const EVENTS_MAX = 2_000_000
+const EVENT_LINES = 200
+const MAX_HOSTS = 200
+
+export type RemoteHost = { desktopId: string; desktopName: string; transport: 'fleet-mcp' | 'ssh' | 'unknown'; runId?: string }
+export type RuosHost = { desktopId: string; name: string; state: string; heartbeatAt?: string; agents: string[] }
+export type RunEventType = 'run.started' | 'run.output' | 'run.completed' | 'run.failed' | 'run.stopped' | 'desktop.state'
+export type RunEvent = { ts: number; type: RunEventType; runId?: string; agentId?: string; desktopId?: string; exitCode?: number; bytes?: number }
+
+const TYPES = new Set<string>(['run.started', 'run.output', 'run.completed', 'run.failed', 'run.stopped', 'desktop.state'])
+
+const recordOf = (value: unknown): Record<string, unknown> | null =>
+ value !== null && typeof value === 'object' && !Array.isArray(value) ? (value as Record<string, unknown>) : null
+
+/** An agent record's `config.host`, when it names a ruOS desktop in the agreed shape. */
+export function remoteHostOf(config: unknown): RemoteHost | null {
+ const host = recordOf(recordOf(config)?.host)
+ const desktopId = idOf(host?.desktopId)
+
+ if (host === null || host.kind !== 'ruos' || desktopId === null) {
+ return null
+ }
+
+ const runId = idOf(host.runId)
+
+ return {
+ desktopId,
+ desktopName: plain(host.desktopName, 40) || desktopId,
+ transport: host.transport === 'fleet-mcp' || host.transport === 'ssh' ? host.transport : 'unknown',
+ ...(runId !== null && { runId }),
+ }
+}
+
+export function parseHosts(text: string | null): RuosHost[] | null {
+ const value = jsonObject(text)
+
+ if (value === null || !Array.isArray(value.hosts)) {
+ return null
+ }
+
+ return value.hosts.slice(0, MAX_HOSTS).flatMap(entry => {
+ const host = recordOf(entry)
+ const desktopId = idOf(host?.desktopId)
+
+ if (host === null || desktopId === null) {
+ return []
+ }
+
+ const heartbeat = typeof host.heartbeatAt === 'string' && !Number.isNaN(Date.parse(host.heartbeatAt)) ? host.heartbeatAt.slice(0, 40) : undefined
+
+ return [
+ {
+ desktopId,
+ name: plain(host.name, 40) || desktopId,
+ state: plain(host.state, 20) || 'unknown',
+ ...(heartbeat !== undefined && { heartbeatAt: heartbeat }),
+ agents: (Array.isArray(host.agents) ? host.agents : []).slice(0, MAX_RECORDS).flatMap(agent => (idOf(agent) !== null ? [agent as string] : [])),
+ },
+ ]
+ })
+}
+
+const tsOf = (value: unknown): number | null => {
+ if (typeof value === 'number' && Number.isFinite(value) && value > 0) {
+ return value
+ }
+
+ const parsed = typeof value === 'string' ? Date.parse(value) : Number.NaN
+
+ return Number.isNaN(parsed) ? null : parsed
+}
+
+const countOf = (value: unknown): number | undefined => (typeof value === 'number' && Number.isInteger(value) ? value : undefined)
+
+/** The newest event of each run (or each desktop, for `desktop.state`), from the tail of the log. A torn first line is dropped. */
+export function parseEvents(text: string | null): RunEvent[] {
+ if (text === null) {
+ return []
+ }
+
+ const tail = text.length > EVENTS_TAIL ? text.slice(text.length - EVENTS_TAIL) : text
+ const lines = tail.split('\n')
+
+ if (text.length > EVENTS_TAIL) {
+ lines.shift()
+ }
+
+ const newest = new Map<string, RunEvent>()
+
+ for (const line of lines.slice(-EVENT_LINES)) {
+ const value = line.trim() === '' ? null : jsonObject(line)
+ const ts = tsOf(value?.ts)
+ const type = typeof value?.type === 'string' && TYPES.has(value.type) ? (value.type as RunEventType) : null
+
+ if (value === null || ts === null || type === null) {
+ continue
+ }
+
+ const runId = idOf(value.runId)
+ const agentId = idOf(value.agentId)
+ const desktopId = idOf(value.desktopId)
+ const key = type === 'desktop.state' ? `desktop:${desktopId ?? ''}` : `run:${runId ?? agentId ?? ''}`
+ const event: RunEvent = {
+ ts,
+ type,
+ ...(runId !== null && { runId }),
+ ...(agentId !== null && { agentId }),
+ ...(desktopId !== null && { desktopId }),
+ ...(countOf(value.exitCode) !== undefined && { exitCode: countOf(value.exitCode) }),
+ ...(countOf(value.bytes) !== undefined && { bytes: countOf(value.bytes) }),
+ }
+ const held = newest.get(key)
+
+ // `run.output` is progress, not a state: it never hides how a run ended.
+ if (held === undefined || (held.ts <= ts && !(type === 'run.output' && held.type !== 'run.started' && held.type !== 'run.output'))) {
+ newest.set(key, event)
+ }
+ }
+
+ return [...newest.values()]
+}
+
+/** What a run's newest event says, as the word under a tile. */
+export function runWord(event: RunEvent): string {
+ switch (event.type) {
+ case 'run.started':
+ case 'run.output':
+ return 'running'
+ case 'run.completed':
+ return 'completed'
+ case 'run.failed':
+ return event.exitCode !== undefined ? `failed (exit ${event.exitCode})` : 'failed'
+ case 'run.stopped':
+ return 'stopped'
+ default:
+ return 'desktop'
+ }
+}
diff --git a/plugins/ruflo-swarm/hooks/reader/snapshot.ts b/plugins/ruflo-swarm/hooks/reader/snapshot.ts
index c441746880..afd8282a36 100644
--- a/plugins/ruflo-swarm/hooks/reader/snapshot.ts
+++ b/plugins/ruflo-swarm/hooks/reader/snapshot.ts
@@ -11,6 +11,7 @@ import {
type SwarmInfo,
type TaskRecord,
} from './parse'
+import { EVENTS_MAX, parseEvents, parseHosts, RUOS_EVENTS, RUOS_HOSTS, type RunEvent, type RuosHost } from './ruos'
/** The file calls a reader makes, as `$.fs` answers them; every one may be refused. */
export type ReaderFs = {
@@ -36,6 +37,8 @@ export type Snapshot = {
tasks: TaskRecord[]
claims: ClaimRecord[]
hive: HiveInfo | null
+ /** ruOS desktops that host swarm agents (ruflo-ruos): null hosts when the snapshot file is absent. */
+ ruos: { hosts: RuosHost[] | null; events: RunEvent[]; note?: string }
/** The facts that are not on disk (no file, unreadable, or not in a shape ruflo writes), by key. */
missing: FileKey[]
/** True when any of ruflo's swarm files is there at all: the pane has something of its own to show. */
@@ -84,12 +87,14 @@ export async function readSnapshot(fs: ReaderFs, cache: ReadCache, nowMs: number
? { id: pointer.id, topology: pointer.topology ?? 'unknown', status: pointer.status ?? 'unknown', agentIds: [], ...(pointer.strategy !== undefined && { strategy: pointer.strategy }) }
: null)
+ const ruos = await readRuos(fs, cache)
const parsed = {
swarm,
agents: parseAgents(text('agents')),
tasks: parseTasks(text('tasks')),
claims: parseClaims(text('claims')),
hive: parseHive(text('hive')),
+ ruos,
}
const missing = keys.filter(key => {
@@ -112,3 +117,21 @@ export async function readSnapshot(fs: ReaderFs, cache: ReadCache, nowMs: number
readAtMs: nowMs,
}
}
+
+/** The ruOS host snapshot and the tail of its event log. The log is read whole (there is no ranged read), so past a size it is not read. */
+async function readRuos(fs: ReaderFs, cache: ReadCache): Promise<Snapshot['ruos']> {
+ const hosts = parseHosts(await textOf(fs, cache, RUOS_HOSTS))
+ let size = -1
+
+ try {
+ size = (await fs.stat(RUOS_EVENTS))?.size ?? -1
+ } catch {
+ return { hosts, events: [] }
+ }
+
+ if (size > EVENTS_MAX) {
+ return { hosts, events: [], note: `ruOS event log is ${Math.round(size / 1_000_000)} MB: not read` }
+ }
+
+ return { hosts, events: parseEvents(await textOf(fs, cache, RUOS_EVENTS)) }
+}
diff --git a/plugins/ruflo-swarm/hooks/register.ts b/plugins/ruflo-swarm/hooks/register.ts
index 6132252a2a..fabe2e6ffd 100644
--- a/plugins/ruflo-swarm/hooks/register.ts
+++ b/plugins/ruflo-swarm/hooks/register.ts
@@ -7,7 +7,7 @@ import type { Host, OpenResult } from './host'
import { isAnimating, LEAD, newActivity, noteCall, noteDone, noteListed, noteResult, noteSpawn } from './model/members'
import { parseRoute, plain } from './reader/parse'
import { readSnapshot, type ReadCache } from './reader/snapshot'
-import { CLI_PREFIXES, newState, PANE_ID, persistedOf, restore, STORE_KEY, type State } from './state'
+import { CLI_PREFIXES, newState, PANE_ID, persistedOf, restore, storeKeyOf, type State } from './state'
import { paneModelOf } from './views/model'
import { paneView } from './views/pane'
@@ -65,7 +65,7 @@ export function register(on: On, raw: PluginOptions) {
let host: Host | null = null
const persist = () => {
- void host?.storeSet(STORE_KEY, persistedOf(state)).catch(() => undefined)
+ void host?.storeSet(storeKeyOf(state.cwd), persistedOf(state)).catch(() => undefined)
}
async function refresh(): Promise<void> {
@@ -225,7 +225,7 @@ export function register(on: On, raw: PluginOptions) {
await Promise.all([
...COMMANDS.map(spec => bound.registerCommand(spec).catch(() => undefined)),
bound
- .storeGet(STORE_KEY)
+ .storeGet(storeKeyOf(e.cwd))
.then(value => restore(state, value))
.catch(() => undefined),
])
diff --git a/plugins/ruflo-swarm/hooks/state.ts b/plugins/ruflo-swarm/hooks/state.ts
index fa9719148a..ea2543de01 100644
--- a/plugins/ruflo-swarm/hooks/state.ts
+++ b/plugins/ruflo-swarm/hooks/state.ts
@@ -8,8 +8,11 @@ import type { Snapshot } from './reader/snapshot'
export const PLUGIN_NAME = 'ruflo-swarm'
export const PANE_ID = 'ruflo-swarm'
-/** The `$.store` key the few facts that must outlive a hot reload sit under. */
-export const STORE_KEY = 'ruflo-swarm/ui'
+/**
+ * The `$.store` key the few facts that must outlive a hot reload sit under. `$.store` is the plugin's, not the folder's,
+ * so the key carries the working directory: a router pick or a selection never follows the person into another project.
+ */
+export const storeKeyOf = (cwd: string): string => `ruflo-swarm/ui:${cwd}`
/** How the pane reaches the ruflo CLI. Each is a fixed argv prefix; only `npx` may touch the network. */
export const CLI_PREFIXES = {
diff --git a/plugins/ruflo-swarm/hooks/views/model.ts b/plugins/ruflo-swarm/hooks/views/model.ts
index 530c379c1f..b0c3de4757 100644
--- a/plugins/ruflo-swarm/hooks/views/model.ts
+++ b/plugins/ruflo-swarm/hooks/views/model.ts
@@ -26,6 +26,8 @@ export type PaneModel = {
decisions: Decision[]
usage: string
route: string
+ /** ruOS desktops hosting swarm agents, one line each; empty when no agent runs remotely and no host file is there. */
+ remote: string[]
missing: string[]
confirm: PendingConfirm | null
outcome: ActionOutcome | null
@@ -47,6 +49,38 @@ const CLAIMED = new Set(['in_progress', 'running', 'assigned'])
const DONE = new Set(['completed', 'done'])
const FAILED = new Set(['failed', 'cancelled'])
+const ageOf = (ms: number): string => {
+ const s = Math.max(0, Math.round(ms / 1000))
+
+ return s < 60 ? `${s}s` : s < 3600 ? `${Math.floor(s / 60)}m` : `${Math.floor(s / 3600)}h`
+}
+
+/** The ruOS hosts section: each desktop with its state, heartbeat age and agents; "not on disk" when agents name a host and no snapshot exists. */
+export function remoteLines(snapshot: State['snapshot'], nowMs: number): string[] {
+ if (snapshot === null) {
+ return []
+ }
+
+ const hosts = snapshot.ruos.hosts
+ const remoteAgents = snapshot.agents.filter(agent => agent.remote !== undefined).length
+ const note = snapshot.ruos.note !== undefined ? [snapshot.ruos.note] : []
+
+ if (hosts === null) {
+ return remoteAgents > 0 ? [`ruOS hosts: not on disk (${remoteAgents} agent${remoteAgents === 1 ? '' : 's'} name one)`, ...note] : note
+ }
+
+ return [
+ ...hosts.slice(0, 20).map(host => {
+ const beat = host.heartbeatAt !== undefined ? ` · heartbeat ${ageOf(nowMs - Date.parse(host.heartbeatAt))} ago` : ' · no heartbeat'
+
+ return `${host.name} · ${host.state}${beat} · ${host.agents.length} agent${host.agents.length === 1 ? '' : 's'}`
+ }),
+ ...(hosts.length > 20 ? [`+${hosts.length - 20} more hosts`] : []),
+ ...(hosts.length === 0 ? ['no ruOS hosts'] : []),
+ ...note,
+ ]
+}
+
const short = (id: string) => (id.length > 14 ? `…${id.slice(-8)}` : id)
/** A cost or a token count as the engine gave it; a figure it left out is `n/a`, never zero. */
@@ -63,22 +97,27 @@ export function usageLine(usage: State['usage']): string {
return `cost ${cost} · context ${tokens}${window}${percent}`
}
-/** The router's last pick seen this session, with its score; under the threshold it says so instead of naming a winner. */
-export function routeLine(route: State['route'], threshold: number): string {
+/**
+ * The router's last pick the pane has seen (kept in `$.store`, so it may come from an earlier session: its age says),
+ * with its score; under the threshold it says so instead of naming a winner.
+ */
+export function routeLine(route: State['route'], threshold: number, nowMs = Date.now()): string {
if (route === null) {
- return 'router: no pick seen this session'
+ return 'router: no pick seen yet'
}
const score = `${Math.round(route.confidence * 100)}%`
const alt = route.alternatives[0] !== undefined ? ` · alt ${route.alternatives[0].agent} ${Math.round(route.alternatives[0].confidence * 100)}%` : ''
+ const age = route.atMs > 0 ? ` · ${ageOf(nowMs - route.atMs)} ago` : ''
+
if (!route.matched) {
- return `router: no match (best ${route.agent} ${score})`
+ return `router: no match (best ${route.agent} ${score})${age}`
}
return route.confidence < threshold
- ? `router: below threshold ${Math.round(threshold * 100)}% (best ${route.agent} ${score})${alt}`
- : `router: ${route.agent} ${score}${route.pattern !== undefined ? ` (${route.pattern})` : ''}${alt}`
+ ? `router: below threshold ${Math.round(threshold * 100)}% (best ${route.agent} ${score})${alt}${age}`
+ : `router: ${route.agent} ${score}${route.pattern !== undefined ? ` (${route.pattern})` : ''}${alt}${age}`
}
function nextOf(state: State, members: readonly Member[], board: PaneModel['board']): PaneModel['next'] {
@@ -161,7 +200,8 @@ export function paneModelOf(state: State, columns: number, rows: number, nowMs:
proposals: snapshot?.hive?.pending.filter(proposal => proposal.status === 'pending') ?? [],
decisions: (snapshot?.hive?.history ?? []).slice(-2).reverse(),
usage: usageLine(state.usage),
- route: routeLine(state.route, state.options.routeThreshold),
+ route: routeLine(state.route, state.options.routeThreshold, nowMs),
+ remote: remoteLines(snapshot, nowMs),
missing: (snapshot?.missing ?? []).map(key => MISSING_WORDS[key]),
confirm: state.confirm,
outcome: state.outcome,
diff --git a/plugins/ruflo-swarm/hooks/views/pane.tsx b/plugins/ruflo-swarm/hooks/views/pane.tsx
index 5de228ccc3..87f8afc33c 100644
--- a/plugins/ruflo-swarm/hooks/views/pane.tsx
+++ b/plugins/ruflo-swarm/hooks/views/pane.tsx
@@ -380,6 +380,7 @@ export function paneView(kit: Kit, model: PaneModel, actions: PaneActions): Rend
const shownDetail = take(detail(kit, model, actions, Math.min(12, Math.max(2, budget - 8))))
const shownBoard = take(board(kit, model, Math.min(8, Math.max(1, budget - 10)), actions))
const shownConsensus = take(consensus(kit, model, actions))
+ const shownRemote = model.remote.length > 0 ? take({ rows: 1 + model.remote.length, node: <Box flexDirection="column">{rule(kit, 'ruOS hosts', model.columns)}{model.remote.map(line => <Text>{clip(line, model.columns)}</Text>)}</Box> }) : null
const shownTopology = take({ rows: 1 + model.topology.length, node: <Box flexDirection="column">{rule(kit, 'Topology', model.columns)}{model.topology.map(line => <Text>{line}</Text>)}</Box> })
const shownSignals = take({ rows: 2, node: <Box flexDirection="column"><Text>{clip(model.route, model.columns)}</Text><Text dimColor>{clip(model.usage, model.columns)}</Text></Box> })
const shownNext = take(nextRow(kit, model, actions))
@@ -392,6 +393,7 @@ export function paneView(kit: Kit, model: PaneModel, actions: PaneActions): Rend
{shownDetail}
{shownBoard}
{shownConsensus}
+ {shownRemote}
{shownTopology}
{shownSignals}
{shownNext}
diff --git a/plugins/ruflo-swarm/tests/pane.test.ts b/plugins/ruflo-swarm/tests/pane.test.ts
index 1722e38079..372cc258fd 100644
--- a/plugins/ruflo-swarm/tests/pane.test.ts
+++ b/plugins/ruflo-swarm/tests/pane.test.ts
@@ -30,7 +30,7 @@ describe('pane', () => {
expect(text).toContain('Write login tests → unassigned')
expect(text).toContain('design (raft) for 0 · against 0')
expect(text).toContain('├─ coder')
- expect(text).toContain('router: no pick seen this session')
+ expect(text).toContain('router: no pick seen yet')
expect(text).toContain('cost $0.421 · context 68k/200k (34%)')
expect(text).not.toContain(HIVE_TOKEN)
expect(buttonKeysOf(tree)).toEqual(expect.arrayContaining(['hide', 'prev', 'next', 'logs', 'task-prev', 'task-next', 'offer', 'reroute', 'vote-yes', 'vote-no']))
diff --git a/plugins/ruflo-swarm/tests/parse.spec.ts b/plugins/ruflo-swarm/tests/parse.spec.ts
index b1164018f7..69de133c7a 100644
--- a/plugins/ruflo-swarm/tests/parse.spec.ts
+++ b/plugins/ruflo-swarm/tests/parse.spec.ts
@@ -6,6 +6,7 @@
import { describe, expect, it } from 'vitest'
import { idOf, parseAgents, parseClaims, parseHive, parseRoute, parseSwarmStore, parseTasks, plain, routeFromStore } from '../hooks/reader/parse'
+import { parseEvents, parseHosts, remoteHostOf, runWord } from '../hooks/reader/ruos'
import { readSnapshot, type ReadCache } from '../hooks/reader/snapshot'
import { HIVE_TOKEN, RUFLO_RUN } from './fixtures/ruflo-run'
@@ -48,7 +49,7 @@ describe('parse (vitest)', () => {
await readSnapshot(fs, cache, 0)
await readSnapshot(fs, cache, 1)
- expect(reads).toBe(6)
+ expect(reads, "six swarm files and the two ruOS files, once each").toBe(8)
})
it('ids are only what ruflo mints; text is printable and bounded', () => {
@@ -68,4 +69,14 @@ describe('parse (vitest)', () => {
expect(routeFromStore({ task: 't', agent: 'x', confidence: 'high', atMs: 1 })).toBeNull()
expect(routeFromStore(pick)).toMatchObject({ agent: 'architect', confidence: 0.41 })
})
+
+ it('reads the ruflo-ruos remote-host contract and keeps only ids, names and states', () => {
+ expect(remoteHostOf({ host: { kind: 'ruos', desktopId: 'm-1', desktopName: 'desk', transport: 'ssh', runId: 'run-1' } })).toEqual({ desktopId: 'm-1', desktopName: 'desk', transport: 'ssh', runId: 'run-1' })
+ expect(parseHosts('{"hosts":[{"desktopId":"m-1","name":"desk","state":"running","agents":["agent-1","bad id"]}]}')).toEqual([{ desktopId: 'm-1', name: 'desk', state: 'running', agents: ['agent-1'] }])
+
+ const [event] = parseEvents('{"ts":3,"type":"run.failed","runId":"run-1","exitCode":2,"error":"secret"}')
+
+ expect(event).toEqual({ ts: 3, type: 'run.failed', runId: 'run-1', exitCode: 2 })
+ expect(event !== undefined && runWord(event)).toBe('failed (exit 2)')
+ })
})
diff --git a/plugins/ruflo-swarm/tests/register.test.ts b/plugins/ruflo-swarm/tests/register.test.ts
index c00a5d1fa4..86f703e209 100644
--- a/plugins/ruflo-swarm/tests/register.test.ts
+++ b/plugins/ruflo-swarm/tests/register.test.ts
@@ -95,7 +95,7 @@ describe('register', () => {
expect(status).toContain('swarm …4-u3ktj4 · hierarchical · running')
expect(status).toContain('· coder (ruflo) busy')
expect(status).toContain('tasks: 1 pending, 1 claimed, 0 done')
- expect(status).toContain('router: no pick seen this session')
+ expect(status).toContain('router: no pick seen yet')
expect(status).toContain('cost $0.421 · context 68k/200k (34%)')
expect(topology).toContain('hierarchical (strategy specialized, max 8 agents, hive consensus byzantine)')
expect(topology).toContain('★ queen')
@@ -107,4 +107,14 @@ describe('register', () => {
expect(text).not.toContain(HIVE_TOKEN)
}
})
+
+ test('what the pane keeps across reloads is kept per folder: a router pick from another project never shows here', async ($, on) => {
+ const world = worldOf(on, RUFLO_RUN)
+
+ mock.clock(on)
+ world.stored.set('ruflo-swarm/ui:/elsewhere', { selected: null, selectedTask: null, isClosedByPerson: false, route: { task: 't', agent: 'coder', confidence: 0.9, matched: true, alternatives: [], atMs: 1 } })
+ await $.session.start(SESSION)
+
+ expect(textOf(await $.ui.render(PANE))).toContain('router: no pick seen yet')
+ })
})
diff --git a/plugins/ruflo-swarm/tests/ruos.test.ts b/plugins/ruflo-swarm/tests/ruos.test.ts
new file mode 100644
index 0000000000..1c6ac610b3
--- /dev/null
+++ b/plugins/ruflo-swarm/tests/ruos.test.ts
@@ -0,0 +1,108 @@
+import { describe, expect, mock, test } from 'claude-code/testing'
+
+import { EVENTS_MAX, parseEvents, parseHosts, remoteHostOf } from '../hooks/reader/ruos'
+import { RUFLO_RUN } from './fixtures/ruflo-run'
+import { command, PANE, SESSION } from './fixtures/inputs'
+import { textOf, worldOf } from './fixtures/world'
+
+const CODER = 'agent-1790888815793-6ju96w'
+const TESTER = 'agent-1790888816288-z5xsn6'
+
+/** The real run, with the coder and tester placed on ruOS desktops as the ruflo-ruos contract writes them. */
+function remoteRun(extra: Record<string, string> = {}): Record<string, string> {
+ const store = JSON.parse(RUFLO_RUN['.claude-flow/agents/store.json'] ?? '{}') as { agents: Record<string, { config: Record<string, unknown> }> }
+ const coder = store.agents[CODER]
+ const tester = store.agents[TESTER]
+
+ if (coder !== undefined && tester !== undefined) {
+ coder.config.host = { kind: 'ruos', desktopId: 'm-7f3a', desktopName: 'ruos-desktop-1', transport: 'fleet-mcp', runId: 'run-1' }
+ tester.config.host = { kind: 'ruos', desktopId: 'm-9c21', desktopName: 'ruos-desktop-2', transport: 'ssh', runId: 'run-2' }
+ }
+
+ return {
+ ...RUFLO_RUN,
+ '.claude-flow/agents/store.json': JSON.stringify(store),
+ '.claude-flow/ruos/hosts.json': JSON.stringify({
+ updatedAt: '2026-10-01T22:00:00.000Z',
+ hosts: [
+ { desktopId: 'm-7f3a', name: 'ruos-desktop-1', state: 'running', heartbeatAt: new Date(Date.now() - 12_000).toISOString(), agents: [CODER] },
+ { desktopId: 'm-9c21', name: 'ruos-desktop-2', state: 'running', agents: [TESTER] },
+ ],
+ }),
+ '.claude-flow/ruos/events.jsonl': [
+ { ts: 1, type: 'run.started', runId: 'run-1', agentId: CODER, desktopId: 'm-7f3a' },
+ { ts: 2, type: 'run.output', runId: 'run-1', agentId: CODER, desktopId: 'm-7f3a', bytes: 812 },
+ { ts: 3, type: 'run.started', runId: 'run-2', agentId: TESTER, desktopId: 'm-9c21' },
+ { ts: 4, type: 'run.failed', runId: 'run-2', agentId: TESTER, desktopId: 'm-9c21', exitCode: 2, error: 'SECRET-OUTPUT-LINE' },
+ ].map(event => JSON.stringify(event)).join('\n'),
+ ...extra,
+ }
+}
+
+describe('ruos', () => {
+ test('agents on ruOS desktops carry the desktop name, take their state from the newest run event, and the hosts are listed', async ($, on) => {
+ worldOf(on, remoteRun())
+ mock.clock(on)
+ await $.session.start(SESSION)
+
+ const text = textOf(await $.ui.render(PANE))
+ const status = (await $.command.run(command('ruflo-swarm-status'))).text ?? ''
+
+ expect(text).toContain('coder @ruos-desktop-1')
+ expect(text).toContain('tester @ruos-desktop-2')
+ expect(text).toContain('ruOS hosts')
+ expect(text).toMatch(/ruos-desktop-1 · running · heartbeat 1[0-9]s ago · 1 agent/)
+ expect(text).toContain('ruos-desktop-2 · running · no heartbeat · 1 agent')
+ expect(status).toContain('coder @ruos-desktop-1 (ruflo) running')
+ expect(status).toContain('tester @ruos-desktop-2 (ruflo) failed (exit 2)')
+ expect(`${text}${status}`, 'free text from the event log is never read').not.toContain('SECRET-OUTPUT-LINE')
+ })
+
+ test('agents that name a desktop with no host snapshot on disk say so; no remote agents and no file draws no section', async ($, on) => {
+ const files = remoteRun()
+
+ delete files['.claude-flow/ruos/hosts.json']
+ worldOf(on, files)
+ mock.clock(on)
+ await $.session.start(SESSION)
+
+ expect(textOf(await $.ui.render(PANE))).toContain('ruOS hosts: not on disk (2 agents name one)')
+ })
+
+ test('without ruflo-ruos the pane has no ruOS section at all', async ($, on) => {
+ worldOf(on, RUFLO_RUN)
+ mock.clock(on)
+ await $.session.start(SESSION)
+
+ expect(textOf(await $.ui.render(PANE))).not.toContain('ruOS')
+ })
+
+ test('an event log past the size cap is not read, and the pane says why', async ($, on) => {
+ worldOf(on, remoteRun({ '.claude-flow/ruos/events.jsonl': ' '.repeat(EVENTS_MAX + 1) }))
+ mock.clock(on)
+ await $.session.start(SESSION)
+
+ expect(textOf(await $.ui.render(PANE))).toContain('ruOS event log is 2 MB: not read')
+ })
+
+ test('hostile host and event text: bad ids are dropped, names cleaned, unknown types ignored, output never ends a run', () => {
+ expect(remoteHostOf({ host: { kind: 'ruos', desktopId: '$(rm -rf /)', desktopName: 'x' } })).toBeNull()
+ expect(remoteHostOf({ host: { kind: 'other', desktopId: 'm-1' } })).toBeNull()
+ expect(remoteHostOf({ host: { kind: 'ruos', desktopId: 'm-1', desktopName: '\u001b[2Jevil\u0007', transport: 'telnet' } })).toEqual({ desktopId: 'm-1', desktopName: '[2Jevil', transport: 'unknown' })
+ expect(parseHosts('{"hosts":[{"desktopId":"bad id"},{"desktopId":"m-2","name":"ok","state":"x","heartbeatAt":"not a date"}]}')).toEqual([{ desktopId: 'm-2', name: 'ok', state: 'x', agents: [] }])
+ expect(parseHosts('[]')).toBeNull()
+
+ const events = parseEvents(
+ [
+ '{"ts":5,"type":"run.completed","runId":"run-1"}',
+ '{"ts":6,"type":"run.output","runId":"run-1","bytes":10}',
+ '{"ts":7,"type":"run.exploded","runId":"run-1"}',
+ 'not json',
+ '{"ts":"2026-10-01T22:00:00Z","type":"desktop.state","desktopId":"m-1"}',
+ ].join('\n'),
+ )
+
+ expect(events.map(event => event.type)).toEqual(['run.completed', 'desktop.state'])
+ expect(parseEvents(`${'{"ts":1,"type":"run.started","runId":"r"}\n'.repeat(5_000)}`)).toHaveLength(1)
+ })
+})