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([issue-1722]): mark creative brain notes consumed after catalog ingest commits

[._.]/ Adam Eivy04e2c81f6ed6
diff --git a/client/src/components/brain/tabs/InboxTab.jsx b/client/src/components/brain/tabs/InboxTab.jsx
index 50232407e3..0f01be9275 100644
--- a/client/src/components/brain/tabs/InboxTab.jsx
+++ b/client/src/components/brain/tabs/InboxTab.jsx
@@ -236,22 +236,26 @@ export default function InboxTab({ onRefresh, settings }) {
const doneEntries = entries.filter(e => e.status === 'done');
const errorEntries = entries.filter(e => e.status === 'error');
- // Creative notes the user flagged at capture, not yet marked done — the pool
- // the "Send to Catalog" batch action draws from. Pending (optimistic) entries
- // are excluded so we never ship a thought the server hasn't confirmed.
+ // Creative notes the user flagged at capture, not yet marked done and not yet
+ // consumed by a committed catalog ingest — the pool the "Send to Catalog" batch
+ // action draws from. `sentToCatalogAt` (stamped on commit, not navigation)
+ // drops a note out so it can't be accidentally re-sent. Pending (optimistic)
+ // entries are excluded so we never ship a thought the server hasn't confirmed.
const creativeEntries = entries.filter(
- e => e.creative && e.status !== 'done' && !String(e.id).startsWith('_pending_')
+ e => e.creative && e.status !== 'done' && !e.sentToCatalogAt && !String(e.id).startsWith('_pending_')
);
// Batch-send creative notes into the catalog ingest flow. We hand the combined
- // text to /catalog/ingest (router state) where the user runs extract→review→
- // commit — turning loose creative thoughts into typed catalog ingredients.
+ // text plus the source note ids to /catalog/ingest (router state) where the
+ // user runs extract→review→commit — turning loose creative thoughts into typed
+ // catalog ingredients. On commit the catalog page stamps these ids consumed.
const handleSendCreativeToCatalog = () => {
if (!creativeEntries.length) return;
const rawText = creativeEntries
.map(e => e.capturedText)
.filter(Boolean)
.join('\n\n---\n\n');
- navigate('/catalog/ingest', { state: { prefill: { title: 'Creative notes from Brain', rawText } } });
+ const creativeNoteIds = creativeEntries.map(e => e.id);
+ navigate('/catalog/ingest', { state: { prefill: { title: 'Creative notes from Brain', rawText, creativeNoteIds } } });
};
if (loading) {
diff --git a/client/src/pages/CatalogIngest.jsx b/client/src/pages/CatalogIngest.jsx
index 8bb31ac5a3..6418a57c8a 100644
--- a/client/src/pages/CatalogIngest.jsx
+++ b/client/src/pages/CatalogIngest.jsx
@@ -21,6 +21,7 @@ import {
ingestCatalogVoice,
ingestCatalogBrain,
} from '../services/apiCatalog';
+import { markBrainInboxSentToCatalog } from '../services/apiBrain';
// One review section per ingredient type. The first three are bible-shaped
// (character/place/object) and use `physicalDescription`/`description` as the
@@ -89,6 +90,11 @@ export default function CatalogIngest() {
const recorderRef = useRef(null);
const fileInputRef = useRef(null);
const brainHandledRef = useRef(false);
+ // Creative inbox note ids handed off from the Brain batch-send. Once the
+ // commit below succeeds we stamp these consumed so they drop out of the
+ // inbox's "ready to become ingredients" banner (issue #1722). Held in a ref so
+ // it survives the history-state clear and the extract/review re-renders.
+ const creativeNoteIdsRef = useRef([]);
// Stop the mic if the page unmounts mid-recording (navigating away), so the
// MediaRecorder stream isn't left live with no UI to stop it.
@@ -237,6 +243,9 @@ export default function CatalogIngest() {
setSourceMode('paste');
setTitle(prefill.title || '');
setRawText(prefill.rawText);
+ if (Array.isArray(prefill.creativeNoteIds)) {
+ creativeNoteIdsRef.current = prefill.creativeNoteIds.filter(Boolean);
+ }
}
if (handled) {
brainHandledRef.current = true;
@@ -379,6 +388,16 @@ export default function CatalogIngest() {
if (!result) return;
const n = Array.isArray(result.ingredients) ? result.ingredients.length : accepted.length;
toast.success(`Added ${n} ingredient${n === 1 ? '' : 's'} to the catalog.`);
+ // Best-effort: mark the source creative notes consumed so the inbox banner
+ // stops offering them. Only fires when this ingest came from the Brain
+ // batch-send (ids present). Failure is non-fatal — the notes just stay
+ // re-sendable (the prior behavior) — so swallow it silently rather than
+ // toasting a confusing error after a successful commit.
+ const noteIds = creativeNoteIdsRef.current;
+ if (noteIds.length) {
+ creativeNoteIdsRef.current = [];
+ await markBrainInboxSentToCatalog(noteIds, { silent: true }).catch(() => {});
+ }
navigate('/catalog');
};
diff --git a/client/src/services/apiBrain.js b/client/src/services/apiBrain.js
index 1fb261dc4d..ec64a41152 100644
--- a/client/src/services/apiBrain.js
+++ b/client/src/services/apiBrain.js
@@ -42,6 +42,12 @@ export const updateBrainInboxEntry = (id, capturedText) => request(`/brain/inbox
});
export const deleteBrainInboxEntry = (id) => request(`/brain/inbox/${id}`, { method: 'DELETE' });
export const markBrainInboxDone = (id) => request(`/brain/inbox/${id}/done`, { method: 'POST' });
+// Stamp a batch of creative notes as consumed once their catalog ingest commits.
+export const markBrainInboxSentToCatalog = (ids, options) => request('/brain/inbox/sent-to-catalog', {
+ method: 'POST',
+ body: JSON.stringify({ ids }),
+ ...options
+});
// Brain - People
export const getBrainPeople = () => request('/brain/people');
diff --git a/server/lib/brainValidation.js b/server/lib/brainValidation.js
index 09e3a33b47..16d6bf5e23 100644
--- a/server/lib/brainValidation.js
+++ b/server/lib/brainValidation.js
@@ -70,7 +70,12 @@ export const inboxLogRecordSchema = z.object({
error: errorSchema.optional(),
// User-marked creative note (see captureInputSchema.creative). Drives the
// "Send creative notes to Catalog" batch action in the inbox.
- creative: z.boolean().optional()
+ creative: z.boolean().optional(),
+ // ISO timestamp stamped once this creative note's catalog ingest COMMITS
+ // (not on mere navigation). Drives the inbox's "already consumed" filter so a
+ // batch-sent note drops out of the "ready to become ingredients" banner and
+ // can't be accidentally re-sent. Absent ⇒ still re-sendable.
+ sentToCatalogAt: z.string().datetime().optional()
});
// People Record schema
@@ -201,6 +206,13 @@ export const updateInboxInputSchema = z.object({
capturedText: z.string().min(1).max(10000)
});
+// Batch mark a set of creative inbox notes as consumed by a catalog ingest that
+// just committed. Bounded to keep a malformed/runaway payload from stamping the
+// whole inbox in one call.
+export const markInboxSentToCatalogSchema = z.object({
+ ids: z.array(z.string().guid()).min(1).max(200)
+}).strict();
+
// Create/Update People input schema
export const peopleInputSchema = z.object({
name: z.string().min(1).max(200),
diff --git a/server/routes/brain.js b/server/routes/brain.js
index 89415eadcb..1e5a36d885 100644
--- a/server/routes/brain.js
+++ b/server/routes/brain.js
@@ -21,6 +21,7 @@ import {
resolveReviewInputSchema,
fixInputSchema,
updateInboxInputSchema,
+ markInboxSentToCatalogSchema,
inboxQuerySchema,
peopleInputSchema,
projectInputSchema,
@@ -138,6 +139,17 @@ router.post('/inbox/:id/done', asyncHandler(async (req, res) => {
res.json(result);
}));
+/**
+ * POST /api/brain/inbox/sent-to-catalog
+ * Mark a batch of creative inbox notes as consumed by a committed catalog ingest.
+ * Literal path — declared before the `/inbox/:id` routes so it isn't shadowed.
+ */
+router.post('/inbox/sent-to-catalog', asyncHandler(async (req, res) => {
+ const { ids } = validateRequest(markInboxSentToCatalogSchema, req.body);
+ const updated = await brainService.markInboxSentToCatalog(ids);
+ res.json({ updated, count: updated.length });
+}));
+
/**
* PUT /api/brain/inbox/:id
* Update an inbox entry (edit captured text)
diff --git a/server/routes/brain.test.js b/server/routes/brain.test.js
index 10e66a1858..16ec5516e3 100644
--- a/server/routes/brain.test.js
+++ b/server/routes/brain.test.js
@@ -13,6 +13,7 @@ vi.mock('../services/brain.js', () => ({
resolveReview: vi.fn(),
fixClassification: vi.fn(),
retryClassification: vi.fn(),
+ markInboxSentToCatalog: vi.fn(),
// People
getPeople: vi.fn(),
getPersonById: vi.fn(),
@@ -336,6 +337,44 @@ describe('Brain Routes', () => {
});
});
+ describe('POST /api/brain/inbox/sent-to-catalog', () => {
+ const id1 = '11111111-1111-4111-8111-111111111111';
+ const id2 = '22222222-2222-4222-8222-222222222222';
+
+ it('stamps the given creative notes consumed and returns the count', async () => {
+ brainService.markInboxSentToCatalog.mockResolvedValue([
+ { id: id1, sentToCatalogAt: 'x' },
+ { id: id2, sentToCatalogAt: 'x' }
+ ]);
+
+ const response = await request(app)
+ .post('/api/brain/inbox/sent-to-catalog')
+ .send({ ids: [id1, id2] });
+
+ expect(response.status).toBe(200);
+ expect(response.body.count).toBe(2);
+ expect(brainService.markInboxSentToCatalog).toHaveBeenCalledWith([id1, id2]);
+ });
+
+ it('rejects an empty id list', async () => {
+ const response = await request(app)
+ .post('/api/brain/inbox/sent-to-catalog')
+ .send({ ids: [] });
+
+ expect(response.status).toBe(400);
+ expect(brainService.markInboxSentToCatalog).not.toHaveBeenCalled();
+ });
+
+ it('rejects non-guid ids', async () => {
+ const response = await request(app)
+ .post('/api/brain/inbox/sent-to-catalog')
+ .send({ ids: ['_pending_1'] });
+
+ expect(response.status).toBe(400);
+ expect(brainService.markInboxSentToCatalog).not.toHaveBeenCalled();
+ });
+ });
+
// ===========================================================================
// PEOPLE CRUD
// ===========================================================================
diff --git a/server/services/brain.js b/server/services/brain.js
index 0d10b9b58f..f9679fc045 100644
--- a/server/services/brain.js
+++ b/server/services/brain.js
@@ -680,6 +680,24 @@ export async function markInboxDone(inboxLogId) {
return updated;
}
+/**
+ * Mark a batch of creative inbox notes as consumed by a catalog ingest that just
+ * committed — stamps `sentToCatalogAt` so they drop out of the inbox's "ready to
+ * become ingredients" banner and can't be accidentally re-sent. Idempotent and
+ * forgiving: ids that no longer exist (deleted/tombstoned) are skipped silently
+ * so a partially-stale list still stamps the rest. Returns the updated entries.
+ */
+export async function markInboxSentToCatalog(ids) {
+ const sentToCatalogAt = new Date().toISOString();
+ const updated = [];
+ for (const id of ids) {
+ const entry = await storage.updateInboxLog(id, { sentToCatalogAt });
+ if (entry) updated.push(entry);
+ }
+ console.log(`🧠 Marked ${updated.length} creative note(s) sent to catalog`);
+ return updated;
+}
+
/**
* Update inbox entry (edit captured text)
*/
diff --git a/server/services/brain.test.js b/server/services/brain.test.js
index 37ca6b61fc..efbbf80b3b 100644
--- a/server/services/brain.test.js
+++ b/server/services/brain.test.js
@@ -130,6 +130,7 @@ import {
runWeeklyReview,
retryClassification,
markInboxDone,
+ markInboxSentToCatalog,
updateInboxEntry,
deleteInboxEntry,
deleteMemoryEntry,
@@ -538,6 +539,45 @@ describe('brain service', () => {
});
});
+ // ===========================================================================
+ // markInboxSentToCatalog
+ // ===========================================================================
+
+ describe('markInboxSentToCatalog', () => {
+ it('stamps sentToCatalogAt on each id and returns updated entries', async () => {
+ storage.updateInboxLog
+ .mockResolvedValueOnce({ id: 'inbox-001', sentToCatalogAt: 'x' })
+ .mockResolvedValueOnce({ id: 'inbox-002', sentToCatalogAt: 'x' });
+
+ const result = await markInboxSentToCatalog(['inbox-001', 'inbox-002']);
+
+ expect(storage.updateInboxLog).toHaveBeenCalledTimes(2);
+ expect(storage.updateInboxLog).toHaveBeenNthCalledWith(1, 'inbox-001', {
+ sentToCatalogAt: expect.any(String)
+ });
+ expect(storage.updateInboxLog).toHaveBeenNthCalledWith(2, 'inbox-002', {
+ sentToCatalogAt: expect.any(String)
+ });
+ expect(result).toHaveLength(2);
+ });
+
+ it('skips ids that no longer exist (null update) without throwing', async () => {
+ storage.updateInboxLog
+ .mockResolvedValueOnce(null)
+ .mockResolvedValueOnce({ id: 'inbox-002', sentToCatalogAt: 'x' });
+
+ const result = await markInboxSentToCatalog(['gone', 'inbox-002']);
+
+ expect(result).toEqual([{ id: 'inbox-002', sentToCatalogAt: 'x' }]);
+ });
+
+ it('returns an empty array for an empty id list', async () => {
+ const result = await markInboxSentToCatalog([]);
+ expect(result).toEqual([]);
+ expect(storage.updateInboxLog).not.toHaveBeenCalled();
+ });
+ });
+
// ===========================================================================
// updateInboxEntry
// ===========================================================================