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

fix(console): sanitize router text, never clip pipeline stages on narrow panes (ADR-455)

ruv585ec22b0701
diff --git a/plugins/ruflo-console/hooks/data/pipeline.ts b/plugins/ruflo-console/hooks/data/pipeline.ts
index 284fd766bb..365c188aaf 100644
--- a/plugins/ruflo-console/hooks/data/pipeline.ts
+++ b/plugins/ruflo-console/hooks/data/pipeline.ts
@@ -59,6 +59,9 @@ export type RouteModel = { owner: RouteOwner; source: RouteSource; candidates: R
/** Who routes in this project: the classic hook-handler, the mod, or nobody known (ruflo-mods not seated). */
export const routeOwnerOf = (seated: boolean, classicOwnsRoute: boolean): RouteOwner => (!seated ? 'unseated' : classicOwnsRoute ? 'classic' : 'mods')
+/** The router's text is untrusted: control characters never reach a cell. */
+// eslint-disable-next-line no-control-regex
+const plain = (text: string): string => text.replace(/[\u0000-\u001f\u007f-\u009f]/g, '')
const clamp01 = (value: number): number => (Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : 0)
const percent = (text: string | undefined): number | null => (text === undefined ? null : clamp01(Number(text) / 100))
@@ -71,13 +74,13 @@ export function candidatesFromLines(lines: readonly string[]): RouteCandidate[]
if (first === null) return []
- const out: RouteCandidate[] = [{ agent: first[1] as string, confidence: percent(first[2]) }]
+ const out: RouteCandidate[] = [{ agent: plain(first[1] as string), confidence: percent(first[2]) }]
for (let i = 1; i < lines.length && out.length < MAX_CANDIDATES; i++) {
const line = lines[i] as string
const alt = /^\s+or (\S+)(?: · (\d{1,3})%)?/.exec(line)
- if (alt !== null) out.push({ agent: alt[1] as string, confidence: percent(alt[2]) })
+ if (alt !== null) out.push({ agent: plain(alt[1] as string), confidence: percent(alt[2]) })
}
return out
@@ -96,7 +99,7 @@ export function routeModelOf(input: {
const owner = routeOwnerOf(input.seated, input.classicOwnsRoute)
const asked = input.lab?.id === 'nn-route' ? candidatesFromLines(input.lab.lines) : []
- if (input.lab !== null && asked.length > 0) return { owner, source: 'router-query', candidates: asked, matched: null, reason: null, asked: input.lab.label }
+ if (input.lab !== null && asked.length > 0) return { owner, source: 'router-query', candidates: asked, matched: null, reason: null, asked: plain(input.lab.label) }
if (input.route !== null) return { owner, source: 'mods', candidates: [{ agent: input.route.agent, confidence: clamp01(input.route.confidence) }], matched: input.route.matched, reason: input.route.reason, asked: null }
return { owner, source: 'none', candidates: [], matched: null, reason: null, asked: null }
diff --git a/plugins/ruflo-console/hooks/gfx/pipeline.ts b/plugins/ruflo-console/hooks/gfx/pipeline.ts
index 7ee0fc97cb..02b71273b4 100644
--- a/plugins/ruflo-console/hooks/gfx/pipeline.ts
+++ b/plugins/ruflo-console/hooks/gfx/pipeline.ts
@@ -10,12 +10,32 @@ export const PIPELINE_ROWS = 5
const compact = (count: number): string => (count >= 10_000 ? `${(count / 1000).toFixed(1)}k` : String(count))
+/** CONSOLIDATE (11) plus the box edges: the widest name, so no stage name is ever cut. */
+const MIN_BOX = 13
+
+/** The narrow form: `NAME count · age` per stage, dim where the stage is stale or absent. */
+function stackedList(stages: readonly PipeStage[], columns: number): Grid {
+ const grid = new Grid(columns, Math.max(1, stages.length))
+
+ stages.forEach((stage, y) => {
+ const count = stage.count === null ? 'n/a' : compact(stage.count)
+
+ grid.text(0, y, `${stage.name} ${count} · ${stageNote(stage)}`, stage.state === 'live' ? COLOR.accent : stage.state === 'stale' ? COLOR.warn : COLOR.dim)
+ })
+
+ return grid
+}
+
/** RETRIEVE → JUDGE → DISTILL → CONSOLIDATE: a box per stage with its count and how old its source is; stale and absent stages dim. */
export function pipelineDiagram(stages: readonly PipeStage[], columns: number): Grid {
- const grid = new Grid(columns, PIPELINE_ROWS)
const n = Math.max(1, stages.length)
- const gap = columns >= 41 ? 3 : 1
- const box = Math.max(4, Math.floor((columns - (n - 1) * gap) / n))
+ const gap = columns >= 56 ? 3 : 1
+ const box = Math.floor((columns - (n - 1) * gap) / n)
+
+ // Too narrow for four boxes that keep every name, count and age whole: one line per stage, never a clipped number.
+ if (box < MIN_BOX) return stackedList(stages, columns)
+
+ const grid = new Grid(columns, PIPELINE_ROWS)
const inner = box - 2
const cell = (text: string): string => text.slice(0, inner).padEnd(inner)
@@ -73,7 +93,7 @@ export function routePicture(model: RouteModel, columns: number): Grid {
const source =
model.source === 'router-query'
- ? `from your route query ${model.asked ?? ''} · a prior, not a calibrated probability`
+ ? `a prior, not a calibrated probability · from your route query ${model.asked ?? ''}`
: model.source === 'mods'
? `${model.matched === true ? 'keyword match' : 'no match, default'} · only the winner is stored; runners-up need a route query`
: 'run a route query in the Learning Lab to see candidates'
diff --git a/plugins/ruflo-console/tests/pipeline.spec.ts b/plugins/ruflo-console/tests/pipeline.spec.ts
index b24579bf10..a98b75c7de 100644
--- a/plugins/ruflo-console/tests/pipeline.spec.ts
+++ b/plugins/ruflo-console/tests/pipeline.spec.ts
@@ -56,6 +56,17 @@ describe('the pipeline diagram', () => {
expect(fg(grid, at('JUDGE') - 1, 0)).toBe(COLOR.dim)
})
+ it('never clips a name, count or age: a narrow pane stacks one line per stage', () => {
+ const grid = pipelineDiagram(stages, 40)
+
+ expect(grid.columns).toBe(40)
+ expect(grid.rows).toBe(4)
+ expect(rowText(grid, 0)).toContain('RETRIEVE 32.3k · 1h ago')
+ expect(rowText(grid, 1)).toContain('JUDGE 9 · stale 9d')
+ expect(rowText(grid, 3)).toContain('CONSOLIDATE n/a · no data')
+ expect(rowText(pipelineDiagram(stages, 80), 1)).toContain('CONSOLIDATE')
+ })
+
it('keeps its size on a narrow pane', () => {
const grid = pipelineDiagram(stages, 24)
@@ -91,6 +102,12 @@ describe('the route model', () => {
expect(found.map(c => c.agent)).toEqual(['a', 'r0', 'r1', 'r2', 'r3'])
})
+ it('strips control characters from router text before it reaches a cell', () => {
+ const [pick] = candidatesFromLines(['→ co\u001b[2Jder · 50%'])
+
+ expect(pick?.agent).toBe('co[2Jder')
+ })
+
it('prefers a route query with candidates, else the mod pick, else says none', () => {
const lab = { id: 'nn-route', label: 'which agent for "fix"', lines: ['→ coder · 80%', ' or tester · 10%'] }