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-console): 0.17.0 — ruflo Optimizer: findings with confirm-gated fixes, scope, before/after, on the Overview

ruvba8a84212c5d
diff --git a/plugins/ruflo-console/.claude-plugin/plugin.json b/plugins/ruflo-console/.claude-plugin/plugin.json
index 99c3f3c50e..1b601be055 100644
--- a/plugins/ruflo-console/.claude-plugin/plugin.json
+++ b/plugins/ruflo-console/.claude-plugin/plugin.json
@@ -1,7 +1,7 @@
{
"name": "ruflo-console",
"description": "ruflo's cockpit inside Claude Code and the one /ruflo command for every ruflo mod (function hooks, early access). Views: overview with health alerts, swarm topology graph, claims flow with TTL rings, federation map, plugin health matrix, learning curve and pipeline, MetaHarness radar and audit trend, memory, cost gauge, agent timeline, approvals queue, event stream, a main menu, an x.ruv.io federation board, an AI terminal (codex, claude or both in remembered sessions, streamed), Skills (npx skills), a Hive-Mind view, a MetaHarness lab, agent drill-down; a command palette for confirm-gated actions through the ruflo CLI; a band above the prompt. Reads ruflo's files and the CLI's local JSON; anything not measured reads n/a; no network by default.",
- "version": "0.14.1",
+ "version": "0.17.0",
"author": {
"name": "ruvnet",
"url": "https://github.com/ruvnet"
diff --git a/plugins/ruflo-console/hooks/bindings.ts b/plugins/ruflo-console/hooks/bindings.ts
index 5876abc588..e500bd0614 100644
--- a/plugins/ruflo-console/hooks/bindings.ts
+++ b/plugins/ruflo-console/hooks/bindings.ts
@@ -6,6 +6,7 @@ import { claimTask, handoffClaim, releaseClaim, stealClaim, whyNot } from './act
import { EVENT_KINDS } from './data/events'
import { evolveActions } from './evolve'
import { askActions } from './ask-claude'
+import { optimizerActions } from './optimizer'
import { missionActions } from './mission-control'
import { catalogActions } from './plugin-catalog'
import { saveAllowed } from './remember'
@@ -326,6 +327,7 @@ export function actionsOf(state: State, host: Host, runner: Runner, steps: Steps
settings: settingsActions(state, host, runner, (agent, text) => actions.term.ask(agent, text), () => CLI_PREFIXES[state.options.cli], () => pluginNames(state, (catalogOf(state).plugins ?? []).filter(plugin => plugin.options.length > 0).map(plugin => plugin.name))),
mission: missionActions(state, host, runner),
ask: askActions(state, host, runner, () => actions),
+ optimizer: optimizerActions(state, () => host.invalidate(), id => void runner.runById(id, ''), question => actions.ask.ask(question, 'overview')),
catalog: catalogActions(state, host, runner, text => actions.term.load('claude', text)),
devtools: devtoolsActions(state, host, runner.runById, why => runner.ask(null, why)),
}
diff --git a/plugins/ruflo-console/hooks/optimizer.ts b/plugins/ruflo-console/hooks/optimizer.ts
new file mode 100644
index 0000000000..5cdd013212
--- /dev/null
+++ b/plugins/ruflo-console/hooks/optimizer.ts
@@ -0,0 +1,185 @@
+/**
+ * The ruflo Optimizer: what is wrong or thin in this project (from what the console already measured, never from a guess), and a fix
+ * for each that is one confirm-gated button. Learning, memory and vectors, performance, the swarm and the install are checked. A fix is
+ * always an existing palette entry (a fixed argv through the ruflo CLI that asks first), so the Optimizer adds no new way to write: it
+ * finds the problem, offers the right button, and shows the metric before and after. The scope setting limits which fixes are offered
+ * (safe: reads and light upkeep; balanced: local compute that writes ruflo's own stores; deep: heavier rebuilds and model downloads).
+ */
+import { alertsOf } from './data/alerts'
+import type { MemoryStats, Namespaces } from './data/cli'
+import { EPOCHS, PATTERNS } from './data/automate'
+import type { State } from './state'
+
+export type Scope = 'safe' | 'balanced' | 'deep'
+export const SCOPES: readonly { id: Scope; title: string; about: string }[] = [
+ { id: 'safe', title: 'Safe', about: 'reads and light upkeep' },
+ { id: 'balanced', title: 'Balanced', about: 'local compute that writes ruflo’s own stores' },
+ { id: 'deep', title: 'Deep', about: 'heavier rebuilds, may fetch a model' },
+]
+const RANK: Record<Scope, number> = { safe: 0, balanced: 1, deep: 2 }
+
+export type Fix = { id: string; label: string; tier: Scope; /** Why it is that tier and what it does. */ note: string }
+export type Finding = { id: string; area: 'learning' | 'memory' | 'performance' | 'swarm' | 'install' | 'health'; level: 'bad' | 'warn' | 'info'; title: string; why: string; metric: string; fixes: Fix[] }
+
+/** A probe's value when it last read ok (the same rule the views use: an error newer than the last ok hides it). */
+const probe = <T>(state: State, key: string): T | null => {
+ const result = state.probes.get(key)
+
+ if (result === undefined || result.value === null) return null
+ if (result.error !== null && (result.errorAtMs ?? 0) >= (result.okAtMs ?? 0)) return null
+
+ return result.value as T
+}
+
+const fix = (id: string, label: string, tier: Scope, note: string): Fix => ({ id, label, tier, note })
+
+/** The findings for this project right now, worst first. Only what was read is judged: an unread store is a finding to check, not a verdict. */
+export function diagnose(state: State, nowMs: number, loadedAtMs: number): Finding[] {
+ const snap = state.snapshot
+ const out: Finding[] = []
+
+ if (snap === null) return out
+
+ // ---- learning
+ const neural = snap.neural
+ const outcomes = snap.outcomes
+
+ if (neural === null || (neural.patterns ?? 0) === 0) {
+ out.push({
+ id: 'learning-empty',
+ area: 'learning',
+ level: 'warn',
+ title: 'ruflo has learned nothing here yet',
+ why: 'no patterns in the neural store: routing and recall start from nothing. Pretraining reads this repository and writes the first ones.',
+ metric: neural === null ? 'patterns n/a' : `patterns ${neural.patterns ?? 0}`,
+ fixes: [fix('nn-pretrain-shallow', 'pretrain (shallow)', 'safe', 'local; reads the repository, writes the intelligence store'), fix('nn-pretrain-medium', 'pretrain (medium)', 'balanced', 'local; a fuller read of the repository'), fix(`nn-train-${PATTERNS[0]}-${EPOCHS[0]}`, `train ${PATTERNS[0]} (${EPOCHS[0]} epochs)`, 'balanced', 'local compute; writes .claude-flow/neural')],
+ })
+ }
+
+ if (outcomes !== null && outcomes.total >= 10 && outcomes.successes / outcomes.total < 0.6) {
+ out.push({
+ id: 'router-accuracy',
+ area: 'learning',
+ level: 'warn',
+ title: 'the router is missing too often',
+ why: `only ${Math.round((outcomes.successes / outcomes.total) * 100)}% of ${outcomes.total} routed tasks succeeded: train on what worked, and look at why it routes the way it does.`,
+ metric: `success ${outcomes.successes}/${outcomes.total}`,
+ fixes: [fix('nn-patterns', 'review the patterns', 'safe', 'a read'), fix('nn-pretrain-medium', 'pretrain (medium)', 'balanced', 'local; writes the intelligence store'), fix('nn-quantize', 'quantize patterns', 'deep', 'local; rewrites the stored patterns to Int8')],
+ })
+ }
+
+ if (snap.router === null && snap.isRufloProject) {
+ out.push({ id: 'router-state', area: 'learning', level: 'info', title: 'no model-router state yet', why: 'the model router has made no decision here, so there is nothing to tune: it fills as agents route tasks.', metric: 'decisions n/a', fixes: [fix('nn-status', 'neural status', 'safe', 'a read: every learning component and whether it is loaded')] })
+ }
+
+ // ---- memory and vectors (judged only when the Memory probes have run)
+ const memory = probe<MemoryStats>(state, 'memory')
+ const spaces = probe<Namespaces>(state, 'namespaces')
+
+ if (memory === null) {
+ out.push({ id: 'memory-unchecked', area: 'memory', level: 'info', title: 'memory has not been checked this session', why: 'open Memory, or read its health here: the vector coverage and the second store are judged from it.', metric: 'memory n/a', fixes: [fix('mem-health', 'check AgentDB health', 'safe', 'a read')] })
+ } else {
+ const listed = spaces?.entries ?? []
+ const embedded = listed.filter(entry => entry.hasVector).length
+
+ if (listed.length > 0 && embedded / listed.length < 0.6) {
+ out.push({
+ id: 'memory-vectors',
+ area: 'memory',
+ level: 'warn',
+ title: 'many memories have no vector',
+ why: `${listed.length - embedded} of the newest ${listed.length} entries cannot be found by meaning. Initialise the embedding model, then rebuild the index.`,
+ metric: `vectors ${embedded}/${listed.length}`,
+ fixes: [fix('mem-embed-status', 'embedding status', 'safe', 'a read'), fix('mem-embed-init', 'initialise embeddings', 'deep', 'may fetch the model (network) the first time'), fix('mem-rabitq-build', 'rebuild the RaBitQ index', 'deep', 'local compute; writes the vector index')],
+ })
+ }
+
+ if ((memory.unread ?? 0) > 0) {
+ out.push({ id: 'memory-second-store', area: 'memory', level: 'info', title: 'a second memory store is not in the counts', why: `${memory.unread} rows in .swarm/agentdb-memory.db (the MCP path’s store) are outside the CLI’s counts and list. Unified search reads them; consolidation tidies both.`, metric: `unread ${memory.unread}`, fixes: [fix('mem-bridge', 'memory bridge status', 'safe', 'a read'), fix('mem-consolidate', 'consolidate memories', 'balanced', 'local; rewrites retained memories')] })
+ }
+
+ if ((memory.total ?? 0) > 500) {
+ out.push({ id: 'memory-size', area: 'memory', level: 'info', title: 'the store is large enough to compact', why: `${memory.total} entries: compressing the store and planning a cleanup keeps search fast.`, metric: `entries ${memory.total}`, fixes: [fix('mem-cleanup-plan', 'plan a cleanup', 'safe', 'a read: what would go, nothing deleted'), fix('mem-compress', 'compress the store', 'balanced', 'local; rewrites the store')] })
+ }
+ }
+
+ // ---- performance
+ out.push({ id: 'performance-unprofiled', area: 'performance', level: 'info', title: 'where the time goes has not been measured', why: 'find the bottleneck before optimising: a read shows it, and optimise applies ruflo’s own suggestions.', metric: 'bottlenecks n/a', fixes: [fix('perf-bottleneck', 'find bottlenecks', 'safe', 'a read'), fix('perf-optimize', 'optimise', 'balanced', 'local; applies ruflo’s suggested settings')] })
+
+ // ---- health and the install (what the console already raises as alerts)
+ for (const alert of alertsOf(state, nowMs, loadedAtMs)) {
+ out.push({
+ id: `alert-${alert.id}`,
+ area: alert.id === 'marketplace' || alert.id === 'mods' || alert.id.startsWith('refused') ? 'install' : alert.id.startsWith('stalled') || alert.id.startsWith('expired') || alert.id.startsWith('old') ? 'swarm' : 'health',
+ level: alert.level,
+ title: alert.text,
+ why: `how to fix it: ${alert.fix}`,
+ metric: alert.level,
+ fixes: alert.paletteId === undefined ? [] : [fix(alert.paletteId, alert.paletteId.replace(/-/g, ' '), 'safe', 'the palette entry for this alert; it asks first')],
+ })
+ }
+
+ out.push({ id: 'health-doctor', area: 'health', level: 'info', title: 'run the full health check', why: 'doctor checks Node, git, config, the daemon, memory, MCP, AIDefence, disk, helpers and mods; with --fix it also applies the fix for each warning.', metric: 'doctor n/a', fixes: [fix('doc-all', 'doctor: every check', 'safe', 'a read'), fix('doc-fix', 'doctor --fix', 'balanced', 'writes: applies each warning’s fix')] })
+
+ const order = { bad: 0, warn: 1, info: 2 } as const
+
+ return out.sort((a, b) => order[a.level] - order[b.level])
+}
+
+/** The fixes of a finding that this scope offers. */
+export const offered = (finding: Finding, scope: Scope): Fix[] => finding.fixes.filter(candidate => RANK[candidate.tier] <= RANK[scope])
+
+/** The finding's metric as it reads now, so a fix can show before → now. */
+export function metricNow(state: State, id: string, nowMs: number, loadedAtMs: number): string | null {
+ return diagnose(state, nowMs, loadedAtMs).find(finding => finding.id === id)?.metric ?? null
+}
+
+export type OptimizerState = { scope: Scope; /** finding id → its metric when a fix was last pressed. */ before: Map<string, string>; /** finding id → the fix last run. */ ran: Map<string, string> }
+
+const states = new WeakMap<State, OptimizerState>()
+
+export function optimizerOf(state: State): OptimizerState {
+ let found = states.get(state)
+
+ if (found === undefined) {
+ found = { scope: 'safe', before: new Map(), ran: new Map() }
+ states.set(state, found)
+ }
+
+ return found
+}
+
+export type OptimizerActions = {
+ scope: (scope: Scope) => void
+ /** Presses a fix: remembers the metric as it is now, then runs the palette entry (which asks first unless it is a read). */
+ fix: (findingId: string, fixId: string) => void
+ /** Asks the main Claude about one finding. */
+ ask: (findingId: string) => void
+}
+
+export function optimizerActions(state: State, invalidate: () => void, run: (id: string) => void, ask: (question: string) => void): OptimizerActions {
+ const cfg = optimizerOf(state)
+
+ return {
+ scope: scope => {
+ cfg.scope = scope
+ invalidate()
+ },
+ fix: (findingId, fixId) => {
+ const now = Date.now()
+ const finding = diagnose(state, now, state.loadedAtMs).find(candidate => candidate.id === findingId)
+
+ if (finding === undefined || !finding.fixes.some(candidate => candidate.id === fixId)) return
+
+ cfg.before.set(findingId, finding.metric)
+ cfg.ran.set(findingId, fixId)
+ run(fixId)
+ },
+ ask: findingId => {
+ const finding = diagnose(state, Date.now(), state.loadedAtMs).find(candidate => candidate.id === findingId)
+
+ if (finding !== undefined) ask(`About this finding in my ruflo project: "${finding.title}" (${finding.metric}). ${finding.why} What is the best way to fix it here, and what should I watch for?`)
+ },
+ }
+}
+
diff --git a/plugins/ruflo-console/hooks/views/common.ts b/plugins/ruflo-console/hooks/views/common.ts
index c6ee240f96..adbb177454 100644
--- a/plugins/ruflo-console/hooks/views/common.ts
+++ b/plugins/ruflo-console/hooks/views/common.ts
@@ -4,6 +4,7 @@
* Text colours are theme names only, so nothing fades on a light background.
*/
import type { AskActions } from '../ask-claude'
+import type { OptimizerActions } from '../optimizer'
import type { Attention } from './attention'
import type { Elements, RenderChildren, RenderElement } from 'claude-code'
@@ -68,6 +69,8 @@ export type Actions = {
evolve: EvolveActions
/** The Dev Tools view: keep a field's text, and Enter in a field runs its entry. */
devtools: DevtoolsActions
+ /** The Optimizer (Overview): scope, fixes (each asks first) and asking Claude about a finding. */
+ optimizer: OptimizerActions
/** Ask Claude about this section (a visible prompt or a /btw aside) or run the plugin command that fits it: each asks first. */
ask: AskActions
/** Mission Control: goal, profile, create, run next, pause/resume/cancel, auto-run, ask aside, guide Claude. */
diff --git a/plugins/ruflo-console/hooks/views/optimizer.ts b/plugins/ruflo-console/hooks/views/optimizer.ts
new file mode 100644
index 0000000000..5ec7313736
--- /dev/null
+++ b/plugins/ruflo-console/hooks/views/optimizer.ts
@@ -0,0 +1,77 @@
+import type { RenderElement } from 'claude-code'
+
+import { diagnose, offered, optimizerOf, metricNow, SCOPES, type Finding } from '../optimizer'
+import { slot } from './attention'
+import { clip, row, section, text, THEME, type Ctx } from './common'
+
+const GLYPH = { bad: '✖', warn: '⚠', info: 'ℹ' } as const
+const COLOR = { bad: () => THEME.bad, warn: () => THEME.warn, info: () => THEME.info } as const
+
+const chip = (ctx: Ctx, key: string, label: string, isOn: boolean, onPress: () => void): RenderElement =>
+ ctx.kit.Button({ key, label: ` ${isOn ? 'â—Ź' : 'â—‹'} ${label} `, plain: true, ...(isOn && { variant: 'primary' as const }), onPress })
+
+/** One finding: its level and title with the metric, why, the fixes this scope offers (each one button), and before → now after a fix. */
+function findingRows(ctx: Ctx, finding: Finding): RenderElement[] {
+ const cfg = optimizerOf(ctx.state)
+ const fixes = offered(finding, cfg.scope)
+ const before = cfg.before.get(finding.id)
+ const now = before === undefined ? null : metricNow(ctx.state, finding.id, ctx.nowMs, ctx.state.loadedAtMs)
+
+ return [
+ row(ctx, [ctx.kit.Text({ bold: true, color: COLOR[finding.level](), children: ` ${GLYPH[finding.level]} ${clip(finding.title, Math.max(20, ctx.columns - 34))} ` }), ctx.kit.Text({ dimColor: true, children: `· ${finding.area} · ${finding.metric}` })], `opt-head-${finding.id}`),
+ text(ctx, ` ${clip(finding.why, Math.max(20, ctx.columns - 6))}`, { dimColor: true }),
+ row(
+ ctx,
+ [
+ ...fixes.map(item => ctx.kit.Button({ key: `opt-fix-${finding.id}-${item.id}`, label: ` â–¸ ${item.label} `, plain: true, onPress: () => ctx.act.optimizer.fix(finding.id, item.id) })),
+ ...(fixes.length === 0 ? [ctx.kit.Text({ dimColor: true, children: finding.fixes.length === 0 ? ' no button for this one: read how to fix it above' : ' a wider scope offers fixes for this' })] : []),
+ ctx.kit.Button({ key: `opt-ask-${finding.id}`, label: ' ✦ ask Claude ', plain: true, dimColor: true, onPress: () => ctx.act.optimizer.ask(finding.id) }),
+ ],
+ `opt-fixes-${finding.id}`,
+ ),
+ ...(before === undefined ? [] : [text(ctx, ` after ${cfg.ran.get(finding.id) ?? 'a fix'}: ${before} → now ${now ?? 'resolved (no longer a finding)'} (refresh r re-reads)`, { color: now === null ? THEME.ok : THEME.info })]),
+ ]
+}
+
+/** The answer of the last fix that ran from here: its result lines, drawn where the pressed button is (or here, when it is not on screen). */
+function resultRows(ctx: Ctx): RenderElement[] {
+ const cfg = optimizerOf(ctx.state)
+ const fixIds = new Set(diagnose(ctx.state, ctx.nowMs, ctx.state.loadedAtMs).flatMap(finding => finding.fixes.map(item => item.id)))
+ const result = ctx.state.lab.result !== null && (fixIds.has(ctx.state.lab.result.id) || [...cfg.ran.values()].includes(ctx.state.lab.result.id)) ? ctx.state.lab.result : null
+
+ if (result === null) return []
+
+ const rows: RenderElement[] = [text(ctx, ` ${result.ok ? 'âś“' : 'âś—'} ${result.label}`, { bold: true, color: result.ok ? THEME.ok : THEME.bad })]
+
+ if (result.note !== undefined) rows.push(text(ctx, ` ${result.note}`, { color: THEME.warn }))
+ for (const line of result.lines.slice(0, 14)) rows.push(text(ctx, ` ${line}`, line.startsWith('âš ') ? { color: THEME.warn } : {}))
+ if (result.lines.length > 14) rows.push(text(ctx, ` … ${result.lines.length - 14} more lines: open the section that owns this command`, { dimColor: true }))
+
+ return slot(ctx, rows)
+}
+
+/**
+ * The Optimizer, a section of the Overview: the problems and thin spots found from what the console read, a fix button for each (it
+ * asks first), a scope that limits which fixes are offered, and the metric before and after. Its answers open under the button pressed.
+ */
+export function optimizerRows(ctx: Ctx): RenderElement[] {
+ const cfg = optimizerOf(ctx.state)
+ const findings = diagnose(ctx.state, ctx.nowMs, ctx.state.loadedAtMs)
+ const attention = findings.filter(finding => finding.level !== 'info').length
+
+ return section(
+ ctx,
+ 'optimizer',
+ 'Optimizer',
+ `${findings.length} finding${findings.length === 1 ? '' : 's'}${attention > 0 ? ` · ${attention} need attention` : ''} · fixes ask first`,
+ [
+ row(ctx, [text(ctx, ' scope '), ...SCOPES.map(scope => chip(ctx, `opt-scope-${scope.id}`, `${scope.title} · ${scope.about}`, cfg.scope === scope.id, () => ctx.act.optimizer.scope(scope.id)))], 'opt-scopes'),
+ ...(findings.length === 0 ? [text(ctx, ' nothing found: the project is still being read', { dimColor: true })] : findings.flatMap(finding => findingRows(ctx, finding))),
+ ...resultRows(ctx),
+ ],
+ true,
+ )
+}
+
+/** This section's result block alone: the pane asks for it to place under the fix button that was pressed. */
+export const optimizerResult = (ctx: Ctx): RenderElement[] => resultRows(ctx)
diff --git a/plugins/ruflo-console/hooks/views/overview.ts b/plugins/ruflo-console/hooks/views/overview.ts
index b07aebc468..341ff602a2 100644
--- a/plugins/ruflo-console/hooks/views/overview.ts
+++ b/plugins/ruflo-console/hooks/views/overview.ts
@@ -3,6 +3,7 @@ import type { RenderElement } from 'claude-code'
import { alertsOf } from '../data/alerts'
import type { MemoryStats } from '../data/cli'
import type { StartId } from '../starts'
+import { optimizerRows } from './optimizer'
import { ago, col, count, kv, live, picture, rule, sourceLine, starts, text, THEME, type Ctx } from './common'
/** Each subsystem in one line: what it is, from where, as of when. Nothing on this view is estimated. */
@@ -17,7 +18,7 @@ export function overviewView(ctx: Ctx): RenderElement {
const loaded = state.mods.filter(mod => mod.isLoaded).length
const refused = state.mods.length - loaded
const swarm = snap?.swarm ?? null
- const rows: RenderElement[] = [rule(ctx, 'Subsystems', snap?.isRufloProject === false ? 'not a ruflo project' : '')]
+ const rows: RenderElement[] = [...optimizerRows(ctx), rule(ctx, 'Subsystems', snap?.isRufloProject === false ? 'not a ruflo project' : '')]
rows.push(kv(ctx, 'ruflo CLI', version !== null ? `v${version} (${state.options.cli})` : sourceLine(state.probes.get('version'), nowMs, 'n/a').text))
rows.push(
diff --git a/plugins/ruflo-console/hooks/views/pane.ts b/plugins/ruflo-console/hooks/views/pane.ts
index b20601513d..32ececfa6f 100644
--- a/plugins/ruflo-console/hooks/views/pane.ts
+++ b/plugins/ruflo-console/hooks/views/pane.ts
@@ -9,6 +9,7 @@ import { HELP } from '../commands'
import { slashFor } from '../ask-claude'
import { launchRows } from './launch'
import { donated, newAttention, panelOf, wrapKit } from './attention'
+import { optimizerResult } from './optimizer'
import { isBooting, isCompactPane, NAV_STYLES, VIEWS, type ViewId } from '../state'
import { agentView } from './agent'
import { automateResult, automateView } from './automate'
@@ -245,6 +246,7 @@ function wildcat(ctx: Ctx): { strip: RenderElement[]; art: RenderElement[] } {
/** The views whose lab result block can be drawn alone (so finding it costs one block, not a second page). */
const RESULT_OF: Partial<Record<ViewId, (ctx: Ctx) => RenderElement[]>> = {
+ overview: optimizerResult,
metaharness: labResult,
devtools: devtoolsResult,
vector: vectorResult,
diff --git a/plugins/ruflo-console/scripts/smoke.sh b/plugins/ruflo-console/scripts/smoke.sh
index 59af72f5bf..d49f60c405 100755
--- a/plugins/ruflo-console/scripts/smoke.sh
+++ b/plugins/ruflo-console/scripts/smoke.sh
@@ -11,9 +11,9 @@ step() { printf "→ %s ... " "$1"; }
ok() { printf "PASS\n"; PASS=$((PASS+1)); }
bad() { printf "FAIL: %s\n" "$1"; FAIL=$((FAIL+1)); }
-step "1. plugin.json declares ruflo-console 0.14.1"
+step "1. plugin.json declares ruflo-console 0.17.0"
grep -q '"name": "ruflo-console"' "$ROOT/.claude-plugin/plugin.json" \
- && grep -q '"version": "0.14.1"' "$ROOT/.claude-plugin/plugin.json" && ok || bad "name/version"
+ && grep -q '"version": "0.17.0"' "$ROOT/.claude-plugin/plugin.json" && ok || bad "name/version"
step "2. hooks.json names exactly one module and no classic hook commands"
grep -q '"modules": \["./register.ts"\]' "$HOOKS/hooks.json" && ! grep -q '"command"' "$HOOKS/hooks.json" \
diff --git a/plugins/ruflo-console/tests/optimizer.spec.ts b/plugins/ruflo-console/tests/optimizer.spec.ts
new file mode 100644
index 0000000000..4d270d0591
--- /dev/null
+++ b/plugins/ruflo-console/tests/optimizer.spec.ts
@@ -0,0 +1,92 @@
+/**
+ * The Optimizer under vitest: what it finds from what was measured, worst first; which fixes each scope offers; that every fix is a
+ * real palette entry (a typo would be a dead button); and that pressing a fix remembers the metric before and runs that entry.
+ */
+import { describe, expect, it } from 'vitest'
+
+import { diagnose, offered, optimizerActions, optimizerOf } from '../hooks/optimizer'
+import { paletteEntries } from '../hooks/palette'
+import { newState, type State } from '../hooks/state'
+
+const NOW = Date.UTC(2026, 9, 3, 12)
+
+function stateWith(snapshot: Record<string, unknown>, probes: Record<string, unknown> = {}): State {
+ const state = newState({})
+
+ state.snapshot = { neural: null, router: null, outcomes: null, sona: null, agents: [], claims: [], tasks: [], daemon: null, isRufloProject: true, plugins: { missingFromClone: [] }, readAtMs: NOW, ...snapshot } as never
+
+ for (const [key, value] of Object.entries(probes)) state.probes.set(key, { value, okAtMs: NOW, error: null, errorAtMs: null, isRunning: false } as never)
+
+ return state
+}
+
+const ids = (state: State) => diagnose(state, NOW, NOW - 1_000).map(finding => finding.id)
+
+describe('optimizer', () => {
+ it('an empty project: nothing learned, memory and performance unchecked, the health check on offer', () => {
+ const found = ids(stateWith({}))
+
+ expect(found).toEqual(expect.arrayContaining(['learning-empty', 'router-state', 'memory-unchecked', 'performance-unprofiled', 'health-doctor']))
+ expect(found).not.toContain('router-accuracy')
+ })
+
+ it('what was learned is not called empty; a low router success rate with enough outcomes is a finding, a small N is not', () => {
+ const learned = { neural: { trajectories: 4, patterns: 12, signals: 3 } }
+
+ expect(ids(stateWith(learned))).not.toContain('learning-empty')
+ expect(ids(stateWith({ ...learned, outcomes: { total: 20, successes: 8, points: [] } }))).toContain('router-accuracy')
+ expect(ids(stateWith({ ...learned, outcomes: { total: 5, successes: 1, points: [] } }))).not.toContain('router-accuracy')
+ expect(ids(stateWith({ ...learned, outcomes: { total: 20, successes: 18, points: [] } }))).not.toContain('router-accuracy')
+ })
+
+ it('memory is judged only once its probes have read: thin vector coverage, a second store, and a large store each become findings', () => {
+ const entries = [1, 2, 3, 4, 5].map(i => ({ key: `k${i}`, namespace: 'n', hasVector: i === 1 }))
+ const state = stateWith({}, { memory: { total: 900, unread: 7, vectors: 1 }, namespaces: { entries, byName: [], sampled: 5 } })
+ const found = ids(state)
+
+ expect(found).toEqual(expect.arrayContaining(['memory-vectors', 'memory-second-store', 'memory-size']))
+ expect(found).not.toContain('memory-unchecked')
+ expect(diagnose(state, NOW, NOW - 1_000).find(finding => finding.id === 'memory-vectors')?.metric).toBe('vectors 1/5')
+ })
+
+ it('alerts the console already raises become findings, worst first, and the safe scope offers only the safe fixes', () => {
+ const state = stateWith({ claims: [{ issueId: 'X-1', status: 'active', claimant: { id: 'a1', agentType: 'coder' }, expiresAtMs: NOW - 1_000, claimedAtMs: NOW - 5_000 }] })
+ const found = diagnose(state, NOW, NOW - 1_000)
+
+ expect(found[0]?.level).toBe('bad')
+ expect(found[0]?.id).toBe('alert-expired-X-1')
+
+ const empty = diagnose(stateWith({}), NOW, NOW).find(finding => finding.id === 'learning-empty')
+
+ expect(offered(empty as never, 'safe').map(item => item.id)).toEqual(['nn-pretrain-shallow'])
+ expect(offered(empty as never, 'balanced').map(item => item.id)).toEqual(['nn-pretrain-shallow', 'nn-pretrain-medium', 'nn-train-coordination-10'])
+ })
+
+ it('every fix is a real palette entry, so no button is dead', () => {
+ const entries = [1, 2, 3, 4, 5].map(i => ({ key: `k${i}`, namespace: 'n', hasVector: false }))
+ const state = stateWith({ outcomes: { total: 20, successes: 5, points: [] } }, { memory: { total: 900, unread: 3 }, namespaces: { entries, byName: [], sampled: 5 } })
+ const known = new Set(paletteEntries(state, NOW).map(entry => entry.id))
+ const missing = diagnose(state, NOW, NOW).flatMap(finding => finding.fixes.map(item => item.id)).filter(id => !known.has(id))
+
+ expect([...new Set(missing)]).toEqual([])
+ })
+
+ it('pressing a fix remembers the metric before and runs that entry; an unknown fix runs nothing; ask words the finding', () => {
+ const state = stateWith({})
+ const ran: string[] = []
+ const asked: string[] = []
+ const actions = optimizerActions(state, () => undefined, id => void ran.push(id), question => void asked.push(question))
+
+ actions.fix('learning-empty', 'nn-pretrain-shallow')
+ expect(ran).toEqual(['nn-pretrain-shallow'])
+ expect(optimizerOf(state).before.get('learning-empty')).toBe('patterns n/a')
+ expect(optimizerOf(state).ran.get('learning-empty')).toBe('nn-pretrain-shallow')
+ actions.fix('learning-empty', 'rm-everything')
+ actions.fix('no-such-finding', 'nn-pretrain-shallow')
+ expect(ran).toHaveLength(1)
+ actions.ask('learning-empty')
+ expect(asked[0]).toContain('ruflo has learned nothing here yet')
+ actions.scope('deep')
+ expect(optimizerOf(state).scope).toBe('deep')
+ })
+})
diff --git a/plugins/ruflo-console/tests/optimizer.test.ts b/plugins/ruflo-console/tests/optimizer.test.ts
new file mode 100644
index 0000000000..7cfea92449
--- /dev/null
+++ b/plugins/ruflo-console/tests/optimizer.test.ts
@@ -0,0 +1,58 @@
+/**
+ * The Optimizer in the Overview page: findings with a scope that limits the fixes offered, and a fix whose confirm opens right under
+ * the finding that raised it, before anything runs.
+ */
+import type { TestBody } from 'claude-code/testing'
+import { describe, expect, mock, test } from 'claude-code/testing'
+
+import { RUFLO_FILES } from './fixtures/ruflo-run'
+import { command, elementsOf, keyOf, paneAt, PLUGIN, SESSION, textOf, worldOf } from './fixtures/world'
+
+type Body = Parameters<TestBody>
+
+const keys = (tree: Parameters<typeof elementsOf>[0]) => elementsOf(tree, 'Button').map(keyOf)
+
+async function opened($: Body[0], on: Body[1]) {
+ const world = worldOf(on, RUFLO_FILES)
+
+ mock.clock(on)
+ await $.session.start(SESSION)
+ await $.command.run(command('overview'))
+
+ const pane = await $.ui.mount({ ...paneAt(150), surface: 'terminal' as const, plugin: PLUGIN })
+
+ await pane.drawn()
+
+ return { world, pane }
+}
+
+describe('optimizer', () => {
+ test('the Overview opens with an Optimizer: findings, the scope chips, and only the safe fixes at first', { options: { boot: false } }, async ($, on) => {
+ const { pane } = await opened($, on)
+ const tree = await pane.drawn()
+ const order = keys(tree)
+
+ expect(textOf(tree)).toContain('OPTIMIZER')
+ expect(textOf(tree)).toMatch(/\d+ findings?/)
+ expect(order).toEqual(expect.arrayContaining(['opt-scope-safe', 'opt-scope-balanced', 'opt-scope-deep', 'opt-ask-performance-unprofiled']))
+ expect(order).not.toContain('opt-fix-performance-unprofiled-perf-optimize')
+ await pane.press({ key: 'opt-scope-balanced' })
+ expect(keys(await pane.drawn())).toContain('opt-fix-performance-unprofiled-perf-optimize')
+ await pane.unmount()
+ })
+
+ test('a fix asks first, and its confirm sits right under the finding that raised it; nothing runs until yes', { options: { boot: false } }, async ($, on) => {
+ const { world, pane } = await opened($, on)
+
+ await pane.press({ key: 'opt-scope-balanced' })
+ await pane.press({ key: 'opt-fix-performance-unprofiled-perf-optimize' })
+
+ const asked = await pane.drawn()
+ const order = keys(asked)
+
+ expect(textOf(asked)).toContain('CONFIRM NEEDED')
+ expect(order.indexOf('confirm')).toBe(order.indexOf('opt-ask-performance-unprofiled') + 1)
+ expect(world.runs.filter(argv => argv.includes('optimize') || argv.includes('performance_optimize'))).toEqual([])
+ await pane.unmount()
+ })
+})
diff --git a/scripts/ci-test-baseline.txt b/scripts/ci-test-baseline.txt
index 72c6395d9b..9723de0a8e 100644
--- a/scripts/ci-test-baseline.txt
+++ b/scripts/ci-test-baseline.txt
@@ -166,6 +166,7 @@ plugins/ruflo-console/tests/views.test.ts
plugins/ruflo-console/tests/labs.test.ts
plugins/ruflo-console/tests/attention.test.ts
plugins/ruflo-console/tests/matrix.test.ts
+plugins/ruflo-console/tests/optimizer.test.ts
plugins/ruflo-console/tests/missions.test.ts
plugins/ruflo-console/tests/settings.test.ts
plugins/ruflo-console/tests/plugin-catalog.test.ts
diff --git a/v3/docs/adr/ADR-408-ruflo-console-mission-control.md b/v3/docs/adr/ADR-408-ruflo-console-mission-control.md
index 2800ecfc62..fef978c793 100644
--- a/v3/docs/adr/ADR-408-ruflo-console-mission-control.md
+++ b/v3/docs/adr/ADR-408-ruflo-console-mission-control.md
@@ -84,3 +84,14 @@ Memory Lab's rule is now the console's, with no per-view code (`views/attention.
## 11. Answers open where they were asked (0.13.1)
Memory Lab no longer keeps one Result block far from what was clicked. Each action records where it was raised (`memoryLab.origin`: Browse, Search, Entry, or a lab group) and its confirm (scope `mem:<area>`) and its result are drawn in a bordered panel directly under that area; the pane no longer draws that confirm at the top (`confirmInline`). An area with nothing asked or answered draws no panel. The lab groups are collapsible sections; the group of the last action stays open.
+
+## 14. The ruflo Optimizer (0.17.0)
+
+A section at the top of the Overview (`hooks/optimizer.ts`, `views/optimizer.ts`): what is wrong or thin in this project, and a fix for each that is one confirm-gated button.
+
+- **Findings** come only from what the console already measured, worst first: ruflo has learned nothing here yet (no patterns), the router missing too often (under 60% of 10 or more routed outcomes), no model-router state; memory not checked this session, many memories with no vector (under 60% of the newest listed), a second memory store outside the counts, a store large enough to compact; where the time goes not measured; every alert the console already raises (stalled agent, expired claim, stale marketplace, daemon stopped, mods not seated, budget); and the full health check. An unread store is a finding to check, never a verdict.
+- **Fixes are existing palette entries**, so the Optimizer adds no new way to write: pretrain at shallow or medium depth, train, quantize, consolidate, compress, plan a cleanup, initialise embeddings, rebuild the RaBitQ index, optimise, doctor with and without `--fix`. Each asks first (a read runs at once) and says what it does. A test fails if a fix names an entry the palette does not have.
+- **Scope** limits which fixes are offered: *safe* (reads and light upkeep), *balanced* (local compute that writes ruflo's own stores), *deep* (heavier rebuilds, and anything that may fetch a model).
+- **Before and after:** pressing a fix remembers the finding's metric (`vectors 1/5`, `patterns n/a`); the line under the finding reads before → now and says when the finding is gone. **✦ ask Claude** words the finding and sends it to the main Claude UI (it asks first).
+- **Answers** open under the fix button pressed (the attention panel, section 11a): the confirm, then the result lines of the command that ran, with the Overview's own result block as the fallback.
+- Tests: `tests/optimizer.spec.ts` (what is found, scopes, every fix a real palette entry, before/after), `tests/optimizer.test.ts` (the section in the Overview; a fix's confirm sits under its finding; nothing runs before yes).