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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: protect IdeaLoom notes from clobbering (#5338)
[._.]/ Adam Eivy540bb4d0238f
diff --git a/client/src/components/brain/IdeaLoomLists.jsx b/client/src/components/brain/IdeaLoomLists.jsxindex 5ab3aeecb2..2e1ebad9f5 100644--- a/client/src/components/brain/IdeaLoomLists.jsx+++ b/client/src/components/brain/IdeaLoomLists.jsx@@ -158,7 +158,7 @@ export default function IdeaLoomLists() {<button type="button" disabled={exchangeBusy} onClick={() => runExchange(() => api.importIdeaLoomFromObsidian({ silent: true }), 'IdeaLoom import complete')} className="flex min-h-[44px] items-center gap-2 rounded border border-port-border px-3 text-xs text-gray-300 hover:bg-port-border/50 disabled:opacity-50"><Upload size={14} />Import from Obsidian</button><button type="button" disabled={exchangeBusy} onClick={() => runExchange(() => api.syncIdeaLoomToObsidian(null, { silent: true }), 'IdeaLoom export complete')} className="flex min-h-[44px] items-center gap-2 rounded border border-port-border px-3 text-xs text-gray-300 hover:bg-port-border/50 disabled:opacity-50"><Download size={14} />Export to Obsidian</button></div>}- {exchangeResult && <p role="status" className="mb-3 text-xs text-gray-400">Last exchange: {exchangeResult.imported || 0} imported · {exchangeResult.exported || 0} exported · {exchangeResult.skipped || 0} skipped · {exchangeResult.malformed || 0} malformed · {exchangeResult.unavailable || 0} unavailable · {exchangeResult.failed || 0} failed</p>}+ {exchangeResult && <p role="status" className="mb-3 text-xs text-gray-400">Last exchange: {exchangeResult.imported || 0} imported · {exchangeResult.exported || 0} exported · {exchangeResult.skipped || 0} skipped · {exchangeResult.conflicted || 0} conflicted · {exchangeResult.malformed || 0} malformed · {exchangeResult.unavailable || 0} unavailable · {exchangeResult.failed || 0} failed</p>}<div className="space-y-1">{lists.map((list) => <button key={list.id} type="button" onClick={() => select(list.id)} className={`w-full rounded p-3 text-left ${selected?.id === list.id ? 'bg-port-accent/20 text-white' : 'text-gray-300 hover:bg-port-border/50'}`}><span className="block truncate text-sm font-medium">{list.title}</span><span className="text-xs text-gray-500">{list.status === 'completed' ? 'Completed' : 'Draft'} · {(list.ideas || []).length} ideas</span>diff --git a/server/services/idealoomObsidian.js b/server/services/idealoomObsidian.jsindex 12ef048302..b832b9ec5e 100644--- a/server/services/idealoomObsidian.js+++ b/server/services/idealoomObsidian.js@@ -97,6 +97,19 @@ const parseFrontmatter = (lines) => {continue;}if (indent) return { error: `unexpected indentation at line ${index + 1}` };+ if (!rawValue.trim()) {+ let propertyIndex = index + 1;+ const propertyValues = [];+ while (propertyIndex < end && /^\s+-\s+/.test(lines[propertyIndex])) {+ const propertyValue = decodeScalar(lines[propertyIndex].replace(/^\s+-\s+/, ''));+ if (propertyValue === null) return { error: `invalid ${key} property at line ${propertyIndex + 1}` };+ propertyValues.push(propertyValue);+ propertyIndex += 1;+ }+ values[key] = propertyValues.length ? propertyValues : '';+ index = propertyIndex - 1;+ continue;+ }if (key === 'tags' && rawValue.trim().startsWith('[') && rawValue.trim().endsWith(']')) {const inner = rawValue.trim().slice(1, -1).trim();values.tags = inner ? inner.split(',').map((entry) => decodeScalar(entry)).filter(Boolean).map((tag) => tag.replace(/^#/, '')) : [];@@ -353,7 +366,9 @@ const writeNote = async (vaultId, notePath, content) => {if (existing?.error === 'NOTE_EVICTED') return { kind: 'unavailable', reason: 'note-unavailable' };if (existing?.error && existing.error !== 'NOTE_NOT_FOUND') return { kind: 'failed', reason: existing.error };const parsedExisting = existing?.content ? parseIdeaLoomMarkdown(existing.content) : null;- if (parsedExisting?.ok && parsedExisting.list.id !== undefined) return { kind: 'existing', id: parsedExisting.list.id };+ if (parsedExisting?.ok && parsedExisting.list.id !== undefined) {+ return { kind: 'existing', id: parsedExisting.list.id, content: existing.content };+ }if (existing?.content) return { kind: 'existing', id: null };const created = await obsidian.createNote(vaultId, notePath, content);if (!created?.error) return { kind: 'written' };@@ -374,6 +389,11 @@ const exportOne = async (vaultId, list) => {}if (pathResult.kind === 'existing') {if (pathResult.id !== list.id) return { kind: 'failed', reason: 'note-path-owned-by-another-list', notePath };+ const remoteChanged = hashContent(pathResult.content) !== list.sync?.lastKnownContentHash;+ const lastLocalSync = list.sync?.lastImportedAt || list.sync?.lastExportedAt;+ const localChanged = !lastLocalSync || list.updatedAt > lastLocalSync;+ if (remoteChanged && localChanged) return { kind: 'conflicted', reason: 'both-sides-changed', notePath };+ if (remoteChanged) return { kind: 'skipped', reason: 'external-change', notePath };const updated = await obsidian.updateNote(vaultId, notePath, content);if (updated?.error === 'NOTE_EVICTED') return { kind: 'unavailable', reason: 'note-unavailable', notePath };if (updated?.error) return { kind: 'failed', reason: updated.error, notePath };diff --git a/server/services/idealoomObsidian.test.js b/server/services/idealoomObsidian.test.jsindex c9c52f5440..11c0284897 100644--- a/server/services/idealoomObsidian.test.js+++ b/server/services/idealoomObsidian.test.js@@ -2,6 +2,7 @@ import { describe, expect, it, beforeEach, vi } from 'vitest';import { mkdirSync, mkdtempSync, rmSync } from 'fs';import { join } from 'path';import { tmpdir } from 'os';+import { createHash } from 'crypto';vi.mock('./obsidian.js', () => ({getVaultById: vi.fn(),@@ -102,6 +103,13 @@ describe('IdeaLoom Markdown contract', () => {}));});+ it('accepts harmless Obsidian Properties metadata', () => {+ const rendered = renderIdeaLoomMarkdown(list());+ const withProperties = rendered.replace('title:', 'aliases:\n - "Example alias"\ntitle:');++ expect(parseIdeaLoomMarkdown(withProperties)).toEqual(expect.objectContaining({ ok: true }));+ });+it('rejects malformed metadata and non-dense numbered ideas', () => {const rendered = renderIdeaLoomMarkdown(list());expect(parseIdeaLoomMarkdown(rendered.replace(`id: "${LIST_ID}"`, 'id: "not-a-uuid"')).ok).toBe(false);@@ -183,7 +191,15 @@ describe('IdeaLoom Obsidian exchange', () => {expect(lists.updateSyncMetadata).toHaveBeenCalledWith(LIST_ID, expect.objectContaining({ notePath: expect.stringContaining('Idea Loom/') }));const importedPath = 'Idea Loom/2026-01-01-original-name.md';- lists.listLists.mockResolvedValue([local, list({ id: '0a1b2c3d-4e5f-4a6b-8c7d-8e9f0a1b2c3d', sync: { notePath: importedPath } })]);+ const importedList = list({ id: '0a1b2c3d-4e5f-4a6b-8c7d-8e9f0a1b2c3d' });+ lists.listLists.mockResolvedValue([local, {+ ...importedList,+ sync: {+ notePath: importedPath,+ lastKnownContentHash: createHash('sha256').update(renderIdeaLoomMarkdown(importedList), 'utf8').digest('hex'),+ lastImportedAt: importedList.updatedAt,+ },+ }]);obsidian.getNote.mockImplementation(async (_id, path) => path === importedPath? { content: renderIdeaLoomMarkdown(list({ id: '0a1b2c3d-4e5f-4a6b-8c7d-8e9f0a1b2c3d' })) }: { error: 'NOTE_NOT_FOUND' });@@ -194,4 +210,25 @@ describe('IdeaLoom Obsidian exchange', () => {expect(exported.counts.exported).toBe(1);expect(obsidian.updateNote).toHaveBeenCalledWith('0f6c6a6f-8c16-4c7d-9a8b-2e2f6f2cb4d1', importedPath, expect.any(String));});++ it('does not overwrite a note changed on both sides', async () => {+ const base = renderIdeaLoomMarkdown(list());+ const external = renderIdeaLoomMarkdown(list({ ideas: ['External edit'] }));+ const importedPath = 'Idea Loom/2026-01-01-original-name.md';+ const local = list({+ updatedAt: '2026-08-29T12:00:00.000Z',+ sync: {+ notePath: importedPath,+ lastKnownContentHash: createHash('sha256').update(base, 'utf8').digest('hex'),+ lastImportedAt: '2026-08-29T11:00:00.000Z',+ },+ });+ lists.listLists.mockResolvedValue([local]);+ obsidian.getNote.mockResolvedValue({ content: external });++ const result = await exportToObsidian();++ expect(result.counts).toMatchObject({ conflicted: 1, exported: 0 });+ expect(obsidian.updateNote).not.toHaveBeenCalled();+ });});