mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-25 14:43:05 +09:00
fix(ruflo-console): fixes from the live run
- name the ruflo MCP servers and their tool count (two servers expose the same tools, so a bare count overstated it); recount every 30 s, since Claude Code connects MCP servers after session start - back off re-stating a missing file for 10 s (explicit refresh and the post-action read skip the backoff), so a closed console stops logging ENOENT every 3 s - tab and footer buttons get a gap; any view switch leaves the help page - pulses are two dots wide, so one on a vertical edge stands out of it Co-Authored-By: RuFlo <ruv@ruv.net>
This commit is contained in:
1 parent
6eb25a823c
commit
7dcea3a02e
9 files changed
+67
-23
No files matched your search
@@ -19,6 +19,7 @@ const PENDING_TTL_MS = 30_000
|
||||
const MAX_PARALLEL_PROBES = 2
|
||||
const BAR_FRESH_MS = 10_000
|
||||
const IDLE_REFRESH_MS = 30_000
|
||||
const TOOLS_RECOUNT_MS = 30_000
|
||||
|
||||
export type Controller = {
|
||||
refresh: () => Promise<void>
|
||||
@@ -57,6 +58,7 @@ export function createController(state: State, host: Host): Controller {
|
||||
let lastSegment: string | null | undefined
|
||||
let lastSpend: number | undefined
|
||||
let hasDrawn = false
|
||||
let toolsCountedAt = 0
|
||||
const lastAttempt = new Map<string, number>()
|
||||
|
||||
const persist = () => void host.storeSet(storeKeyOf(state.cwd), { view: state.view }).catch(() => undefined)
|
||||
@@ -76,6 +78,12 @@ export function createController(state: State, host: Host): Controller {
|
||||
/** A read that starts after this call: what an action checks, since a read already running may predate its write. */
|
||||
async function freshRead(): Promise<void> {
|
||||
await inflight?.catch(() => undefined)
|
||||
|
||||
// A file the action just created must not wait out the missing-file backoff.
|
||||
for (const [path, held] of state.cache) {
|
||||
if ('missingUntilMs' in held) state.cache.delete(path)
|
||||
}
|
||||
|
||||
await refresh()
|
||||
}
|
||||
|
||||
@@ -85,6 +93,12 @@ export function createController(state: State, host: Host): Controller {
|
||||
const started = Date.now()
|
||||
|
||||
try {
|
||||
// Claude Code connects MCP servers after the session starts: count the ruflo tools again now and then.
|
||||
if (Date.now() - toolsCountedAt >= TOOLS_RECOUNT_MS) {
|
||||
toolsCountedAt = Date.now()
|
||||
void host.rufloTools().then(counted => void (state.rufloTools = counted), () => undefined)
|
||||
}
|
||||
|
||||
const [settings, usage, snapshot, route] = await Promise.all([
|
||||
host.settings().catch(() => null),
|
||||
host.usage().catch(() => null),
|
||||
@@ -285,9 +299,10 @@ export function createController(state: State, host: Host): Controller {
|
||||
}
|
||||
|
||||
function setView(view: State['view']): void {
|
||||
state.isHelp = false
|
||||
|
||||
if (view !== state.view) {
|
||||
state.view = view
|
||||
state.isHelp = false
|
||||
state.mounted.clear()
|
||||
persist()
|
||||
// A new view asks for its own height inline; the dock ignores it.
|
||||
@@ -351,7 +366,7 @@ export function createController(state: State, host: Host): Controller {
|
||||
|
||||
const actions: Actions = {
|
||||
view: setView,
|
||||
refresh: () => void refresh().then(() => probe(true)),
|
||||
refresh: () => void freshRead().then(() => probe(true)),
|
||||
help: () => {
|
||||
state.isHelp = !state.isHelp
|
||||
host.invalidate()
|
||||
|
||||
@@ -51,16 +51,25 @@ export const NOSTR_KEY = '.ruflo/nostr.key'
|
||||
export type Read = { text: string; mtimeMs: number } | { text: null; reason: 'missing' | 'too-large' | 'refused'; size?: number }
|
||||
|
||||
/** The text of each file as last read, by path, with the mtime and size it was read at. */
|
||||
export type ReadCache = Map<string, { mtimeMs: number; size: number; text: string }>
|
||||
export type ReadCache = Map<string, { mtimeMs: number; size: number; text: string } | { missingUntilMs: number }>
|
||||
|
||||
/** A path found missing is not stat-ed again for this long: a file ruflo creates shows up within it. */
|
||||
export const MISSING_RECHECK_MS = 10_000
|
||||
|
||||
/** Reads one file, unless its mtime and size match what was read last; stats first, so a huge file is never read. */
|
||||
export async function readBounded(fs: ReaderFs, cache: ReadCache, path: string): Promise<Read> {
|
||||
let stat: { mtimeMs?: number; size?: number } | undefined
|
||||
|
||||
const before = cache.get(path)
|
||||
|
||||
if (before !== undefined && 'missingUntilMs' in before && before.missingUntilMs > Date.now()) {
|
||||
return { text: null, reason: 'missing' }
|
||||
}
|
||||
|
||||
try {
|
||||
stat = await fs.stat(path)
|
||||
} catch {
|
||||
cache.delete(path)
|
||||
cache.set(path, { missingUntilMs: Date.now() + MISSING_RECHECK_MS })
|
||||
|
||||
return { text: null, reason: 'missing' }
|
||||
}
|
||||
@@ -74,7 +83,7 @@ export async function readBounded(fs: ReaderFs, cache: ReadCache, path: string):
|
||||
return { text: null, reason: 'too-large', size }
|
||||
}
|
||||
|
||||
const held = cache.get(path)
|
||||
const held = before !== undefined && 'text' in before ? before : undefined
|
||||
|
||||
if (held !== undefined && mtimeMs >= 0 && held.mtimeMs === mtimeMs && held.size === size) {
|
||||
return { text: held.text, mtimeMs }
|
||||
@@ -101,7 +110,8 @@ export type DiskRead = { project: Record<ProjectKey, Read>; home: Record<keyof t
|
||||
|
||||
/** Reads every file in parallel; nothing here rejects. `home` is null when the home directory is unknown. */
|
||||
export async function readDisk(fs: ReaderFs, cache: ReadCache, cwd: string, home: string | null): Promise<DiskRead> {
|
||||
const before = new Map([...cache].map(([path, held]) => [path, held.mtimeMs]))
|
||||
const mtimeOf = (held: ReadCache extends Map<string, infer V> ? V : never) => ('mtimeMs' in held ? held.mtimeMs : -1)
|
||||
const before = new Map([...cache].map(([path, held]) => [path, mtimeOf(held)]))
|
||||
const projectKeys = Object.keys(PROJECT) as ProjectKey[]
|
||||
const homeKeys = Object.keys(HOME) as (keyof typeof HOME)[]
|
||||
const missingHome: Read = { text: null, reason: 'missing' }
|
||||
@@ -119,7 +129,7 @@ export async function readDisk(fs: ReaderFs, cache: ReadCache, cwd: string, home
|
||||
let changed = 0
|
||||
|
||||
for (const [path, held] of cache) {
|
||||
if (before.get(path) !== held.mtimeMs) {
|
||||
if ('mtimeMs' in held && before.get(path) !== held.mtimeMs) {
|
||||
changed += 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,12 @@ export function topologyPicture(model: TopoModel, columns: number, rows: number,
|
||||
for (const lag of [0, 0.5]) {
|
||||
const k = (((t / 1400 + i * 0.13 + lag) % 1) + 1) % 1
|
||||
|
||||
canvas.dot(p.x + (q.x - p.x) * k, p.y + (q.y - p.y) * k, COLOR.warn)
|
||||
const x = p.x + (q.x - p.x) * k
|
||||
const y = p.y + (q.y - p.y) * k
|
||||
|
||||
// Two dots wide, so a pulse on a vertical edge stands out of the line rather than sitting on its dots.
|
||||
canvas.dot(x, y, COLOR.warn)
|
||||
canvas.dot(x + 1, y, COLOR.warn)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ export type Host = {
|
||||
registerCommand: (spec: CommandSpec) => Promise<unknown>
|
||||
run: (argv: readonly string[], timeoutMs: number) => Promise<ProcessRunResult>
|
||||
usage: () => Promise<{ costUsd?: number; contextPercent?: number }>
|
||||
/** How many ruflo / claude-flow MCP tools the model can call now. */
|
||||
rufloTools: () => Promise<number>
|
||||
/** The ruflo / claude-flow MCP tools the model can call now, and the servers they come from. */
|
||||
rufloTools: () => Promise<{ tools: number; servers: string[] }>
|
||||
settings: () => Promise<unknown>
|
||||
home: () => Promise<string | undefined>
|
||||
rufloSnapshot: () => Promise<RufloSnapshot>
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { Kit } from './views/common'
|
||||
import { picturesOf } from './views/frames'
|
||||
import { NARROW, paneView } from './views/pane'
|
||||
|
||||
const RUFLO_TOOL = /^mcp__(?:claude-flow|ruflo|plugin_ruflo[\w-]*)__/
|
||||
const RUFLO_TOOL = /^mcp__(claude-flow|ruflo|plugin_ruflo[\w-]*)__/
|
||||
|
||||
/**
|
||||
* Binds a Host from `$`, every member spelled `$.noun.method(...)` here and nowhere else, so the engine reads what
|
||||
@@ -45,7 +45,11 @@ function hostOf($: EngineInterface, cwd: string): Host {
|
||||
|
||||
return { ...(usage.cost?.usd !== undefined && { costUsd: usage.cost.usd }), ...(usage.context?.percent !== undefined && { contextPercent: usage.context.percent }) }
|
||||
},
|
||||
rufloTools: async () => (await $.tool.list()).filter(tool => RUFLO_TOOL.test(tool.name)).length,
|
||||
rufloTools: async () => {
|
||||
const names = (await $.tool.list()).flatMap(tool => RUFLO_TOOL.exec(tool.name)?.slice(1, 2) ?? [])
|
||||
|
||||
return { tools: names.length, servers: [...new Set(names)].sort() }
|
||||
},
|
||||
settings: async () => $.settings.read(),
|
||||
home: async () => $.env.get('HOME'),
|
||||
// `$.ruflo` exists only where ruflo-mods is seated; validate refuses feature-detecting a noun, so these are
|
||||
@@ -85,7 +89,7 @@ export const register: Register = (on, raw: PluginOptions) => {
|
||||
await Promise.all([
|
||||
bound.registerCommand({ name: 'ruflo-console', description: 'ruflo console: swarms, claims, federation, plugins, learning, MetaHarness, memory', argumentHint: '[view|close|status]' }).catch(() => undefined),
|
||||
bound.storeGet(storeKeyOf(e.cwd)).then(value => restore(state, value), () => undefined),
|
||||
bound.rufloTools().then(n => void (state.rufloTools = n), () => undefined),
|
||||
bound.rufloTools().then(counted => void (state.rufloTools = counted), () => undefined),
|
||||
])
|
||||
control.start()
|
||||
void control.refresh()
|
||||
|
||||
@@ -93,7 +93,7 @@ export type State = {
|
||||
probes: Map<string, ProbeResult>
|
||||
ruflo: { snapshot: RufloSnapshot | null; route: RufloRoute | null; error: string | null }
|
||||
usage: { costUsd?: number; contextPercent?: number } | null
|
||||
rufloTools: number | null
|
||||
rufloTools: { tools: number; servers: string[] } | null
|
||||
mods: ModSeen[]
|
||||
/** Tool calls the console saw, per 5 s bucket, newest last: a measured series. */
|
||||
activity: number[]
|
||||
|
||||
@@ -36,7 +36,16 @@ export function overviewView(ctx: Ctx): RenderElement {
|
||||
daemon?.running === true ? THEME.ok : undefined,
|
||||
),
|
||||
)
|
||||
rows.push(kv(ctx, 'MCP tools', state.rufloTools === null ? 'n/a' : state.rufloTools > 0 ? `${state.rufloTools} ruflo tools callable now (Claude Code's tool list)` : 'none connected in this session', state.rufloTools !== null && state.rufloTools > 0 ? THEME.ok : undefined))
|
||||
const mcp = state.rufloTools
|
||||
|
||||
rows.push(
|
||||
kv(
|
||||
ctx,
|
||||
'MCP',
|
||||
mcp === null ? 'n/a' : mcp.tools > 0 ? `${mcp.servers.length} ruflo server${mcp.servers.length === 1 ? '' : 's'} connected (${mcp.servers.join(', ')}) · ${mcp.tools} tools callable now` : 'no ruflo MCP server connected in this session',
|
||||
mcp !== null && mcp.tools > 0 ? THEME.ok : undefined,
|
||||
),
|
||||
)
|
||||
rows.push(kv(ctx, 'memory DB', memory !== null ? `${count(memory.total)} entries · ${count(memory.vectors)} vectors · ${memory.backend}${memory.storage !== undefined ? ` · ${memory.storage}` : ''}` : sourceLine(state.probes.get('memory'), nowMs, 'n/a').text))
|
||||
rows.push(
|
||||
kv(
|
||||
|
||||
@@ -29,7 +29,7 @@ const BODIES = {
|
||||
} as const
|
||||
|
||||
function tabs(ctx: Ctx): RenderElement {
|
||||
const isShort = ctx.columns < 104
|
||||
const isShort = ctx.columns < 100
|
||||
|
||||
if (ctx.columns < NARROW) {
|
||||
const index = VIEWS.findIndex(view => view.id === ctx.state.view)
|
||||
@@ -37,16 +37,17 @@ function tabs(ctx: Ctx): RenderElement {
|
||||
return text(ctx, `${index + 1}/${VIEWS.length} ${VIEWS[index]?.label ?? ''} · 1-8 switch · h help`, { bold: true, color: THEME.head })
|
||||
}
|
||||
|
||||
return row(
|
||||
ctx,
|
||||
VIEWS.map(view => {
|
||||
return ctx.kit.Box({
|
||||
flexDirection: 'row',
|
||||
gap: 1,
|
||||
key: 'tabs',
|
||||
children: VIEWS.map(view => {
|
||||
const isCurrent = view.id === ctx.state.view
|
||||
const label = isShort ? view.label.slice(0, view.id === 'metaharness' ? 4 : 5) : view.label
|
||||
|
||||
return ctx.kit.Button({ key: `tab-${view.id}`, label: isCurrent ? `${label}◂` : label, hotkey: view.key, plain: true, ...(isCurrent ? {} : { dimColor: true }), onPress: () => ctx.act.view(view.id) })
|
||||
}),
|
||||
'tabs',
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function help(ctx: Ctx): RenderElement {
|
||||
@@ -102,7 +103,7 @@ function footer(ctx: Ctx): RenderElement {
|
||||
|
||||
parts.push(
|
||||
row(ctx, [
|
||||
text(ctx, clip(`${read} · ${keys}`, Math.max(10, ctx.columns - 24)), { dimColor: true }),
|
||||
text(ctx, `${clip(`${read} · ${keys}`, Math.max(10, ctx.columns - 34))} `, { dimColor: true }),
|
||||
...(ctx.columns >= NARROW ? [button(ctx, 'refresh', 'Refresh', ctx.act.refresh, { hotkey: 'r' }), button(ctx, 'help', 'Help', ctx.act.help, { hotkey: 'h' }), button(ctx, 'close', 'Close', ctx.act.close, { hotkey: 'x' })] : []),
|
||||
]),
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('views', () => {
|
||||
|
||||
expect(text).toContain('v3.50.0 (npx-offline)')
|
||||
expect(text).toContain('running per daemon-state.json')
|
||||
expect(text).toContain('2 ruflo tools callable now')
|
||||
expect(text).toContain('1 ruflo server connected (claude-flow) · 2 tools callable now')
|
||||
expect(text).toContain('1 entries')
|
||||
expect(text).toContain('manifest v3.32.24')
|
||||
expect(text).toContain('signature not checked here')
|
||||
|
||||
Reference in new issue
Block a user