Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([issue-3282]): clamp Review Hub card bodies to a 3-line plain-text preview

[._.]/ Adam Eivy893e529874c9
diff --git a/client/src/components/ui/CollapsibleText.jsx b/client/src/components/ui/CollapsibleText.jsx
index 755015ad60..0a127aa6c5 100644
--- a/client/src/components/ui/CollapsibleText.jsx
+++ b/client/src/components/ui/CollapsibleText.jsx
@@ -1,8 +1,28 @@
import { useState, useRef, useEffect } from 'react';
import { ChevronDown, ChevronUp } from 'lucide-react';
+// Tailwind scans source for literal class names, so the clamp variants must
+// appear as whole strings — a computed `line-clamp-${lines}` compiles to nothing
+// and the "clamped" preview silently renders full height.
+const CLAMP_CLASS = {
+ 1: 'line-clamp-1',
+ 2: 'line-clamp-2',
+ 3: 'line-clamp-3',
+ 4: 'line-clamp-4',
+ 5: 'line-clamp-5',
+ 6: 'line-clamp-6'
+};
+
/**
- * Long text collapsed to two lines with a Show more / Show less toggle.
+ * Long text collapsed to a few lines with a Show more / Show less toggle.
+ *
+ * `lines` (default 2) picks the clamp depth; only the values in `CLAMP_CLASS`
+ * are supported, since Tailwind needs the literal class name in source.
+ *
+ * `expandedContent` lets a caller swap in richer markup once the user opts in —
+ * e.g. a card that previews arbitrary markdown as flattened plain text (so the
+ * clamp works and foreign headings stay out of the page outline) but renders
+ * the real markdown on expand. When omitted, expanding just unclamps `text`.
*
* The overflow measurement runs against the *clamped* element, so the toggle
* only appears when the text actually spills. It is recomputed on the collapsed
@@ -23,7 +43,14 @@ import { ChevronDown, ChevronUp } from 'lucide-react';
*
* `id` is required: it wires the toggle's `aria-controls` to the text it expands.
*/
-export default function CollapsibleText({ id, text, className = '' }) {
+export default function CollapsibleText({
+ id,
+ text,
+ className = '',
+ lines = 2,
+ expandedContent = null,
+ expandedClassName = ''
+}) {
const [expanded, setExpanded] = useState(false);
const [isOverflowing, setIsOverflowing] = useState(false);
const ref = useRef(null);
@@ -40,15 +67,21 @@ export default function CollapsibleText({ id, text, className = '' }) {
return () => observer.disconnect();
}, [text, expanded]);
+ const clamp = CLAMP_CLASS[lines] || CLAMP_CLASS[2];
+
return (
<>
- <p
- ref={ref}
- id={id}
- className={`whitespace-pre-wrap break-words ${className} ${expanded ? '' : 'line-clamp-2'}`}
- >
- {text}
- </p>
+ {expanded && expandedContent ? (
+ <div id={id} className={`${className} ${expandedClassName}`}>{expandedContent}</div>
+ ) : (
+ <p
+ ref={ref}
+ id={id}
+ className={`whitespace-pre-wrap break-words ${className} ${expanded ? '' : clamp}`}
+ >
+ {text}
+ </p>
+ )}
{(isOverflowing || expanded) && (
<button
type="button"
diff --git a/client/src/components/ui/CollapsibleText.test.jsx b/client/src/components/ui/CollapsibleText.test.jsx
index 259414b1bd..443c2430bb 100644
--- a/client/src/components/ui/CollapsibleText.test.jsx
+++ b/client/src/components/ui/CollapsibleText.test.jsx
@@ -93,4 +93,49 @@ describe('CollapsibleText', () => {
const p = document.getElementById('t5');
expect(p).toHaveClass('text-sm', 'text-gray-500', 'mt-1', 'line-clamp-2');
});
+
+ it('clamps at the requested depth', () => {
+ render(<CollapsibleText id="t8" text="hi" lines={3} />);
+ expect(document.getElementById('t8')).toHaveClass('line-clamp-3');
+ });
+
+ it('falls back to the 2-line clamp for an unsupported depth', () => {
+ // Tailwind only emits the literal class names in CLAMP_CLASS, so an
+ // out-of-range value must degrade to a real clamp rather than to none —
+ // an unclamped "preview" is the exact bug this component exists to prevent.
+ render(<CollapsibleText id="t9" text="hi" lines={99} />);
+ expect(document.getElementById('t9')).toHaveClass('line-clamp-2');
+ });
+
+ it('swaps in expandedContent on expand and restores the plain-text clamp on collapse', () => {
+ forceOverflow();
+ render(
+ <CollapsibleText
+ id="t10"
+ text="flattened preview"
+ lines={3}
+ expandedContent={<h4>Foreign Heading</h4>}
+ expandedClassName="max-h-80 overflow-y-auto"
+ />
+ );
+
+ // Collapsed: plain text only — the rich content (and its heading) is absent
+ // from the document, so it cannot pollute the page outline.
+ expect(document.getElementById('t10')).toHaveClass('line-clamp-3');
+ expect(screen.getByText('flattened preview')).toBeInTheDocument();
+ expect(screen.queryByRole('heading', { name: 'Foreign Heading' })).not.toBeInTheDocument();
+
+ fireEvent.click(screen.getByRole('button', { name: /Show more/ }));
+ expect(screen.getByRole('heading', { name: 'Foreign Heading' })).toBeInTheDocument();
+ expect(screen.queryByText('flattened preview')).not.toBeInTheDocument();
+ // The expanded body keeps the id (so aria-controls still resolves) and is
+ // height-capped so one expanded card can't swallow the list.
+ const expandedBody = document.getElementById('t10');
+ expect(expandedBody).toHaveClass('max-h-80', 'overflow-y-auto');
+ expect(expandedBody).not.toHaveClass('line-clamp-3');
+
+ fireEvent.click(screen.getByRole('button', { name: /Show less/ }));
+ expect(screen.getByText('flattened preview')).toBeInTheDocument();
+ expect(screen.queryByRole('heading', { name: 'Foreign Heading' })).not.toBeInTheDocument();
+ });
});
diff --git a/client/src/pages/Review.jsx b/client/src/pages/Review.jsx
index 3071346f56..ddb112da4e 100644
--- a/client/src/pages/Review.jsx
+++ b/client/src/pages/Review.jsx
@@ -26,8 +26,10 @@ import {
DatabaseBackup
} from 'lucide-react';
import PageSkeleton from '../components/ui/PageSkeleton';
+import CollapsibleText from '../components/ui/CollapsibleText';
import MarkdownOutput from '../components/cos/MarkdownOutput';
import { timeAgo, formatDateTime } from '../utils/formatters';
+import { markdownToPlainText } from '../utils/markdownText';
import { coalesce } from '../utils/coalesce';
import * as api from '../services/api';
import socket from '../services/socket';
@@ -413,6 +415,7 @@ export default function Review() {
key={item.id}
item={item}
config={TYPE_CONFIG[item.type]}
+ idScope="action-queue"
isEditing={editingId === item.id}
onComplete={handleComplete}
onDismiss={handleDismiss}
@@ -481,6 +484,7 @@ export default function Review() {
key={item.id}
item={item}
config={config}
+ idScope={`section-${type}`}
isEditing={editingId === item.id}
onComplete={handleComplete}
onDismiss={handleDismiss}
@@ -680,7 +684,11 @@ function SummaryPill({ icon: Icon, label, value, tone = 'text-white', urgent = f
);
}
-function ReviewItem({ item, config, isEditing, onComplete, onDismiss, onDelete, onStartEdit, onSaveEdit, onCancelEdit, compact = false }) {
+// `idScope` namespaces the body's DOM id. An actionable item renders twice —
+// once in the Action Queue and again (dimmed) in its per-type section — so
+// without a scope both copies would share one id and the disclosure's
+// aria-controls would be ambiguous.
+function ReviewItem({ item, config, idScope, isEditing, onComplete, onDismiss, onDelete, onStartEdit, onSaveEdit, onCancelEdit, compact = false }) {
const [editTitle, setEditTitle] = useState(item.title);
const [editDescription, setEditDescription] = useState(item.description || '');
const isPending = item.status === 'pending';
@@ -738,13 +746,28 @@ function ReviewItem({ item, config, isEditing, onComplete, onDismiss, onDelete,
<>
<div className="flex items-start justify-between gap-3">
<div className="min-w-0">
- <p className={`text-sm font-medium ${isPending ? 'text-white' : 'text-gray-400 line-through'}`}>
+ <p
+ className={`text-sm font-medium break-words line-clamp-2 ${isPending ? 'text-white' : 'text-gray-400 line-through'}`}
+ title={item.title}
+ >
{item.title}
</p>
+ {/* Triage is a scanning task, so the body is a fixed 3-line
+ plain-text preview: the raw markdown for a CoS task prompt
+ or a stack trace runs thousands of words, and rendering it
+ through MarkdownOutput both defeated the clamp (line-clamp
+ doesn't apply across block children) and injected the
+ prompt's own headings into this page's outline. The real
+ markdown renders — height-capped — behind Show more. */}
{item.description && (
- <div className="text-xs text-gray-500 mt-0.5 line-clamp-3">
- <MarkdownOutput content={item.description} />
- </div>
+ <CollapsibleText
+ id={`review-item-body-${idScope}-${item.id}`}
+ lines={3}
+ text={markdownToPlainText(item.description)}
+ className="text-xs text-gray-500 mt-0.5"
+ expandedContent={<MarkdownOutput content={item.description} />}
+ expandedClassName="max-h-80 overflow-y-auto pr-1"
+ />
)}
{item.metadata?.reportUrl && (
<a
diff --git a/client/src/pages/Review.test.jsx b/client/src/pages/Review.test.jsx
new file mode 100644
index 0000000000..48eac41469
--- /dev/null
+++ b/client/src/pages/Review.test.jsx
@@ -0,0 +1,125 @@
+import { describe, it, expect, vi, afterEach } from 'vitest';
+import { fireEvent, render, screen, waitFor } from '@testing-library/react';
+
+// A CoS action body is arbitrary agent-authored markdown — thousands of words,
+// its own heading outline, and raw technical payloads. This is the shape that
+// made the queue unscannable (issue #3282).
+const LONG_BODY = [
+ '## Task Prompt',
+ '',
+ 'Investigate the **failing** request and file a follow-up.',
+ '',
+ '- url: https://example.com/a',
+ '- user-agent: Mozilla/5.0 (X11; Linux x86_64) ExampleBrowser/1.0',
+ '',
+ '### Stack',
+ '',
+ '```',
+ 'TypeError: x is not a function',
+ ' at foo (/app/a.js:1:2)',
+ '```'
+].join('\n');
+
+const ITEM = {
+ id: 'item-1',
+ type: 'alert',
+ status: 'pending',
+ title: 'Client error reported',
+ description: LONG_BODY,
+ createdAt: '2026-08-01T12:00:00.000Z',
+ metadata: {}
+};
+
+vi.mock('../services/api', () => ({
+ getReviewItems: vi.fn(() => Promise.resolve([ITEM])),
+ getReviewBriefing: vi.fn(() => Promise.resolve(null)),
+ getReviewQueue: vi.fn(() => Promise.resolve({ items: [], sources: {} })),
+ createReviewTodo: vi.fn(() => Promise.resolve({})),
+ completeReviewItem: vi.fn(() => Promise.resolve({})),
+ dismissReviewItem: vi.fn(() => Promise.resolve({})),
+ deleteReviewItem: vi.fn(() => Promise.resolve({})),
+ updateReviewItem: vi.fn(() => Promise.resolve({})),
+ bulkUpdateReviewStatus: vi.fn(() => Promise.resolve({})),
+ resolveReviewQueueItem: vi.fn(() => Promise.resolve({})),
+ promoteAskReviewQueueItem: vi.fn(() => Promise.resolve({})),
+ normalizeBrainScanReportPath: vi.fn((p) => p)
+}));
+
+vi.mock('../services/socket', () => ({
+ default: { on: vi.fn(), off: vi.fn(), emit: vi.fn() }
+}));
+
+vi.mock('react-router-dom', () => ({
+ useNavigate: () => vi.fn()
+}));
+
+import Review from './Review';
+
+// jsdom reports 0 for scrollHeight/clientHeight, so nothing measures as
+// overflowing unless we force it.
+const forceOverflow = () =>
+ vi.spyOn(HTMLElement.prototype, 'scrollHeight', 'get').mockReturnValue(500);
+
+afterEach(() => vi.restoreAllMocks());
+
+const actionQueueBody = () => document.getElementById(`review-item-body-action-queue-${ITEM.id}`);
+
+describe('Review Hub queue-card triage (#3282)', () => {
+ it('previews the body as clamped plain text instead of full markdown', async () => {
+ render(<Review />);
+
+ const body = await waitFor(() => {
+ const el = actionQueueBody();
+ expect(el).toBeTruthy();
+ return el;
+ });
+
+ // Three-line clamp on the element that actually carries the text — a clamp
+ // on a wrapper around block-level markdown does not clamp at all.
+ expect(body).toHaveClass('line-clamp-3');
+ // Flattened: heading/list/fence markers stripped, words kept.
+ expect(body.textContent).toContain('Task Prompt');
+ expect(body.textContent).toContain('Investigate the failing request');
+ expect(body.textContent).not.toContain('##');
+ expect(body.textContent).not.toContain('**');
+ // The foreign body contributes no headings to this page's outline.
+ expect(screen.queryByRole('heading', { name: 'Task Prompt' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('heading', { name: 'Stack' })).not.toBeInTheDocument();
+ });
+
+ it('keeps the per-card decisions available without expanding', async () => {
+ render(<Review />);
+ await waitFor(() => expect(actionQueueBody()).toBeTruthy());
+
+ // Accept / Reject / Delete are all reachable on the collapsed card.
+ expect(screen.getAllByTitle('Accept').length).toBeGreaterThan(0);
+ expect(screen.getAllByTitle('Reject').length).toBeGreaterThan(0);
+ expect(screen.getAllByTitle('Delete').length).toBeGreaterThan(0);
+ });
+
+ it('renders the full markdown behind Show more, height-capped', async () => {
+ forceOverflow();
+ render(<Review />);
+ await waitFor(() => expect(actionQueueBody()).toBeTruthy());
+
+ // findAll, not getAll: the overflow measurement lives in a passive effect,
+ // which React may flush a tick after the card itself paints.
+ const toggles = await screen.findAllByRole('button', { name: /Show more/ });
+ const toggle = toggles.find(b => b.getAttribute('aria-controls') === `review-item-body-action-queue-${ITEM.id}`);
+ expect(toggle).toBeTruthy();
+
+ fireEvent.click(toggle);
+
+ expect(screen.getByRole('heading', { name: 'Task Prompt' })).toBeInTheDocument();
+ expect(actionQueueBody()).toHaveClass('max-h-80', 'overflow-y-auto');
+ });
+
+ it('scopes the body id per placement so the duplicate card is not an id collision', async () => {
+ render(<Review />);
+ await waitFor(() => expect(actionQueueBody()).toBeTruthy());
+
+ // The same actionable item renders twice: Action Queue + its Alerts section.
+ expect(document.getElementById(`review-item-body-section-alert-${ITEM.id}`)).toBeTruthy();
+ expect(document.querySelectorAll(`[id="review-item-body-action-queue-${ITEM.id}"]`)).toHaveLength(1);
+ });
+});
diff --git a/client/src/utils/README.md b/client/src/utils/README.md
index d58d05136d..7a41b23f64 100644
--- a/client/src/utils/README.md
+++ b/client/src/utils/README.md
@@ -24,6 +24,7 @@ grep -i "what you want to do" client/src/utils/README.md
|---|---|
| `formatters` | Date/time/duration/byte/word formatters (`formatBytes`, `formatCompactCount`, `timeAgo`, `formatTimecode`, `formatDurationMs`, `formatDateShort`, `parseTimeoutMs`, `formatCooldown`, `parseSizeGb`, `recommendedRamGb`, `nameFromImageFilename`, …) plus timeout-input bounds and `getAppName`. Do not re-define formatters inside components. |
| `cronHelpers` | Cron preset list, `isCronExpression` detection, and `describeCron` human-readable rendering. |
+| `markdownText` | `markdownToPlainText(md)` — flatten markdown source to one plain-text string for a clamped preview: strips heading/list/blockquote/fence markers, unwraps emphasis, inline code and links, images → `[alt]`, collapses blank-line runs. Use whenever a card previews arbitrary agent-authored markdown — `line-clamp-N` does not clamp a subtree of block elements, and foreign `##` headings would otherwise join the page's heading outline. |
| `timeWindow` | Time-of-day window math (`isInTimeWindow`, `timeStringToMinutes`) and morning-layout auto-switch helpers (`pickActiveLayoutId`, `recordManualLayoutPick`). |
| `timezone` | Timezone day-key helpers (`dayKeyInTimezone`, `todayKeyInTimezone`) — browser mirror of the server's `todayInTimezone`, so date-scoped POST surfaces derive "today" in the user's configured timezone and agree with the server (#2681). |
diff --git a/client/src/utils/index.js b/client/src/utils/index.js
index ddc2b1bc68..aa72772623 100644
--- a/client/src/utils/index.js
+++ b/client/src/utils/index.js
@@ -12,6 +12,7 @@
// === Formatting & time ===
export * from './formatters.js';
export * from './cronHelpers.js';
+export * from './markdownText.js';
export * from './timeWindow.js';
export * from './timezone.js';
diff --git a/client/src/utils/markdownText.js b/client/src/utils/markdownText.js
new file mode 100644
index 0000000000..b4a7d8b883
--- /dev/null
+++ b/client/src/utils/markdownText.js
@@ -0,0 +1,52 @@
+// Markdown → plain text, for clamped previews.
+//
+// A queue card's body is arbitrary agent-authored markdown (CoS task prompts,
+// stack traces, error payloads). Rendering it through the markdown renderer in
+// a collapsed card is wrong twice over: `line-clamp-N` does not clamp a subtree
+// of block elements (the `-webkit-box` clamp only applies to the inline content
+// of the element carrying it), so the "preview" prints the whole document; and
+// any `##` heading inside that foreign body joins the page's own heading
+// outline. Flattening to one plain-text string fixes both — the preview clamps,
+// and no foreign structure leaks out. The full markdown is still rendered once
+// the user expands that card.
+//
+// This is a *display* flattener, not a parser: it strips the syntax a reader
+// doesn't need in a three-line preview and keeps the words.
+
+// Fenced code blocks — keep the code, drop the fence lines (and any info string).
+const FENCE_LINE = /^\s*(?:`{3,}|~{3,}).*$/;
+
+/**
+ * Flatten markdown source to a single plain-text string suitable for a clamped
+ * preview. Returns `''` for anything that isn't a non-empty string.
+ */
+export function markdownToPlainText(markdown) {
+ if (typeof markdown !== 'string' || !markdown) return '';
+
+ const lines = markdown
+ .replace(/\r\n?/g, '\n')
+ .replace(/<!--[\s\S]*?-->/g, '') // HTML comments
+ .split('\n')
+ .filter(line => !FENCE_LINE.test(line))
+ .map(line => line
+ .replace(/^\s{0,3}#{1,6}\s+/, '') // ATX heading markers
+ .replace(/^\s{0,3}>\s?/, '') // blockquote markers
+ .replace(/^\s*[-*+]\s+/, '• ') // bullet markers
+ .replace(/^\s*(\d+)[.)]\s+/, '$1. ') // ordered-list markers
+ .replace(/^\s*([-*_])(?:\s*\1){2,}\s*$/, '')); // thematic breaks
+
+ return lines
+ .join('\n')
+ .replace(/!\[([^\]]*)\]\([^)]*\)/g, (_, alt) => (alt ? `[${alt}]` : '[image]'))
+ .replace(/\[([^\]]+)\]\([^)]*\)/g, '$1') // links → their text
+ .replace(/`([^`]*)`/g, '$1') // inline code
+ .replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g, '$2') // bold
+ .replace(/(\*|_)(?=\S)([^*_]*?\S)\1/g, '$2') // italic
+ .replace(/~~(?=\S)([\s\S]*?\S)~~/g, '$1') // strikethrough
+ .replace(/[ \t]+/g, ' ')
+ .replace(/\n{2,}/g, '\n') // collapse blank-line runs
+ .split('\n')
+ .map(line => line.trim())
+ .filter(Boolean)
+ .join('\n');
+}
diff --git a/client/src/utils/markdownText.test.js b/client/src/utils/markdownText.test.js
new file mode 100644
index 0000000000..f3e2349423
--- /dev/null
+++ b/client/src/utils/markdownText.test.js
@@ -0,0 +1,61 @@
+import { describe, it, expect } from 'vitest';
+import { markdownToPlainText } from './markdownText';
+
+describe('markdownToPlainText', () => {
+ it('returns an empty string for non-string / empty input', () => {
+ expect(markdownToPlainText(undefined)).toBe('');
+ expect(markdownToPlainText(null)).toBe('');
+ expect(markdownToPlainText('')).toBe('');
+ expect(markdownToPlainText(42)).toBe('');
+ expect(markdownToPlainText({ text: 'hi' })).toBe('');
+ });
+
+ it('strips heading markers so a foreign body cannot hijack the page outline', () => {
+ expect(markdownToPlainText('## Summary\nBackup failed'))
+ .toBe('Summary\nBackup failed');
+ expect(markdownToPlainText('###### Deep')).toBe('Deep');
+ // Not a heading — no space after the hashes.
+ expect(markdownToPlainText('#hashtag')).toBe('#hashtag');
+ });
+
+ it('unwraps emphasis, inline code, and links to their text', () => {
+ expect(markdownToPlainText('**bold** and *italic* and `code`'))
+ .toBe('bold and italic and code');
+ expect(markdownToPlainText('__bold__ and _italic_ and ~~gone~~'))
+ .toBe('bold and italic and gone');
+ expect(markdownToPlainText('see [the report](/data/reports/x.html)'))
+ .toBe('see the report');
+ });
+
+ it('renders images as a bracketed alt placeholder rather than a URL', () => {
+ expect(markdownToPlainText('![a diagram](/img/x.png)')).toBe('[a diagram]');
+ expect(markdownToPlainText('![](/img/x.png)')).toBe('[image]');
+ });
+
+ it('normalizes list and blockquote markers', () => {
+ expect(markdownToPlainText('- one\n* two\n+ three')).toBe('• one\n• two\n• three');
+ expect(markdownToPlainText('1. first\n2) second')).toBe('1. first\n2. second');
+ expect(markdownToPlainText('> quoted line')).toBe('quoted line');
+ });
+
+ it('drops code fences but keeps the code inside', () => {
+ expect(markdownToPlainText('```js\nconst a = 1;\n```')).toBe('const a = 1;');
+ expect(markdownToPlainText('~~~\nraw\n~~~')).toBe('raw');
+ });
+
+ it('drops thematic breaks and HTML comments', () => {
+ expect(markdownToPlainText('before\n\n---\n\nafter')).toBe('before\nafter');
+ expect(markdownToPlainText('kept <!-- hidden --> text')).toBe('kept text');
+ });
+
+ it('collapses blank-line runs and trailing whitespace so the clamp shows real words', () => {
+ expect(markdownToPlainText('one\n\n\n\ntwo \n\n three')).toBe('one\ntwo\nthree');
+ expect(markdownToPlainText(' spaced out ')).toBe('spaced out');
+ });
+
+ it('leaves a plain stack trace readable', () => {
+ const trace = 'TypeError: x is not a function\n at foo (/app/a.js:1:2)\n at bar (/app/b.js:3:4)';
+ expect(markdownToPlainText(trace))
+ .toBe('TypeError: x is not a function\nat foo (/app/a.js:1:2)\nat bar (/app/b.js:3:4)');
+ });
+});