fix: refresh magic notes after external updates

Subscribe the open Magic Notes workspace to committed database changes from desktop and Agent/MCP writes. Preserve selections and unsaved drafts during refresh and external deletion.

File-level commit includes existing runtime edits in shared files; their remaining dependencies are still in the working tree.

Release note: Magic Notes now updates automatically after Agent/MCP edits while preserving your selection and unsaved drafts.
This commit is contained in:
mesalogo
2026-09-15 00:31:21 +08:00
parent fbba2e3abf
commit e1fe1cf10a
19 changed files with 571 additions and 49 deletions
+13 -1
View File
@@ -783,8 +783,10 @@ describe('KnowledgeMcpGateway', () => {
const { service } = createService()
const directory = await mkdtemp(join(tmpdir(), 'goodbuddy-note-mcp-'))
temporaryDirectories.push(directory)
const onMagicNotesChanged = vi.fn()
const database = new AssistantDatabase(
join(directory, 'assistant.sqlite')
join(directory, 'assistant.sqlite'),
{ onMagicNotesChanged }
)
databases.push(database)
database.initialize('C:\\Workspace')
@@ -838,12 +840,20 @@ describe('KnowledgeMcpGateway', () => {
})
])
expect(created.entries[0]?.content).toBe('核对构建产物')
expect(onMagicNotesChanged).toHaveBeenCalledTimes(1)
gateway.updateMagicNote(writeToken, {
noteId: created.id,
title: 'Updated plan',
expectedRevision: created.revision
})
expect(onMagicNotesChanged).toHaveBeenCalledTimes(2)
const withEntry = gateway.createMagicNoteEntry(writeToken, {
noteId: created.id,
content: '通知发布负责人'
})
const entry = withEntry.entries[1]!
expect(entry.content).toBe('通知发布负责人')
expect(onMagicNotesChanged).toHaveBeenCalledTimes(3)
const updatedEntry = gateway.updateMagicNoteEntry(writeToken, {
entryId: entry.id,
@@ -859,6 +869,7 @@ describe('KnowledgeMcpGateway', () => {
expectedRevision: entry.revision
})
).toThrow('已被更新')
expect(onMagicNotesChanged).toHaveBeenCalledTimes(4)
const withoutEntry = gateway.deleteMagicNoteEntry(writeToken, {
entryId: entry.id,
@@ -873,6 +884,7 @@ describe('KnowledgeMcpGateway', () => {
expectedRevision: withoutEntry.revision
})
).toEqual({ deleted: true, noteId: created.id })
expect(onMagicNotesChanged).toHaveBeenCalledTimes(6)
expect(() =>
gateway.getMagicNote(readToken, { noteId: created.id })
).toThrow('笔记不存在')