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

feat: add AddToThreadButton affordance and include threads in Brain graph (#7664)

[._.]/ Adam Eivyde1ff533de52
diff --git a/client/src/components/apps/tabs/IssuesTab.jsx b/client/src/components/apps/tabs/IssuesTab.jsx
index 0150b99643..148472b968 100644
--- a/client/src/components/apps/tabs/IssuesTab.jsx
+++ b/client/src/components/apps/tabs/IssuesTab.jsx
@@ -22,6 +22,7 @@ import { chipColors } from '../../../lib/chipContrast';
import { enabledProcessProviderFilter } from '../../../utils/providers';
import * as api from '../../../services/api';
import { timeAgo } from '../../../utils/formatters';
+import AddToThreadButton from '../../threads/AddToThreadButton';
function ClaimReviewOverride({ defaults, overrides, onChange, modelOptions }) {
return (
@@ -882,6 +883,17 @@ export default function IssuesTab({ appId, appName }) {
</button>
);
})}
+ {(issue.url || issue.html_url) && (
+ <AddToThreadButton
+ refItem={{
+ kind: data?.forge === 'gitlab' ? 'gitlab.issue' : 'github.issue',
+ id: issue.url || issue.html_url,
+ label: `#${issue.number} ${issue.title || ''}`.trim()
+ }}
+ buttonText="Thread"
+ className="px-3 py-1.5 bg-port-bg text-gray-300 hover:text-white border border-port-border rounded-lg text-xs flex items-center gap-1.5 transition-colors"
+ />
+ )}
</div>
</div>
diff --git a/client/src/components/brain/constants.js b/client/src/components/brain/constants.js
index 2e0cd490f0..f0ca92034e 100644
--- a/client/src/components/brain/constants.js
+++ b/client/src/components/brain/constants.js
@@ -86,6 +86,11 @@ export const DESTINATIONS = {
icon: Music,
color: 'bg-rose-500/20 text-rose-400 border-rose-500/30'
},
+ threads: {
+ label: 'Threads',
+ icon: ListTodo,
+ color: 'bg-emerald-500/20 text-emerald-400 border-emerald-500/30'
+ },
unknown: {
label: 'Unknown',
icon: MessageSquare,
@@ -164,5 +169,6 @@ export const BRAIN_TYPE_HEX = {
memories: '#ec4899',
goals: '#f97316',
journals: '#14b8a6',
- songs: '#f43f5e'
+ songs: '#f43f5e',
+ threads: '#10b981'
};
diff --git a/client/src/components/brain/tabs/BrainGraph.jsx b/client/src/components/brain/tabs/BrainGraph.jsx
index 5e3e2b691b..2df7b9a88d 100644
--- a/client/src/components/brain/tabs/BrainGraph.jsx
+++ b/client/src/components/brain/tabs/BrainGraph.jsx
@@ -23,7 +23,7 @@ const EDGE_COLORS = {
linked: '#ffffff'
};
-const BRAIN_TYPES = ['people', 'projects', 'ideas', 'admin', 'memories', 'songs', 'goals', 'journals'];
+const BRAIN_TYPES = ['people', 'projects', 'ideas', 'admin', 'memories', 'songs', 'goals', 'journals', 'threads'];
// Scene-appearance callbacks handed to the shared graph3d/GraphScene.
// brainEdgeColor/brainEdgeIntensity are exported so the extraction's
@@ -59,7 +59,8 @@ const TYPE_GETTERS = {
memories: api.getBrainMemory,
goals: api.getBrainGoal,
journals: api.getBrainJournalEntry,
- songs: api.getSong
+ songs: api.getSong,
+ threads: api.getThread
};
// Prose body for the detail panel, in the order the panel prefers it. Every
diff --git a/client/src/components/brain/tabs/BrainGraph.test.jsx b/client/src/components/brain/tabs/BrainGraph.test.jsx
index c38a4573ea..98cc1a58f3 100644
--- a/client/src/components/brain/tabs/BrainGraph.test.jsx
+++ b/client/src/components/brain/tabs/BrainGraph.test.jsx
@@ -36,6 +36,7 @@ vi.mock('../../../services/api', () => ({
getBrainGoal: vi.fn(),
getBrainJournalEntry: vi.fn(),
getSong: vi.fn(),
+ getThread: vi.fn(),
}));
import * as api from '../../../services/api';
diff --git a/client/src/components/messages/InboxTab.jsx b/client/src/components/messages/InboxTab.jsx
index c30b9ff102..5790efdf01 100644
--- a/client/src/components/messages/InboxTab.jsx
+++ b/client/src/components/messages/InboxTab.jsx
@@ -7,6 +7,7 @@ import * as api from '../../services/api';
import socket from '../../services/socket';
import { timeAgo, formatDateNumeric } from '../../utils/formatters';
import MessageDetail from './MessageDetail';
+import AddToThreadButton from '../threads/AddToThreadButton';
const ACTION_CONFIG = {
reply: { icon: Reply, color: 'text-port-accent', bg: 'bg-port-accent/10', hoverBg: 'hover:bg-port-accent/20', label: 'Reply' },
@@ -661,6 +662,16 @@ export default function InboxTab({ accounts }) {
</button>
);
})}
+ {msg.accountId && msg.id && (
+ <AddToThreadButton
+ refItem={{
+ kind: 'message',
+ id: `${msg.accountId}:${msg.id}`,
+ label: msg.subject || '(no subject)'
+ }}
+ className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1.5 rounded text-xs text-gray-500 hover:text-gray-300 hover:bg-port-border/50 transition-colors disabled:opacity-50"
+ />
+ )}
<ChevronRight size={16} className="text-gray-600 ml-1" />
</div>
</div>
diff --git a/client/src/components/threads/AddToThreadButton.jsx b/client/src/components/threads/AddToThreadButton.jsx
new file mode 100644
index 0000000000..af5c0a987c
--- /dev/null
+++ b/client/src/components/threads/AddToThreadButton.jsx
@@ -0,0 +1,212 @@
+/**
+ * AddToThreadButton — attach any PortOS record or external item to a Brain thread (#7664).
+ *
+ * A Brain *thread* is a tracked topic or commitment (an open loop in the bullet
+ * journal sense), NOT a message thread (`messages/` owns that other sense of
+ * the word).
+ *
+ * Renders a compact button opening an EntityCombobox over open threads with
+ * match-or-create, POSTing `/api/brain/threads/attach`.
+ */
+
+import { useState, useEffect, useMemo, useId } from 'react';
+import { createPortal } from 'react-dom';
+import { ListTodo, X } from 'lucide-react';
+import * as api from '../../services/api';
+import toast from '../ui/Toast';
+import EntityCombobox from '../EntityCombobox';
+import useClickOutside from '../../hooks/useClickOutside';
+import usePopoverPosition, { VIEWPORT_PADDING } from '../../hooks/usePopoverPosition';
+import { THREAD_ACTIVE_STATUSES } from '../../lib/brainThreads';
+
+export default function AddToThreadButton({
+ refItem,
+ threadRef,
+ kind,
+ id,
+ label,
+ title,
+ buttonText,
+ className = '',
+ disabled = false,
+ size = 'md',
+ onAttached,
+ ariaLabel,
+ tooltip
+}) {
+ const [open, setOpen] = useState(false);
+ const [threads, setThreads] = useState([]);
+ const [loading, setLoading] = useState(false);
+ const [attaching, setAttaching] = useState(false);
+ const [query, setQuery] = useState('');
+ const inputId = useId();
+
+ const computedRef = useMemo(() => {
+ const base = refItem || threadRef;
+ const k = base?.kind || kind;
+ const i = base?.id || id;
+ const l = base?.label || label || title;
+ if (!k || !i) return null;
+ return {
+ kind: k,
+ id: String(i),
+ ...(l ? { label: String(l).slice(0, 300) } : {})
+ };
+ }, [refItem, threadRef, kind, id, label, title]);
+
+ useEffect(() => {
+ if (!open) return;
+ let active = true;
+ setLoading(true);
+ api.listThreads({ status: THREAD_ACTIVE_STATUSES.join(',') }, { silent: true })
+ .then((res) => {
+ if (!active) return;
+ const list = Array.isArray(res?.threads) ? res.threads : Array.isArray(res) ? res : [];
+ setThreads(list);
+ })
+ .catch(() => {
+ if (active) setThreads([]);
+ })
+ .finally(() => {
+ if (active) setLoading(false);
+ });
+ return () => { active = false; };
+ }, [open]);
+
+ const comboboxItems = useMemo(() => {
+ return threads.map((t) => ({
+ id: t.id,
+ name: t.title || '(untitled)',
+ subtitle: t.nextAction || (t.status !== 'open' ? t.status : undefined)
+ }));
+ }, [threads]);
+
+ const { triggerRef, popoverRef, style: menuStyle } = usePopoverPosition({
+ open,
+ width: 320,
+ minWidth: 260,
+ position: 'below',
+ contentDeps: [comboboxItems.length, loading, attaching]
+ });
+
+ useClickOutside([triggerRef, popoverRef], open, () => setOpen(false));
+
+ const handlePick = async (item) => {
+ if (!computedRef || attaching) return;
+ setAttaching(true);
+ try {
+ const res = await api.attachToThread({ threadId: item.id, ref: computedRef });
+ toast.success(`Attached to thread "${res?.thread?.title || item.name}"`);
+ onAttached?.(res);
+ setOpen(false);
+ setQuery('');
+ } catch (err) {
+ toast.error(err?.message || 'Failed to attach to thread');
+ } finally {
+ setAttaching(false);
+ }
+ };
+
+ const handleCreate = async () => {
+ const trimmed = query.trim();
+ if (!trimmed || !computedRef || attaching) return;
+ setAttaching(true);
+ try {
+ const res = await api.attachToThread({ title: trimmed, ref: computedRef });
+ toast.success(`Created thread "${res?.thread?.title || trimmed}"`);
+ onAttached?.(res);
+ setOpen(false);
+ setQuery('');
+ } catch (err) {
+ toast.error(err?.message || 'Failed to create thread');
+ } finally {
+ setAttaching(false);
+ }
+ };
+
+ const accessibleName = ariaLabel || (buttonText ? undefined : 'Add to Brain thread');
+ const titleText = tooltip || (accessibleName || 'Add to Brain thread');
+ const isDisabled = disabled || !computedRef;
+
+ const defaultClasses = buttonText
+ ? 'inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs border border-port-border bg-port-bg text-gray-300 hover:text-white hover:border-port-accent/40 transition-colors disabled:opacity-50'
+ : 'min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1.5 rounded-lg border border-port-border bg-port-bg text-gray-400 hover:text-port-accent hover:border-port-accent/40 transition-colors disabled:opacity-50';
+
+ return (
+ <>
+ <button
+ ref={triggerRef}
+ type="button"
+ onClick={() => setOpen((prev) => !prev)}
+ disabled={isDisabled}
+ aria-expanded={open}
+ aria-haspopup="dialog"
+ aria-label={accessibleName}
+ title={titleText}
+ className={className || defaultClasses}
+ >
+ <ListTodo size={size === 'sm' ? 12 : 14} className="shrink-0" />
+ {buttonText && <span>{buttonText}</span>}
+ </button>
+
+ {open && typeof document !== 'undefined' && createPortal(
+ <div
+ ref={popoverRef}
+ role="dialog"
+ aria-label="Add to Brain thread"
+ style={{
+ position: 'fixed',
+ left: menuStyle?.left ?? `${VIEWPORT_PADDING}px`,
+ top: menuStyle?.top ?? `${VIEWPORT_PADDING}px`,
+ width: menuStyle?.width ?? '320px',
+ visibility: menuStyle ? 'visible' : 'hidden',
+ }}
+ onKeyDown={(e) => {
+ if (e.key === 'Escape') {
+ e.stopPropagation();
+ setOpen(false);
+ }
+ }}
+ className="z-50 bg-port-card border border-port-border rounded-lg shadow-xl p-3 space-y-2 text-white"
+ >
+ <div className="flex items-center justify-between gap-2 pb-1 border-b border-port-border">
+ <div className="flex items-center gap-1.5 text-xs font-medium text-white">
+ <ListTodo size={14} className="text-port-accent shrink-0" />
+ <span>Add to Brain thread</span>
+ </div>
+ <button
+ type="button"
+ onClick={() => setOpen(false)}
+ className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center text-gray-400 hover:text-white p-1 rounded transition-colors"
+ aria-label="Close"
+ >
+ <X size={14} />
+ </button>
+ </div>
+
+ {computedRef?.label && (
+ <div className="text-[11px] text-gray-400 truncate">
+ Attaching: <span className="text-gray-200 font-medium">{computedRef.label}</span>
+ </div>
+ )}
+
+ <EntityCombobox
+ items={comboboxItems}
+ value={query}
+ onChange={setQuery}
+ onPick={handlePick}
+ onCreate={handleCreate}
+ busy={loading || attaching}
+ inputId={inputId}
+ noun="thread"
+ placeholder="Search open threads or type name…"
+ createPrefix="New thread"
+ emptyNoItems="No open threads yet — type a name to create one."
+ className="w-full"
+ />
+ </div>,
+ document.body
+ )}
+ </>
+ );
+}
diff --git a/client/src/components/threads/AddToThreadButton.test.jsx b/client/src/components/threads/AddToThreadButton.test.jsx
new file mode 100644
index 0000000000..83630bc85c
--- /dev/null
+++ b/client/src/components/threads/AddToThreadButton.test.jsx
@@ -0,0 +1,209 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { render, screen, fireEvent, waitFor } from '@testing-library/react';
+import AddToThreadButton from './AddToThreadButton';
+import * as api from '../../services/api';
+import toast from '../ui/Toast';
+
+vi.mock('../../services/api', () => ({
+ listThreads: vi.fn(),
+ attachToThread: vi.fn(),
+}));
+
+vi.mock('../ui/Toast', () => ({
+ default: {
+ success: vi.fn(),
+ error: vi.fn(),
+ },
+}));
+
+describe('AddToThreadButton', () => {
+ const sampleRef = {
+ kind: 'github.issue',
+ id: 'https://github.com/atomantic/PortOS/issues/100',
+ label: '#100 Fix widget layout',
+ };
+
+ const sampleThreads = [
+ { id: 't1', title: 'Sprint planning', status: 'open', nextAction: 'Review backlog' },
+ { id: 't2', title: 'Refactor auth', status: 'waiting', waitingOn: 'Alice' },
+ ];
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ api.listThreads.mockResolvedValue({ threads: sampleThreads });
+ api.attachToThread.mockResolvedValue({ thread: { id: 't1', title: 'Sprint planning' }, created: false });
+ });
+
+ it('renders a button with accessible label and title', () => {
+ render(<AddToThreadButton threadRef={sampleRef} />);
+ const btn = screen.getByRole('button', { name: 'Add to Brain thread' });
+ expect(btn).toBeInTheDocument();
+ expect(btn).not.toBeDisabled();
+ });
+
+ it('renders buttonText when provided', () => {
+ render(<AddToThreadButton threadRef={sampleRef} buttonText="Thread" />);
+ const btn = screen.getByRole('button', { name: 'Thread' });
+ expect(btn).toBeInTheDocument();
+ });
+
+ it('disables the button when no ref is provided', () => {
+ render(<AddToThreadButton />);
+ const btn = screen.getByRole('button', { name: 'Add to Brain thread' });
+ expect(btn).toBeDisabled();
+ });
+
+ it('opens the popover and fetches open threads when clicked', async () => {
+ render(<AddToThreadButton threadRef={sampleRef} />);
+ const btn = screen.getByRole('button', { name: 'Add to Brain thread' });
+ fireEvent.click(btn);
+
+ expect(api.listThreads).toHaveBeenCalledWith(
+ { status: 'open,waiting,someday' },
+ { silent: true }
+ );
+
+ await waitFor(() => {
+ expect(screen.getByText('Add to Brain thread')).toBeInTheDocument();
+ expect(screen.getByText('Attaching:')).toBeInTheDocument();
+ expect(screen.getByText('#100 Fix widget layout')).toBeInTheDocument();
+ });
+ });
+
+ it('attaches to an existing thread when selected from combobox', async () => {
+ const onAttached = vi.fn();
+ render(<AddToThreadButton threadRef={sampleRef} onAttached={onAttached} />);
+ fireEvent.click(screen.getByRole('button', { name: 'Add to Brain thread' }));
+
+ await waitFor(() => {
+ expect(screen.getByRole('combobox')).toBeInTheDocument();
+ });
+
+ const input = screen.getByRole('combobox');
+ fireEvent.focus(input);
+
+ await waitFor(() => {
+ expect(screen.getByText('Sprint planning')).toBeInTheDocument();
+ });
+
+ fireEvent.click(screen.getByText('Sprint planning'));
+
+ await waitFor(() => {
+ expect(api.attachToThread).toHaveBeenCalledWith({
+ threadId: 't1',
+ ref: {
+ kind: 'github.issue',
+ id: 'https://github.com/atomantic/PortOS/issues/100',
+ label: '#100 Fix widget layout',
+ },
+ });
+ expect(toast.success).toHaveBeenCalledWith('Attached to thread "Sprint planning"');
+ expect(onAttached).toHaveBeenCalled();
+ });
+ });
+
+ it('creates a new thread and attaches when committing a typed name', async () => {
+ api.attachToThread.mockResolvedValue({ thread: { id: 't3', title: 'New Open Loop' }, created: true });
+ render(<AddToThreadButton threadRef={sampleRef} />);
+ fireEvent.click(screen.getByRole('button', { name: 'Add to Brain thread' }));
+
+ await waitFor(() => {
+ expect(screen.getByPlaceholderText('Search open threads or type name…')).toBeInTheDocument();
+ });
+
+ const input = screen.getByPlaceholderText('Search open threads or type name…');
+ fireEvent.focus(input);
+ fireEvent.change(input, { target: { value: 'New Open Loop' } });
+
+ await waitFor(() => {
+ expect(screen.getByText(/New thread “New Open Loop”/i)).toBeInTheDocument();
+ });
+
+ fireEvent.click(screen.getByText(/New thread “New Open Loop”/i));
+
+ await waitFor(() => {
+ expect(api.attachToThread).toHaveBeenCalledWith({
+ title: 'New Open Loop',
+ ref: {
+ kind: 'github.issue',
+ id: 'https://github.com/atomantic/PortOS/issues/100',
+ label: '#100 Fix widget layout',
+ },
+ });
+ expect(toast.success).toHaveBeenCalledWith('Created thread "New Open Loop"');
+ });
+ });
+
+ it('supports individual kind, id, label props', async () => {
+ render(
+ <AddToThreadButton
+ kind="message"
+ id="acc-1:msg-99"
+ label="Quarterly Review Notes"
+ />
+ );
+ fireEvent.click(screen.getByRole('button', { name: 'Add to Brain thread' }));
+
+ await waitFor(() => {
+ expect(screen.getByText('Quarterly Review Notes')).toBeInTheDocument();
+ });
+
+ const input = screen.getByRole('combobox');
+ fireEvent.focus(input);
+
+ await waitFor(() => {
+ expect(screen.getByText('Sprint planning')).toBeInTheDocument();
+ });
+
+ fireEvent.click(screen.getByText('Sprint planning'));
+
+ await waitFor(() => {
+ expect(api.attachToThread).toHaveBeenCalledWith({
+ threadId: 't1',
+ ref: {
+ kind: 'message',
+ id: 'acc-1:msg-99',
+ label: 'Quarterly Review Notes',
+ },
+ });
+ });
+ });
+
+ it('handles attach failure with error toast', async () => {
+ api.attachToThread.mockRejectedValue(new Error('Network error'));
+ render(<AddToThreadButton threadRef={sampleRef} />);
+ fireEvent.click(screen.getByRole('button', { name: 'Add to Brain thread' }));
+
+ await waitFor(() => {
+ expect(screen.getByRole('combobox')).toBeInTheDocument();
+ });
+
+ const input = screen.getByRole('combobox');
+ fireEvent.focus(input);
+
+ await waitFor(() => {
+ expect(screen.getByText('Sprint planning')).toBeInTheDocument();
+ });
+
+ fireEvent.click(screen.getByText('Sprint planning'));
+
+ await waitFor(() => {
+ expect(toast.error).toHaveBeenCalledWith('Network error');
+ });
+ });
+
+ it('closes popover on Close button click', async () => {
+ render(<AddToThreadButton threadRef={sampleRef} />);
+ fireEvent.click(screen.getByRole('button', { name: 'Add to Brain thread' }));
+
+ await waitFor(() => {
+ expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();
+ });
+
+ fireEvent.click(screen.getByRole('button', { name: 'Close' }));
+
+ await waitFor(() => {
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
+ });
+ });
+});
diff --git a/client/src/components/threads/README.md b/client/src/components/threads/README.md
new file mode 100644
index 0000000000..dec07d39fb
--- /dev/null
+++ b/client/src/components/threads/README.md
@@ -0,0 +1,7 @@
+# Threads Components
+
+Affordances and components for Brain threads (#7664) — tracked open loops (bullet journal sense), distinct from message threads.
+
+| Component | Purpose |
+|---|---|
+| `AddToThreadButton.jsx` | Compact button opening an `EntityCombobox` over open threads to attach PortOS records or external items. |
diff --git a/client/src/components/threads/index.js b/client/src/components/threads/index.js
new file mode 100644
index 0000000000..2fd2939537
--- /dev/null
+++ b/client/src/components/threads/index.js
@@ -0,0 +1,9 @@
+/**
+ * Brain threads component library (#7664).
+ *
+ * A Brain *thread* is a tracked topic or commitment (an open loop in the bullet
+ * journal sense), NOT a message thread (`messages/` owns that other sense of
+ * the word).
+ */
+
+export { default as AddToThreadButton } from './AddToThreadButton.jsx';
diff --git a/client/src/pages/CatalogIngredient.jsx b/client/src/pages/CatalogIngredient.jsx
index 88dac5c741..3b1f082f77 100644
--- a/client/src/pages/CatalogIngredient.jsx
+++ b/client/src/pages/CatalogIngredient.jsx
@@ -37,6 +37,7 @@ import { generateImage } from '../services/apiSystem';
import { composeCanonStyledPrompt } from '../lib/composeStyledPrompt';
import { threadRefLabel, threadRefUrl } from '../lib/threadRefKinds.js';
import ThreadRefChip from '../components/brain/ThreadRefChip';
+import AddToThreadButton from '../components/threads/AddToThreadButton';
import { getUniverse } from '../services/apiUniverseBuilder';
import useMounted from '../hooks/useMounted';
import MediaJobThumb from '../components/pipeline/MediaJobThumb';
@@ -490,6 +491,15 @@ export default function CatalogIngredient() {
className="inline-flex items-center gap-1.5 px-3 py-2 rounded-lg bg-port-accent hover:bg-port-accent/90 disabled:opacity-50 text-white text-sm font-medium">
{saving ? <Loader2 size={14} className="animate-spin" /> : <Save size={14} />} Save
</button>
+ <AddToThreadButton
+ refItem={{
+ kind: 'catalog.ingredient',
+ id: record.id,
+ label: name || record.name || record.id
+ }}
+ buttonText="Thread"
+ className="inline-flex items-center gap-1.5 px-3 py-2 rounded-lg text-sm border border-port-border text-gray-300 hover:text-white hover:border-port-accent/40 transition-colors"
+ />
{isDirty && <span className="text-xs text-port-warning" role="status">Unsaved changes</span>}
{armedDelete ? (
<span className="inline-flex items-center gap-1 text-sm">
diff --git a/client/src/services/README.md b/client/src/services/README.md
index f46a014e20..ec04e8c128 100644
--- a/client/src/services/README.md
+++ b/client/src/services/README.md
@@ -73,7 +73,7 @@ toasts on throw). **Custom catch ⇒ `silent: true`** — otherwise toasts fire
| File | Purpose |
|---|---|
-| `apiBrainThreads.js` | Brain threads — the bullet journal's open loops (`/brain/threads`, Brain `threads` entity; a *thread* is a tracked topic, never a message thread): filtered list (`listThreads({ status, priority, tag, pinned, refKind, q })`), full record with `resolvedRefs` (`getThread`), create / defaults-free PUT / tombstone delete, and per-ref attach/detach (`addThreadRef`, `removeThreadRef`). |
+| `apiBrainThreads.js` | Brain threads — the bullet journal's open loops (`/brain/threads`, Brain `threads` entity; a *thread* is a tracked topic, never a message thread): filtered list (`listThreads({ status, priority, tag, pinned, refKind, q })`), full record with `resolvedRefs` (`getThread`), create / defaults-free PUT / tombstone delete, per-ref attach/detach (`addThreadRef`, `removeThreadRef`), and attach (`attachToThread`). |
| `apiBrain.js` | Brain (second-brain) search + ingest + edit, plus the federation parity audit (`getBrainParityReports`, `runBrainParityCheck`). |
| `apiMemory.js` | Memory CRUD. |
| `apiNotes.js` | Notes vault. |
diff --git a/client/src/services/apiBrainThreads.js b/client/src/services/apiBrainThreads.js
index 131f0886a8..777eee244b 100644
--- a/client/src/services/apiBrainThreads.js
+++ b/client/src/services/apiBrainThreads.js
@@ -43,3 +43,7 @@ export const addThreadRef = (id, ref, options) =>
export const removeThreadRef = (id, kind, refId, options) =>
request(`/brain/threads/${enc(id)}/refs/${enc(kind)}/${enc(refId)}`, { method: 'DELETE', ...options });
+
+// POST /api/brain/threads/attach — `{ ref, threadId?, title? }` → `{ thread, created }` (200 / 201).
+export const attachToThread = (body = {}, options) =>
+ request('/brain/threads/attach', { method: 'POST', body: JSON.stringify(body), ...options });
diff --git a/server/services/brainGraph.js b/server/services/brainGraph.js
index f6d9824edb..f413da1907 100644
--- a/server/services/brainGraph.js
+++ b/server/services/brainGraph.js
@@ -28,7 +28,7 @@ import { loadBridgeMap, bridgeKey } from './brainMemoryBridge.js';
import { getBrainProjections, journalHasBody } from './brainSearchIndex.js';
import { getGoals } from './identity.js';
-const ENTITY_TYPES = ['people', 'projects', 'ideas', 'admin', 'memories', 'songs'];
+const ENTITY_TYPES = ['people', 'projects', 'ideas', 'admin', 'memories', 'songs', 'threads'];
// Edges shown per node are capped so a densely-tagged hub can't reintroduce the
// combinatorial blow-up inside a bounded view.
@@ -90,7 +90,7 @@ async function loadNodes() {
const perType = await Promise.all(ENTITY_TYPES.map((type) => getBrainProjections(type, { ranked: false })));
ENTITY_TYPES.forEach((type, i) => {
for (const record of perType[i]) {
- if (record.archived) continue;
+ if (record.archived || record.status === 'archived') continue;
nodes.push({
id: record.id,
brainType: type,
@@ -161,7 +161,7 @@ export async function getBrainGraphSearchIndex() {
const perType = await Promise.all(ENTITY_TYPES.map((type) => getBrainProjections(type, { ranked: false })));
perType.forEach((records, i) => {
for (const record of records) {
- if (record.archived) continue;
+ if (record.archived || record.status === 'archived') continue;
nodes.push({ id: record.id, label: entityLabel(record), brainType: ENTITY_TYPES[i] });
}
});
diff --git a/server/services/brainGraph.test.js b/server/services/brainGraph.test.js
index 24b3b898e9..729a281632 100644
--- a/server/services/brainGraph.test.js
+++ b/server/services/brainGraph.test.js
@@ -128,11 +128,11 @@ describe('getBrainGraphSearchIndex', () => {
onlyType('people', [{ id: 'p1', name: 'A' }]);
await getBrainGraphSearchIndex();
- // 6 entity types (incl. songs) + journals, one scan each.
- expect(brainStorage.getAll).toHaveBeenCalledTimes(7);
+ // 7 entity types (incl. songs and threads) + journals, one scan each.
+ expect(brainStorage.getAll).toHaveBeenCalledTimes(8);
await getBrainGraphSearchIndex();
- expect(brainStorage.getAll).toHaveBeenCalledTimes(7);
+ expect(brainStorage.getAll).toHaveBeenCalledTimes(8);
});
it('keeps unrendered payloads and journal bodies out of the projections it reads', async () => {
@@ -464,4 +464,26 @@ describe('goals and journal nodes', () => {
const { nodes } = await getBrainGraphSearchIndex();
expect(nodes).toEqual([{ id: 's1', label: 'Example Song', brainType: 'songs' }]);
});
+
+ it('includes Thread records as graph nodes labelled by title and skips archived threads (#7664)', async () => {
+ onlyType('threads', [
+ { id: 'th1', title: 'Sprint planning', status: 'open', notes: 'Backlog items', tags: ['planning'] },
+ { id: 'th2', title: 'Old loop', status: 'archived' }
+ ]);
+ const { nodes } = await getBrainGraphSearchIndex();
+ expect(nodes).toEqual([{ id: 'th1', label: 'Sprint planning', brainType: 'threads' }]);
+
+ const overview = await getBrainGraphOverview({ limit: 50 });
+ const thNode = overview.nodes.find(n => n.id === 'th1');
+ expect(thNode).toEqual({
+ id: 'th1',
+ brainType: 'threads',
+ label: 'Sprint planning',
+ summary: 'Backlog items',
+ tags: ['planning'],
+ importance: 0.6,
+ status: 'open'
+ });
+ expect(overview.nodes.find(n => n.id === 'th2')).toBeUndefined();
+ });
});
diff --git a/server/services/brainSearchIndex.js b/server/services/brainSearchIndex.js
index 603d56d725..d96c2fef26 100644
--- a/server/services/brainSearchIndex.js
+++ b/server/services/brainSearchIndex.js
@@ -77,7 +77,8 @@ const PROJECTED_FIELDS = Object.freeze({
// A Brain *thread* is a tracked open loop (#7664), not a message thread.
// Search matches the fields a person would type to find one; `notes` is the
// markdown body (capped at 20k, the same order as an admin item's notes).
- threads: Object.freeze(['title', 'nextAction', 'waitingOn', 'notes']),
+ // Includes graph projection fields (tags, status, archived) for brainGraph.
+ threads: Object.freeze([...GRAPH_PROJECTION_FIELDS, 'nextAction', 'waitingOn']),
});
/**