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: clean ChatGPT citations and independently scroll brain memories

[._.]/ Adam Eivy4cd612266c0f
diff --git a/client/src/components/brain/ConversationViewer.jsx b/client/src/components/brain/ConversationViewer.jsx
index acecfdeb05..8e0566a8c8 100644
--- a/client/src/components/brain/ConversationViewer.jsx
+++ b/client/src/components/brain/ConversationViewer.jsx
@@ -13,7 +13,7 @@ import { timeAgo } from '../../utils/formatters';
* (with inline images and asset links) lives in the import archive or markdown
* body, rendered in this sidebar preview without a blocking modal.
*/
-export default function ConversationViewer({ record, onClose, onEdit, onSendToCatalog }) {
+export default function ConversationViewer({ record, onClose, onEdit, onSendToCatalog, fillHeight = false }) {
const [archive, setArchive] = useState(null);
const [loading, setLoading] = useState(record?.source === 'chatgpt-import' && !!record?.sourceRef);
const [error, setError] = useState(null);
@@ -38,7 +38,7 @@ export default function ConversationViewer({ record, onClose, onEdit, onSendToCa
return (
<aside
aria-label={`Preview: ${title}`}
- className="bg-port-card border border-port-border rounded-lg flex flex-col w-full overflow-hidden shadow-lg lg:sticky lg:top-4 max-h-[85vh] lg:max-h-[calc(100vh-10rem)]"
+ className={`bg-port-card border border-port-border rounded-lg flex flex-col w-full overflow-hidden shadow-lg ${fillHeight ? 'h-full min-h-0' : 'lg:sticky lg:top-4 max-h-[85vh] lg:max-h-[calc(100vh-10rem)]'}`}
>
{/* Mobile-only back button bar */}
<div className="px-4 pt-3 pb-0 lg:hidden">
diff --git a/client/src/components/brain/constants.js b/client/src/components/brain/constants.js
index f0ca92034e..7db2fd47e8 100644
--- a/client/src/components/brain/constants.js
+++ b/client/src/components/brain/constants.js
@@ -14,7 +14,7 @@ const TAB_PRESENTATION = {
ideas: { icon: Lightbulb },
'daily-log': { icon: NotebookPen, fullBleed: true },
links: { icon: Link2 },
- memory: { icon: Database },
+ memory: { icon: Database, fullBleed: true },
notes: { icon: FileText, fullBleed: true },
graph: { icon: Network, fullBleed: true },
digest: { icon: Calendar },
diff --git a/client/src/components/brain/constants.test.js b/client/src/components/brain/constants.test.js
index 36c5f2e060..3e396b7f37 100644
--- a/client/src/components/brain/constants.test.js
+++ b/client/src/components/brain/constants.test.js
@@ -24,6 +24,6 @@ describe('Brain TABS ↔ nav manifest', () => {
});
it('keeps the full-bleed set derived from the presentation map', () => {
- expect([...FULL_BLEED_TAB_IDS].sort()).toEqual(['daily-log', 'graph', 'notes', 'threads']);
+ expect([...FULL_BLEED_TAB_IDS].sort()).toEqual(['daily-log', 'graph', 'memory', 'notes', 'threads']);
});
});
diff --git a/client/src/components/brain/tabs/MemoryTab.jsx b/client/src/components/brain/tabs/MemoryTab.jsx
index 15c545e6f1..4a44749e7f 100644
--- a/client/src/components/brain/tabs/MemoryTab.jsx
+++ b/client/src/components/brain/tabs/MemoryTab.jsx
@@ -737,7 +737,7 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {
};
return (
- <div className="space-y-4">
+ <div className={fixedType ? 'space-y-4' : 'h-full min-h-0 flex flex-col gap-4 overflow-hidden p-3 sm:p-4'}>
{/* Backend status banner */}
{backendStatus?.backend === 'file' && (
<Banner
@@ -762,7 +762,7 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {
)}
{/* Type tabs */}
- <div className="flex items-center gap-2 flex-wrap">
+ <div className="flex items-center gap-2 flex-wrap shrink-0">
{!fixedType && MEMORY_TABS.map((tab) => {
const Icon = tab.icon;
const isActive = activeType === tab.id;
@@ -826,9 +826,9 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {
</div>
{/* Main content area: split into list + sidebar preview when an entry is active */}
- <div className="flex flex-col lg:flex-row items-start gap-4">
+ <div className={`flex flex-col lg:flex-row gap-4 ${fixedType ? 'items-start' : 'flex-1 min-h-0 overflow-hidden'}`}>
{/* Left column: search, add form, records list */}
- <div className={`flex-1 min-w-0 w-full space-y-4 ${recordId && !loading ? 'hidden lg:block' : 'block'}`}>
+ <div role="region" aria-label="Memory entries" tabIndex={0} className={`flex-1 min-w-0 w-full space-y-4 ${fixedType ? '' : 'min-h-0 overflow-y-auto overscroll-contain'} ${recordId && !loading ? 'hidden lg:block' : 'block'}`}>
{/* Search filter */}
<div className="relative">
<Search size={16} className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-500" />
@@ -903,11 +903,12 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {
{/* Right column: Sidebar preview for full content */}
{recordId && !loading && (
- <div className="w-full lg:w-[480px] xl:w-[560px] 2xl:w-[640px] shrink-0">
+ <div className={`w-full lg:w-[480px] xl:w-[560px] 2xl:w-[640px] shrink-0 ${fixedType ? '' : 'h-full min-h-0 overflow-y-auto'}`}>
{viewerRecord ? (
<ConversationViewer
key={viewerRecord.id}
record={viewerRecord}
+ fillHeight={!fixedType}
onClose={closeReader}
onEdit={startEdit}
onSendToCatalog={handleSendToCatalog}
diff --git a/client/src/components/brain/tabs/MemoryTab.reader.test.jsx b/client/src/components/brain/tabs/MemoryTab.reader.test.jsx
index a9396aea7c..9a43638c48 100644
--- a/client/src/components/brain/tabs/MemoryTab.reader.test.jsx
+++ b/client/src/components/brain/tabs/MemoryTab.reader.test.jsx
@@ -69,6 +69,11 @@ describe('Brain memory reader', () => {
expect(screen.queryByRole('complementary')).toBeNull();
expect(screen.queryByRole('dialog')).toBeNull();
+ // Selecting from a scrolled list keeps that same independent scroll region.
+ const entries = screen.getByRole('region', { name: 'Memory entries' });
+ expect(entries.className).toContain('overflow-y-auto');
+ entries.scrollTop = 800;
+
// Click to read full entry
fireEvent.click(screen.getByRole('button', { name: 'Read First memory' }));
expect(screen.getByTestId('location').textContent).toBe('/brain/memory/memories/mem-1');
@@ -76,6 +81,9 @@ describe('Brain memory reader', () => {
// Sidebar aside preview appears, NO modal dialog
const sidebar = await screen.findByRole('complementary', { name: 'Preview: First memory' });
expect(sidebar).toBeTruthy();
+ expect(sidebar.className).toContain('h-full');
+ expect(screen.getByRole('region', { name: 'Memory entries' })).toBe(entries);
+ expect(entries.scrollTop).toBe(800);
expect(screen.queryByRole('dialog')).toBeNull();
expect(within(sidebar).getByText('First memory full content')).toBeTruthy();
expect(screen.getByText('Viewing')).toBeTruthy();
diff --git a/server/lib/README.md b/server/lib/README.md
index d950270c9c..89a13c26e8 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -731,3 +731,5 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `persistentMindProcessAudit.js` | Bounded process-audit schemas, deterministic observations, measured recovery ratios, and closed-vocabulary synthetic finding renderer. |
| `markdownImages.js` | `markdownImages(content, limit)` — bounded, deduplicated safe markdown image previews for Brain cards and import archives. |
+
+| `chatgptText.js` | `stripChatgptCitations(text)` removes opaque ChatGPT citation tokens while preserving ordinary Markdown and asset links. |
diff --git a/server/lib/chatgptText.js b/server/lib/chatgptText.js
new file mode 100644
index 0000000000..fcad35a5ba
--- /dev/null
+++ b/server/lib/chatgptText.js
@@ -0,0 +1,12 @@
+/** Remove ChatGPT's opaque citation markup without changing ordinary Markdown. */
+export function stripChatgptCitations(text) {
+ if (typeof text !== 'string') return text;
+ return text
+ .replace(/\uE200cite\uE202[^\uE200\uE201\r\n]*\uE201/g, '')
+ // Some exports omit the closing marker. Match only known reference IDs
+ // at a line boundary, never arbitrary text after an unfinished opener.
+ .replace(/\uE200cite\uE202turn\d+(?:search|view|fetch|file)\d+(?:\uE202turn\d+(?:search|view|fetch|file)\d+)*(?=\r?\n|$)/g, '')
+ // Older imports could cut a token at the preview limit. Only recognize
+ // that partial token immediately before the importer's truncation footer.
+ .replace(/\uE200cite\uE202[^\uE200\uE201\r\n]*(?=\n\n…\(transcript truncated — open the full conversation to see everything\)$)/g, '');
+}
diff --git a/server/lib/chatgptText.test.js b/server/lib/chatgptText.test.js
new file mode 100644
index 0000000000..01b25e7949
--- /dev/null
+++ b/server/lib/chatgptText.test.js
@@ -0,0 +1,25 @@
+import { describe, expect, it } from 'vitest';
+import { stripChatgptCitations } from './chatgptText.js';
+
+describe('ChatGPT citation cleanup', () => {
+ it('removes complete single and multi-source tokens without changing surrounding Markdown', () => {
+ const input = 'A citeturn1search0 and B.citeturn2search3turn2search4\n\n[Source](https://example.com)\n![Image](/data/brain-imports/example.png)';
+ const expected = 'A and B.\n\n[Source](https://example.com)\n![Image](/data/brain-imports/example.png)';
+ expect(stripChatgptCitations(input)).toBe(expected);
+ expect(stripChatgptCitations(expected)).toBe(expected);
+ });
+
+ it('removes unterminated reference IDs at line boundaries without consuming the following prose', () => {
+ expect(stripChatgptCitations('Answer.citeturn1search0turn2view1\n\nKeep this.\nciteturn3search2')).toBe('Answer.\n\nKeep this.\n');
+ });
+
+ it('removes a token cut by the legacy import preview limit', () => {
+ const footer = '\n\n…(transcript truncated — open the full conversation to see everything)';
+ expect(stripChatgptCitations(`Answer.citeturn1sea${footer}`)).toBe(`Answer.${footer}`);
+ });
+
+ it('preserves unrelated private-use markup and incomplete tokens rather than eating prose', () => {
+ const text = 'imageexample citeunfinished\nKeep this. citeturn1search0';
+ expect(stripChatgptCitations(text)).toBe('imageexample citeunfinished\nKeep this. ');
+ });
+});
diff --git a/server/lib/index.js b/server/lib/index.js
index e400ed7f7a..f46c5927a0 100644
--- a/server/lib/index.js
+++ b/server/lib/index.js
@@ -714,3 +714,5 @@ export * from './contributionSecurityPolicy.js';
export * from './catalogExtractionDraft.js';
export * from './markdownImages.js';
+
+export * from './chatgptText.js';
diff --git a/server/services/chatgptImport.js b/server/services/chatgptImport.js
index f2ccb60106..34507164b7 100644
--- a/server/services/chatgptImport.js
+++ b/server/services/chatgptImport.js
@@ -20,6 +20,7 @@
*/
import { join } from 'path';
+import { stripChatgptCitations } from '../lib/chatgptText.js';
import { unlink } from 'fs/promises';
import { atomicWrite, ensureDir, PATHS, tryReadFile, safeJSONParse } from '../lib/fileUtils.js';
import { createMemoryEntry } from './brainStorage.js';
@@ -170,7 +171,7 @@ export function extractMessages(conversation, { assetResolver = null } = {}) {
if (!role || role === 'system') continue;
const { text: partsText, renderedIds } = renderParts(msg.content?.parts, assetResolver);
const attachmentText = renderAttachments(msg, assetResolver, renderedIds);
- const text = `${partsText}${attachmentText}`;
+ const text = stripChatgptCitations(`${partsText}${attachmentText}`);
if (!text.trim()) continue;
messages.push({
id: msg.id || node.id,
diff --git a/server/services/chatgptImport.test.js b/server/services/chatgptImport.test.js
index 8d3af8e150..ae59cd0c82 100644
--- a/server/services/chatgptImport.test.js
+++ b/server/services/chatgptImport.test.js
@@ -82,6 +82,17 @@ describe('chatgptImport service', () => {
...overrides
});
+ it('cleans citations before persisting both the preview and full archive', async () => {
+ const conv = sampleConversation();
+ conv.mapping.n2.message.content.parts = ['Answer.citeturn1search0turn1search1 [Source](https://example.com)'];
+ const parsed = parseExport([conv]);
+ await importConversations(parsed);
+ expect(createMemoryEntryMock.mock.calls[0][0].content).toContain('Answer. [Source](https://example.com)');
+ const archive = await readArchivedConversation('conv-1.json');
+ expect(archive.transcript).not.toContain('cite');
+ expect(archive.messages[1].text).toBe('Answer. [Source](https://example.com)');
+ });
+
describe('extractMessages', () => {
it('walks the mapping tree from current_node back to root, in order', () => {
const messages = extractMessages(sampleConversation());