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

Merge branch 'feat/console-hive-art' into feat/console-starts

ruv6a86afb71493
diff --cc plugins/ruflo-console/hooks/views/hive.ts
index 3249e4e492,e7651f1e3f..860b27bdcc
--- a/plugins/ruflo-console/hooks/views/hive.ts
+++ b/plugins/ruflo-console/hooks/views/hive.ts
@@@ -6,18 -8,31 +8,26 @@@
*/
import type { RenderElement } from 'claude-code'
- import { faultTolerance, membersOf, nextVoter, nodesOf, pickedProposal, proposalStrategyOf, proposeBlock, requiredVotes, tallyOf, type Liveness, type Member, type Tally } from '../data/hive'
- import { shortId, type HiveInfo } from '../data/parse'
- import { HIVE_COLOR, type HiveCell, type HivePictureModel } from '../gfx/hive'
+ import { Arrivals, faultTolerance, membersOf, nextVoter, nodesOf, pickedProposal, proposalStrategyOf, proposeBlock, requiredVotes, tallyOf, waveOf, type Liveness, type Member, type Tally } from '../data/hive'
+ import { shortId, type HiveInfo, type Proposal } from '../data/parse'
+ import { hivePicture, type HiveCell, type HivePictureModel, type Role } from '../gfx/hive'
+ import { chambersPicture, MAX_CHAMBERS, type Chamber } from '../gfx/hive-chamber'
+ import { eggBottomPicture, eggTopPicture } from '../gfx/hive-egg'
+ import { stripPicture, type Mark, type StripModel } from '../gfx/hive-strip'
+ import type { Grid } from '../gfx/raster'
import type { State } from '../state'
-import { ago, button, clip, col, kv, picture, row, rule, text, THEME, type Ctx } from './common'
+import { ago, button, clip, col, kv, picture, row, rule, starts, text, THEME, type Ctx } from './common'
const ROLE_GLYPH: Record<string, string> = { worker: '●', specialist: '◆', scout: '▲' }
- const LIVE_COLOR: Record<Liveness, number> = { busy: HIVE_COLOR.yellow, idle: HIVE_COLOR.cyan, error: HIVE_COLOR.pink, down: HIVE_COLOR.grey, unknown: HIVE_COLOR.wall }
const LIVE_THEME = (liveness: Liveness): { color?: string; dimColor?: boolean } =>
liveness === 'busy' ? { color: THEME.warn } : liveness === 'idle' ? { color: THEME.info } : liveness === 'error' ? { color: THEME.bad } : { dimColor: true }
const glyphOf = (member: Member): string => (member.isKnown ? (ROLE_GLYPH[member.role] ?? '●') : '○')
+ const roleOf = (member: Member): Role => (member.isKnown && (member.role === 'worker' || member.role === 'specialist' || member.role === 'scout') ? member.role : 'unknown')
+
+ /** The starts an empty hive offers: the palette ids `starts.ts` registers, each asking first with its exact argv. */
-export const HIVE_STARTS = [
- { id: 'hive', label: '▸ start a hive-mind (raft)' },
- { id: 'hive-workers', label: '▸ spawn 3 hive workers' },
-] as const
-
+ /** When the console first saw each broadcast: the ticker slides a new one in, once. */
+ const arrivals = new Arrivals()
/** The bar a proposal must clear, as the CLI's rule reads in words. */
function ruleOf(strategy: string, preset?: string): string {
@@@ -216,6 -319,19 +315,19 @@@ function actSection(ctx: Ctx, hive: Hiv
return rows
}
+ /**
+ * No hive yet: the empty comb with its egg, the start buttons inside it (between the comb's two halves), and the way
+ * in said plainly. The buttons run the starts' palette ids, so each asks first with its exact argv.
+ */
+ function emptyComb(ctx: Ctx): RenderElement[] {
+ return [
+ picture(ctx, 'hive-egg', 'an empty comb: no queen yet'),
+ text(ctx, ' the comb is empty · the egg is where the queen will sit · start a hive, then spawn workers to fill the comb', { color: THEME.warn }),
- row(ctx, [text(ctx, ' '), ...HIVE_STARTS.map(start => button(ctx, `start-${start.id}`, start.label, () => void ctx.act.run(start.id)))]),
++ starts(ctx, 'Start a hive with a queen, then spawn workers to fill the comb.', ['hive', 'hive-workers']),
+ picture(ctx, 'hive-egg-base', ''),
+ ]
+ }
+
export function hiveView(ctx: Ctx): RenderElement {
const snap = ctx.state.snapshot
const hive = snap?.hive ?? null
diff --cc plugins/ruflo-console/tests/labs.test.ts
index ff86a841ac,0000000000..64981f6587
mode 100644,000000..100644
--- a/plugins/ruflo-console/tests/labs.test.ts
+++ b/plugins/ruflo-console/tests/labs.test.ts
@@@ -1,213 -1,0 +1,213 @@@
+import { describe, expect, mock, test } from 'claude-code/testing'
+
+import { MEM_OUT } from './fixtures/memory'
+import { RUFLO_FILES } from './fixtures/ruflo-run'
+import { drawn, memoryWorld } from './fixtures/views'
+import { cliAnswer, command, elementsOf, keyOf, paneAt, PLUGIN, SESSION, textOf, worldOf } from './fixtures/world'
+
+describe('labs and starts', () => {
+ test('cost: a preset asks first, names the exact change, and sends one fixed argv with JSON stdin on yes', { options: { boot: false } }, async ($, on) => {
+ const world = worldOf(on, RUFLO_FILES)
+ mock.clock(on)
+ await $.session.start(SESSION)
+ await drawn($, 'cost')
+
+ const pane = await $.ui.mount({ ...paneAt(110), surface: 'terminal' as const, plugin: PLUGIN })
+ const setters = () => world.runs.filter(argv => argv.includes('--values-stdin'))
+
+ await pane.press({ key: 'cost-budget-5' })
+ const ask = textOf(await pane.drawn())
+
+ expect(ask).toContain('Confirm: set ruflo-mods@ruflo costBudgetUsd to $5?')
+ expect(ask).toContain('runs: claude plugin configure ruflo-mods@ruflo --values-stdin · stdin {"costBudgetUsd":"5"}')
+ expect(ask).toContain('restart/reload may be needed')
+ expect(setters()).toHaveLength(0)
+ await pane.press({ key: 'confirm' })
+ expect(setters()).toEqual([['claude', 'plugin', 'configure', 'ruflo-mods@ruflo', '--values-stdin']])
+ expect(world.inputs).toEqual(['{"costBudgetUsd":"5"}'])
+ await pane.press({ key: 'cost-budget-25' })
+ await pane.press({ key: 'cancel' })
+ expect(setters()).toHaveLength(1)
+ await pane.input({ key: 'cost-budget', text: '12.5', kind: 'change' })
+ await pane.press({ key: 'cost-budget-apply' })
+ expect(textOf(await pane.drawn())).toContain('costBudgetUsd to $12.5?')
+ await pane.input({ key: 'cost-budget', text: '--help', kind: 'submit' })
+ expect(textOf(await pane.drawn())).toContain('budget must be a number from 0.01 to 10000 USD')
+ expect((await $.command.run(command('yes'))).text).toBe('Nothing is waiting for a confirm.')
+ expect(setters()).toHaveLength(1)
+ await pane.unmount()
+ })
+
+ test('cost: unsupported configuration says where to set it and no preset or custom entry runs a setter', { options: { boot: false } }, async ($, on) => {
+ const world = worldOf(on, RUFLO_FILES)
+
+ world.respond = argv => argv.includes('configure') ? { exitCode: 1, stdout: '', stderr: 'unknown command configure' } : cliAnswer(argv)
+ mock.clock(on)
+ await $.session.start(SESSION)
+ const cost = await drawn($, 'cost')
+
+ expect(cost.text).toContain('set costBudgetUsd in /config → ruflo-mods')
+ const pane = await $.ui.mount({ ...paneAt(110), surface: 'terminal' as const, plugin: PLUGIN })
+
+ await pane.press({ key: 'cost-budget-1' })
+ expect(textOf(await pane.drawn())).not.toContain('Confirm:')
+ await pane.input({ key: 'cost-budget', text: '5', kind: 'submit' })
+ expect((await $.command.run(command('yes'))).text).toBe('Nothing is waiting for a confirm.')
+ expect(world.runs.some(argv => argv.includes('--values-stdin'))).toBe(false)
+ await pane.unmount()
+ })
+
+ test('cost: its probes stay on Cost and model inspection is an immediate offline read', { options: { boot: false, cli: 'npx' } }, async ($, on) => {
+ const world = worldOf(on, RUFLO_FILES)
+
+ mock.clock(on)
+ await $.session.start(SESSION)
+ await drawn($, 'overview')
+ expect(world.runs.some(argv => argv.includes('model-stats') || argv.includes('configure'))).toBe(false)
+ const costStart = world.runs.length
+
+ await drawn($, 'cost')
+ const pane = await $.ui.mount({ ...paneAt(110), surface: 'terminal' as const, plugin: PLUGIN })
+ const before = world.runs.filter(argv => argv.includes('model-stats')).length
+
+ await pane.press({ key: 'cost-model-stats' })
+ expect(textOf(await pane.drawn())).not.toContain('Confirm:')
+ const reads = world.runs.filter(argv => argv.includes('model-stats'))
+
+ expect(reads).toHaveLength(before + 1)
+ expect(reads.every(argv => argv[1] === '--offline')).toBe(true)
+ expect(world.runs.slice(costStart).filter(argv => argv[0] === 'npx').every(argv => argv[1] === '--offline')).toBe(true)
+ await pane.unmount()
+ })
+
+ test('memory lab: gauge, namespace bars, recency, browse, search, entry fields and every group; nothing runs unasked', { options: { boot: false } }, async ($, on) => {
+ const world = memoryWorld(on)
+
+ mock.clock(on)
+ await $.session.start(SESSION)
+
+ const { text, tree } = await drawn($, 'memory')
+
+ for (const section of ['AGENTDB', 'NAMESPACES', 'RECENCY', 'BROWSE', 'SEARCH', 'ENTRY', 'RESULT', 'LAB · MEMORY', 'LAB · AGENTDB', 'LAB · EMBEDDINGS', 'LAB · MAINTAIN']) expect(text).toContain(`▓▒░ ${section} ░▒▓`)
+ expect(text).toContain('1/2 of the newest listed carry a vector')
+ expect(text).toContain('2 more rows in .swarm/agentdb-memory.db')
+ expect(text).toMatch(/ ◆ beta \.+/)
+ expect(text).toMatch(/del \n DELETE \.+/)
+ expect(elementsOf(tree, 'Input').map(keyOf)).toEqual(['mem-query', 'mem-namespace', 'mem-key', 'mem-value', 'mem-text'])
+ expect(elementsOf(tree, 'Button').map(keyOf)).toEqual(expect.arrayContaining(['mem-ns-0', 'mem-open-0', 'mem-del-0', 'mem-lab-mem-stats', 'mem-lab-mem-cleanup', 'mem-lab-mem-rabitq-build']))
+ // Opening it runs only its two local probes.
+ expect(world.runs.filter(argv => /memory (retrieve|search|store|delete|export)|mcp exec -t (memory_|agentdb_|embeddings_)/.test(argv.join(' ')))).toEqual([])
+ })
+
+ test('memory lab: view reads at once with one fixed argv; delete and store ask with their argv, then run it on yes', { options: { boot: false } }, async ($, on) => {
+ const world = memoryWorld(on)
+ const ran = (word: string) => world.runs.filter(argv => argv[5] === word).map(argv => argv.slice(4).join(' '))
+
+ mock.clock(on)
+ await $.session.start(SESSION)
+ await $.command.run(command('memory'))
+
+ const pane = await $.ui.mount({ ...paneAt(110), surface: 'terminal' as const, plugin: PLUGIN })
+
+ await pane.drawn()
+ await pane.press({ key: 'mem-open-0' })
+
+ const opened = textOf(await pane.drawn())
+
+ expect(opened).not.toContain('Confirm:')
+ expect(opened).toContain('auth/beta · 25 chars · read 1× · has a vector')
+ expect(opened).toContain('jwt refresh tokens rotate')
+ expect(ran('retrieve')).toEqual(['memory retrieve --key beta --namespace auth --format json'])
+
+ await pane.press({ key: 'mem-del-0' })
+
+ const asked = textOf(await pane.drawn())
+
+ expect(asked).toContain('runs: ruflo memory delete --key beta --namespace auth --force')
+ expect(asked).toContain('DELETES FOR GOOD')
+ expect(ran('delete')).toEqual([])
+ await pane.press({ key: 'confirm' })
+ await pane.drawn()
+ expect(ran('delete')).toEqual(['memory delete --key beta --namespace auth --force'])
+
+ await pane.input({ key: 'mem-namespace', text: 'notes', kind: 'change' })
+ await pane.input({ key: 'mem-key', text: 'alpha', kind: 'change' })
+ await pane.input({ key: 'mem-value', text: 'the quick brown fox', kind: 'submit' })
+ expect(textOf(await pane.drawn())).toContain('runs: ruflo memory store --key alpha --value the quick brown fox --namespace notes')
+ expect(ran('store')).toEqual([])
+ await pane.press({ key: 'confirm' })
+ await pane.drawn()
+ expect(ran('store')).toEqual(['memory store --key alpha --value the quick brown fox --namespace notes'])
+ await pane.unmount()
+ })
+
+ test('memory lab: search runs at once from its field and headless, a bad key never reaches the CLI', { options: { boot: false } }, async ($, on) => {
+ const world = memoryWorld(on)
+
+ mock.clock(on)
+ await $.session.start(SESSION)
+
+ const answer = (await $.command.run(command('run mem-search token rotation'))).text ?? ''
+
+ expect(answer).toContain('0.684 auth/beta jwt refresh tokens rotate')
+ expect((await $.command.run(command('run mem-delete auth --force'))).text).not.toMatch(/^Asked/)
+ expect((await $.command.run(command('run mem-cleanup'))).text).toBe('Asked: memory cleanup. Confirm with /ruflo yes (or y in the pane), cancel with /ruflo no.')
+ await $.command.run(command('no'))
+ await $.command.run(command('memory'))
+
+ const pane = await $.ui.mount({ ...paneAt(110), surface: 'terminal' as const, plugin: PLUGIN })
+
+ await pane.drawn()
+ await pane.press({ key: 'mem-scope' })
+ await pane.input({ key: 'mem-query', text: 'token rotation', kind: 'submit' })
+ expect(textOf(await pane.drawn())).toContain('0.684 auth/beta [agentdb] jwt refresh tokens rotate')
+ expect(world.runs.map(argv => argv.slice(4).join(' ')).filter(line => /search|delete|cleanup/.test(line))).toEqual([
+ 'memory search --query token rotation --limit 10 --format json',
+ 'mcp exec -t memory_search_unified -p {"query":"token rotation","limit":10}',
+ ])
+ await pane.unmount()
+ })
+
+ test('empty sections offer the button that starts them, not a command to copy; a start asks first and runs one fixed argv', { options: { boot: false } }, async ($, on) => {
+ const { ".claude-flow/hive-mind/state.json": _hive, ...withoutHive } = RUFLO_FILES
+ const world = worldOf(on, withoutHive)
+
+ mock.clock(on)
+ await $.session.start(SESSION)
+
+ // A project with no hive-mind: the view says so and offers to start one.
+ await $.command.run(command('hive'))
+
+ const pane = await $.ui.mount({ ...paneAt(110), surface: 'terminal' as const, plugin: PLUGIN })
+ const hive = await pane.drawn()
+
- expect(textOf(hive)).toContain('No hive-mind here yet')
++ expect(textOf(hive)).toContain('Start a hive with a queen')
+ expect(textOf(hive)).not.toContain('npx ruflo')
+ expect(elementsOf(hive, 'Button').map(keyOf)).toContain('start-hive')
+
+ await pane.press({ key: 'start-hive' })
+ expect(textOf(await pane.drawn())).toContain('Confirm: start a hive-mind: a queen with raft consensus?')
+ expect(world.runs.some(argv => argv.includes('hive-mind') && argv.includes('init'))).toBe(false)
+
+ await pane.press({ key: 'confirm' })
+
+ const ran = world.runs.filter(argv => argv.includes('hive-mind') && argv.includes('init'))
+
+ expect(ran.map(argv => argv.slice(4))).toEqual([['hive-mind', 'init', '--consensus', 'raft']])
+ await pane.unmount()
+ })
+
+ test('starts that take a sentence refuse a leading dash and an empty one; nothing runs', { options: { boot: false } }, async ($, on) => {
+ const world = worldOf(on, RUFLO_FILES)
+
+ mock.clock(on)
+ await $.session.start(SESSION)
+
+ for (const text of ['', '--force']) {
+ expect((await $.command.run(command(`run start-task ${text}`))).text ?? '').not.toMatch(/^Asked: /)
+ }
+
+ expect(world.runs.some(argv => argv.includes('task') && argv.includes('create'))).toBe(false)
+ })
+
+})