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-memory' into feat/console-starts

ruv4394677afcb1
diff --cc plugins/ruflo-console/hooks/bindings.ts
index 4de8b24d76,a1cf9727b2..4cb66a8a73
--- a/plugins/ruflo-console/hooks/bindings.ts
+++ b/plugins/ruflo-console/hooks/bindings.ts
@@@ -5,9 -5,9 +5,10 @@@
import { claimTask, handoffClaim, releaseClaim, stealClaim, whyNot } from './actions'
import { EVENT_KINDS } from './data/events'
import { HARNESSES, harnessSpec, isLive, newSession, send, whyNotRun } from './harness'
+import { startSpec } from './starts'
import { plain } from './data/parse'
import type { Host } from './host'
+ import { memoryActions } from './memory-lab'
import { filterPalette, paletteEntries } from './palette'
import type { Runner } from './runner'
import { skillActions } from './skills'
diff --cc plugins/ruflo-console/hooks/palette.ts
index 73614b2b29,e891ac16cf..73492ae181
--- a/plugins/ruflo-console/hooks/palette.ts
+++ b/plugins/ruflo-console/hooks/palette.ts
@@@ -4,10 -4,9 +4,11 @@@
* argument from the query after their keyword: `route fix the login bug`.
*/
import { HIVE_ROLES, pickedProposal } from './data/hive'
+import { START_IDS, START_LABEL, startSpec } from './starts'
+import { BUDGET_PRESETS, budgetWhy, inspectModels, setBudget } from './cost'
import { hiveBroadcast, hivePropose, hiveSpawn, hiveVote } from './hive'
import { claimTask, handoffClaim, releaseClaim, stealClaim, type ActionSpec } from './actions'
+ import { MEM_KEYWORDS, MEM_LAB, memSpecOf, memWhy } from './memory-lab'
import { LAB, labSpec, labWhy } from './mh-lab'
import { AGENT_TYPES, agentLogs, dispatchWorker, memorySearch, memoryStore, reroute, setClaimStatus, spawnAgent, stopAgent, swarmInit, swarmStop, vote, WORKERS } from './ops'
import { VIEWS, type State, type ViewId } from './state'
@@@ -52,7 -50,7 +53,7 @@@ export function fuzzy(query: string, la
return whole < 0 ? score : score + 5 + (whole === 0 || text[whole - 1] === ' ' ? 3 : 0)
}
- const TEXT_KEYWORDS = ['route', 'store', 'search', 'propose', 'broadcast', 'task', 'mission', 'cost-budget', 'x-join', 'x-read', 'x-publish', 'x-create', 'x-grant', 'x-hub', 'x-admit'] as const
-const TEXT_KEYWORDS: readonly string[] = ['route', 'store', 'search', 'propose', 'broadcast', ...MEM_KEYWORDS]
++const TEXT_KEYWORDS: readonly string[] = ['route', 'store', 'search', 'propose', 'broadcast', 'task', 'mission', 'cost-budget', 'x-join', 'x-read', 'x-publish', 'x-create', 'x-grant', 'x-hub', 'x-admit', ...MEM_KEYWORDS]
/** Every entry for the state as it is, before filtering. */
export function paletteEntries(state: State, nowMs: number): PaletteEntry[] {
@@@ -128,13 -117,11 +129,18 @@@
// The MetaHarness lab: reads run at once, the rest ask first; promotion is never an entry (see mh-lab.ts).
for (const entry of LAB) add(entry.id, 'metaharness', entry.label, { kind: 'spec', spec: labSpec(entry, state), why: labWhy(entry) })
+ // The x.ruv.io board: reads run at once (the ask is the consent), writes ask first, admin rows need the token.
+ for (const entry of XRUV) {
+ // An admin row without the token is a spec with its reason, so `/ruflo run x-admit …` says why instead of "type …".
+ if (entry.takes !== undefined && (entry.kind !== 'admin' || state.xruv.hasAdminToken === true)) add(entry.id, 'x.ruv.io', `${entry.id.slice(2)} <${entry.takes}>: ${entry.label}`, { kind: 'text', keyword: entry.id, make: text => entry.spec(state, text) })
+ else add(entry.id, 'x.ruv.io', entry.label, { kind: 'spec', spec: entry.spec(state, ''), why: entry.why(state, '') })
+ }
+
+ // The Memory Lab: an entry that takes text reads it after its id (`mem-search jwt refresh`), the rest run as they are.
+ for (const entry of MEM_LAB) {
+ add(entry.id, 'memory', entry.label, entry.takes === undefined ? { kind: 'spec', spec: memSpecOf(entry, '', state), why: memWhy(entry) } : { kind: 'text', keyword: entry.id, make: text => memSpecOf(entry, text, state) })
+ }
+
for (const worker of WORKERS) add(`worker-${worker}`, 'workers', `dispatch the ${worker} background worker`, { kind: 'spec', spec: dispatchWorker(worker), why: 'unknown worker' })
add('route', 'learning', 'route <task words>: ask the router for a pick', { kind: 'text', keyword: 'route', make: reroute })
diff --cc plugins/ruflo-console/hooks/state.ts
index f1904d6b3b,0ab8ea5403..0b0fa73123
--- a/plugins/ruflo-console/hooks/state.ts
+++ b/plugins/ruflo-console/hooks/state.ts
@@@ -32,8 -33,8 +33,8 @@@ export const VIEWS: readonly { id: View
{ id: 'plugins', key: '5', label: 'Plugins', short: 'Plg', icon: '🧩', blurb: 'ruflo plugins: installed, enabled, in the marketplace clone, and loaded as mods', rows: 30 },
{ id: 'learning', key: '6', label: 'Learning', short: 'Lrn', icon: '🧠', blurb: 'router picks and outcomes, and the RETRIEVE β†’ JUDGE β†’ DISTILL β†’ CONSOLIDATE pipeline', rows: 30 },
{ id: 'metaharness', key: '7', label: 'MetaHarness', short: 'MH', icon: 'πŸ”¬', blurb: 'harness readiness, the flywheel, the audit trend, and a lab that runs every MetaHarness verb', rows: 40 },
- { id: 'memory', key: '8', label: 'Memory', short: 'Mem', icon: 'πŸ’Ύ', blurb: 'AgentDB entries by namespace: what the swarm has stored', rows: 22 },
+ { id: 'memory', key: '8', label: 'Memory', short: 'Mem', icon: 'πŸ’Ύ', blurb: 'the Memory Lab: browse, search, store and delete entries; AgentDB, embeddings and upkeep, each a button', rows: 60 },
- { id: 'cost', key: '9', label: 'Cost', short: 'Cst', icon: 'πŸ’°', blurb: 'this session spend against the budget, and how fast it is burning', rows: 20 },
+ { id: 'cost', key: '9', label: 'Cost', short: 'Cst', icon: 'πŸ’°', blurb: 'set a budget, see where spend is reported, and project its burn', rows: 40 },
{ id: 'timeline', key: 'g', label: 'Timeline', short: 'Gnt', icon: 'πŸ•’', blurb: 'each agent busy or idle over the last minutes, beside Claude Code tool calls', rows: 24 },
{ id: 'approvals', key: 'q', label: 'Approvals', short: 'Apv', icon: 'βœ…', blurb: 'decisions waiting for a person: votes, stealable claims, refused mods, budget', rows: 24 },
{ id: 'events', key: 'e', label: 'Events', short: 'Evt', icon: 'πŸ“‘', blurb: 'every swarm, claim, memory and mod event as it happens (f filters them)', rows: 26 },
@@@ -267,11 -260,11 +270,12 @@@ export function newState(raw: PluginOpt
outcome: null,
isActing: false,
lab: { result: null, running: null },
+ xruv: { result: null, running: null, pubkey: null, hasAdminToken: null },
isRefreshing: false,
barDrawnAtMs: 0,
- terminal: { harness: 'codex', draft: '', lines: [], runs: new Map(), sessions: {}, isLive: { codex: false, claude: false }, turns: { codex: 0, claude: 0 }, costUsd: 0, scroll: 0, unseen: 0, asked: null },
+ terminal: { harness: 'codex', draft: '', lines: [], runs: new Map(), sessions: {}, isLive: { codex: false, claude: false }, turns: { codex: 0, claude: 0 }, costUsd: 0, costReports: 0, scroll: 0, unseen: 0, asked: null },
skills: emptySkills(),
+ memoryLab: emptyMemoryLab(),
timers: new Map(),
stats: { renders: [], refreshes: [], frames: [] },
}
diff --cc plugins/ruflo-console/hooks/views/common.ts
index 8d79df5fb3,175b08acca..e6ac12398b
--- a/plugins/ruflo-console/hooks/views/common.ts
+++ b/plugins/ruflo-console/hooks/views/common.ts
@@@ -7,8 -7,8 +7,9 @@@ import type { Elements, RenderChildren
import type { ProbeResult } from '../data/cli'
import type { Grid } from '../gfx/raster'
+ import type { MemoryActions } from '../memory-lab'
import type { SkillActions } from '../skills'
+import { START_LABEL, type StartId } from '../starts'
import type { HarnessId, State, ViewId } from '../state'
export type Kit = Pick<Elements['terminal'], 'Box' | 'Text' | 'Button'> & { Raster?: Elements['terminal']['Raster']; Input?: Elements['terminal']['Input'] }
diff --cc plugins/ruflo-console/tests/fixtures/views.ts
index 0000000000,0000000000..addb2a8eca
new file mode 100644
--- /dev/null
+++ b/plugins/ruflo-console/tests/fixtures/views.ts
@@@ -1,0 -1,0 +1,41 @@@
++import type { TestBody } from 'claude-code/testing'
++
++import { MEM_OUT } from './memory'
++import { RUFLO_FILES } from './ruflo-run'
++import { cliAnswer, command, elementsOf, keyOf, paneAt, PLUGIN, textOf, worldOf } from './world'
++
++export type Engine = Parameters<TestBody>[0]
++
++/** The captured world, with the Memory Lab's reads answered from a two-entry store (auth/beta, notes/alpha). */
++export function memoryWorld(on: Parameters<TestBody>[1]) {
++ const world = worldOf(on, RUFLO_FILES)
++ const out = (stdout: string) => ({ exitCode: 0, stdout, stderr: '' })
++
++ world.respond = argv => {
++ const line = argv.join(' ')
++
++ if (line.includes('memory stats')) return out(MEM_OUT.stats ?? '')
++ if (line.includes('memory list')) return out(MEM_OUT.list ?? '')
++ if (line.includes('memory retrieve')) return out(MEM_OUT.retrieve ?? '')
++ if (line.includes('memory search')) return out(MEM_OUT.search ?? '')
++ if (line.includes('memory_search_unified')) return out(MEM_OUT.unified ?? '')
++
++ return cliAnswer(argv)
++ }
++
++ return world
++}
++
++/** Opens the console on `view` via /ruflo, waits for its probes, and answers its drawing and its Raster keys. */
++export async function drawn($: Engine, view: string, columns = 110) {
++ await $.command.run(command(view))
++ await $.command.run(command('status'))
++
++ const pane = await $.ui.mount({ ...paneAt(columns), plugin: PLUGIN })
++ const tree = await pane.drawn()
++
++ await pane.unmount()
++
++ return { text: textOf(tree), tree, rasters: elementsOf(tree, 'Raster').map(keyOf) }
++}
++
diff --cc plugins/ruflo-console/tests/labs.test.ts
index 0000000000,0000000000..ff86a841ac
new file mode 100644
--- /dev/null
+++ b/plugins/ruflo-console/tests/labs.test.ts
@@@ -1,0 -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)).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)
++ })
++
++})
diff --cc plugins/ruflo-console/tests/views.test.ts
index 67c7884d47,04c46f6abb..bde2d8b57b
--- a/plugins/ruflo-console/tests/views.test.ts
+++ b/plugins/ruflo-console/tests/views.test.ts
@@@ -19,22 -20,42 +20,10 @@@ const HOME_FILES =
'.claude/plugins/marketplaces/ruflo/.claude-plugin/marketplace.json': JSON.stringify({ name: 'ruflo', plugins: [{ name: 'ruflo-core' }, { name: 'ruflo-swarm' }] }),
}
--type Engine = Parameters<TestBody>[0]
-
-/** The captured world, with the Memory Lab's reads answered from a two-entry store (auth/beta, notes/alpha). */
-function memoryWorld(on: Parameters<TestBody>[1]) {
- const world = worldOf(on, RUFLO_FILES)
- const out = (stdout: string) => ({ exitCode: 0, stdout, stderr: '' })
-
- world.respond = argv => {
- const line = argv.join(' ')
-
- if (line.includes('memory stats')) return out(MEM_OUT.stats ?? '')
- if (line.includes('memory list')) return out(MEM_OUT.list ?? '')
- if (line.includes('memory retrieve')) return out(MEM_OUT.retrieve ?? '')
- if (line.includes('memory search')) return out(MEM_OUT.search ?? '')
- if (line.includes('memory_search_unified')) return out(MEM_OUT.unified ?? '')
-
- return cliAnswer(argv)
- }
-
- return world
-}
--
--/** Opens the console on `view` via /ruflo, waits for its probes, and answers its drawing and its Raster keys. */
--async function drawn($: Engine, view: string, columns = 110) {
-- await $.command.run(command(view))
-- await $.command.run(command('status'))
--
-- const pane = await $.ui.mount({ ...paneAt(columns), plugin: PLUGIN })
-- const tree = await pane.drawn()
--
-- await pane.unmount()
--
-- return { text: textOf(tree), tree, rasters: elementsOf(tree, 'Raster').map(keyOf) }
--}
++import { drawn } from './fixtures/views'
describe('views', () => {
++
test('overview: every subsystem from disk, the CLI or the engine, health alerts, the activity raster', { options: { boot: false } }, async ($, on) => {
fakeRuflo().register(on, {})
worldOf(on, RUFLO_FILES, { home: HOME_FILES })
@@@ -221,90 -242,96 +210,16 @@@
expect(cost.rasters).toEqual(['header', 'title', 'gauge', 'burn'])
expect(cost.text).toContain('$0.421')
expect(cost.text).toContain('WARNING Β· $3.90 of $5.00 (78%)')
- })
-
- 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()
+ expect(cost.text).toContain('WHERE IT GOES')
+ expect(cost.text).toContain('AI terminal')
+ expect(cost.text).toContain('8 decisions')
+ expect(cost.text).toContain('5 routes Β· spend n/a Β· tokens n/a')
+ expect(cost.text).toContain('$1.100 Β· ruflo-mods budget')
+ expect(cost.text).toContain('50% Β· $2.50')
+ expect(elementsOf(cost.tree, 'Button').map(keyOf)).toEqual(expect.arrayContaining(['cost-budget-1', 'cost-budget-5', 'cost-budget-10', 'cost-budget-25', 'cost-budget-apply', 'cost-model-stats']))
+ expect(elementsOf(cost.tree, 'Input').map(keyOf)).toEqual(['cost-budget'])
})
- 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('timeline, approvals and events draw from what was seen; the drill-down opens an agent', { options: { boot: false } }, async ($, on) => {
const world = worldOf(on, RUFLO_FILES)
mock.clock(on)
diff --cc scripts/ci-test-baseline.txt
index 0229bb5522,e3fe62415a..f66bff8d7c
--- a/scripts/ci-test-baseline.txt
+++ b/scripts/ci-test-baseline.txt
@@@ -163,4 -163,3 +163,5 @@@ plugins/ruflo-console/tests/actions.tes
plugins/ruflo-console/tests/behaviour.test.ts
plugins/ruflo-console/tests/palette.test.ts
plugins/ruflo-console/tests/views.test.ts
++plugins/ruflo-console/tests/labs.test.ts
+plugins/ruflo-console/tests/xruv.test.ts