π 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
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(ruflo-console): results read markdown as text: pipe tables drawn aligned, headings, bullets, bold, code and links tidied
ruv6fd0a78c231f
diff --git a/plugins/ruflo-console/hooks/result-lines.ts b/plugins/ruflo-console/hooks/result-lines.tsindex 314f75e7c8..d3e665973b 100644--- a/plugins/ruflo-console/hooks/result-lines.ts+++ b/plugins/ruflo-console/hooks/result-lines.ts@@ -5,19 +5,32 @@* removed and runs of blank lines collapsed to one. Pure, bounded, and it never invents text: a block it cannot read as a table stays as it was.*/-const RULE = /^\s*\+[-=+]{2,}\+\s*$/+/** A table rule: the CLI's `+----+----+`, or a markdown separator row `| --- | :---: |`. */+const RULE = /^\s*(?:\+[-=+]{2,}\+|\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)+\|?)\s*$/const ROW = /^\s*\|.*\|\s*$//** The widest a column is drawn; a longer cell is cut with an ellipsis. */const MAX_CELL = 48/** The most table lines read as one block (a runaway block stays as plain lines). */const MAX_BLOCK = 200-const cellsOf = (line: string): string[] => line.trim().slice(1, -1).split('|').map(cell => cell.trim())+/**+ * Markdown inside a line, read as text: `**bold**`, `__bold__` and `code` lose their markers, `[text](url)` reads `text (url)`. Single `*` and `_` are+ * left alone (a product like 5 * 3, snake_case), and a marker with no partner is left as it is.+ */+export function plainMarkdown(line: string): string {+ return line+ .replace(/\*\*([^*\n]+?)\*\*/g, '$1')+ .replace(/__([^_\n]+?)__/g, '$1')+ .replace(/`([^`\n]+?)`/g, '$1')+ .replace(/\[([^\]\n]+)\]\((https?:\/\/[^)\s]+)\)/g, '$1 ($2)')+}++const cellsOf = (line: string): string[] => line.trim().slice(1, -1).split('|').map(cell => plainMarkdown(cell.trim()))const cut = (cell: string): string => (cell.length > MAX_CELL ? `${cell.slice(0, MAX_CELL - 1)}β¦` : cell)/** One table block (rules and rows, in order) as box-drawn lines, or null when it is not a rectangular table of at least two rows. */function drawTable(block: readonly string[]): string[] | null {- const rows = block.filter(line => ROW.test(line)).map(cellsOf)+ const rows = block.filter(line => ROW.test(line) && !RULE.test(line)).map(cellsOf)if (rows.length < 2) return null@@ -29,16 +42,33 @@ function drawTable(block: readonly string[]): string[] | null {const rule = (left: string, mid: string, right: string): string => `${left}${widths.map(width => 'β'.repeat(width + 2)).join(mid)}${right}`const draw = (row: readonly string[]): string => `β${row.map((cell, column) => ` ${cut(cell).padEnd(widths[column] ?? 0)} `).join('β')}β`// The first row is the header when a rule sits right under it (the CLI's table shape).- const hasHeader = block.findIndex(line => ROW.test(line)) + 1 < block.length && RULE.test(block[block.findIndex(line => ROW.test(line)) + 1] ?? '')+ const first = block.findIndex(line => ROW.test(line) && !RULE.test(line))+ const hasHeader = first >= 0 && RULE.test(block[first + 1] ?? '')const [head, ...rest] = rowsreturn [rule('β', 'β¬', 'β'), ...(hasHeader && head !== undefined ? [draw(head), rule('β', 'βΌ', 'β€')] : head !== undefined ? [draw(head)] : []), ...rest.map(draw), rule('β', 'β΄', 'β')]}+/** One non-table line: headings read `βΈ Title`, bullets `β’`, quotes `β`, and the inline markers are dropped. */+function textLine(raw: string): string {+ const heading = /^\s{0,3}#{1,6}\s+(.*?)\s*#*\s*$/.exec(raw)++ if (heading !== null) return `βΈ ${plainMarkdown(heading[1] ?? '')}`++ const bullet = /^(\s*)[-*+]\s+(.*)$/.exec(raw)++ if (bullet !== null) return `${bullet[1] ?? ''}β’ ${plainMarkdown(bullet[2] ?? '')}`++ const quote = /^\s*>\s?(.*)$/.exec(raw)++ return quote !== null ? `β ${plainMarkdown(quote[1] ?? '')}` : plainMarkdown(raw)+}+export function prettyLines(lines: readonly string[]): string[] {const out: string[] = []let block: string[] = []let blank = false+ let fenced = falseconst flush = (): void => {if (block.length === 0) return@@ -50,6 +80,18 @@ export function prettyLines(lines: readonly string[]): string[] {}for (const raw of lines) {+ // A fenced code block is shown as it is, minus the fence lines themselves.+ if (/^\s*(```|~~~)/.test(raw)) {+ flush()+ fenced = !fenced+ continue+ }++ if (fenced) {+ out.push(raw.trimEnd())+ continue+ }+if (RULE.test(raw) || ROW.test(raw)) {blank = falseblock.push(raw)@@ -67,7 +109,7 @@ export function prettyLines(lines: readonly string[]): string[] {}blank = false- out.push(line)+ out.push(textLine(line))}flush()diff --git a/plugins/ruflo-console/tests/result-lines.spec.ts b/plugins/ruflo-console/tests/result-lines.spec.tsindex 78cbfb43b6..925014434b 100644--- a/plugins/ruflo-console/tests/result-lines.spec.ts+++ b/plugins/ruflo-console/tests/result-lines.spec.ts@@ -1,7 +1,7 @@/** The result lines are tidied before a view draws them: ASCII tables are drawn again with aligned columns, nothing else is rewritten. */import { describe, expect, it } from 'vitest'-import { prettyLines } from '../hooks/result-lines'+import { plainMarkdown, prettyLines } from '../hooks/result-lines'const PASTED = ['Pattern Optimization (Real)',@@ -61,3 +61,40 @@ describe('prettyLines', () => {for (const line of prettyLines(PASTED).filter(row => row.startsWith('β'))) for (const cell of line.slice(1, -1).split('β').map(part => part.trim())) expect(cells.has(cell), cell).toBe(true)})})++describe('markdown in a result', () => {+ it('draws a markdown pipe table like the CLI one, and reads the markers inside its cells', () => {+ const out = prettyLines(['| Component | Status |', '|---|:---:|', '| **SONA** | `Active` |', '| HNSW | Available |'])++ expect(out[0]).toBe('βββββββββββββ¬ββββββββββββ')+ expect(out[1]).toBe('β Component β Status β')+ expect(out[2]).toBe('βββββββββββββΌββββββββββββ€')+ expect(out[3]).toBe('β SONA β Active β')+ expect(out.at(-1)).toBe('βββββββββββββ΄ββββββββββββ')+ expect(out.join('\n')).not.toMatch(/\*\*|`|:---/)+ })++ it('reads headings, bullets, quotes, bold, code and links as plain text', () => {+ expect(prettyLines(['## Neural status', '', '- **SONA** is `active`', ' * nested [docs](https://example.com/a)', '> a note'])).toEqual([+ 'βΈ Neural status',+ '',+ 'β’ SONA is active',+ ' β’ nested docs (https://example.com/a)',+ 'β a note',+ ])+ })++ it('shows a fenced block as it is, without the fences, and leaves single asterisks and unpaired markers alone', () => {+ expect(prettyLines(['```json', '{ "a": **1** }', '```', 'after'])).toEqual(['{ "a": **1** }', 'after'])+ expect(plainMarkdown('5 * 3 = 15, snake_case, a **dangling')).toBe('5 * 3 = 15, snake_case, a **dangling')+ expect(plainMarkdown('use `npm test` and **always** [x](https://a.b)')).toBe('use npm test and always x (https://a.b)')+ })++ it('keeps a table that mixes both styles apart from the text around it', () => {+ const out = prettyLines(['Result:', '+---+---+', '| a | b |', '+---+---+', '| 1 | 2 |', '+---+---+', '', '**done**'])++ expect(out[0]).toBe('Result:')+ expect(out.filter(line => line.startsWith('β'))).toHaveLength(1)+ expect(out.at(-1)).toBe('done')+ })+})