feat: connect conversations with Magic Notes

Let users retain useful assistant replies or complete conversations without
leaving their chat workflow. Preview and edit captured text, choose an existing
note or atomically create a note with its first entry, and return to the source
conversation or message from saved records.

Add an application-scoped Notes workbar tab with title/body search and quick
text appends. Preserve drafts across conversation switches and guard closing,
replacement and disabling. Schema 48 stores optional source metadata without
rewriting file-backed bodies; source deletion retains the saved note. Older
clients cannot reopen an upgraded database without a pre-upgrade backup.

Release note: 可将助手回答或完整会话预览、编辑后加入魔法笔记,并从笔记返回原会话或消息。右侧快速笔记支持搜索和追加文字,切换会话保留草稿;采集本身不调用模型,保存后自动评论仍遵循已有设置。

Validation: isolated HEAD-based candidate passed 22 files / 930 focused tests,
plus 20 gateway tests after including its create-result fixture adjustment.
Real Electron App/preload/IPC/SQLite acceptance passed for all 502 historical
messages, exact-entry/source navigation, native keyboard input in a 214px
panel, reopen and source-deletion retention, with zero capture model calls.
Repository lint and web TypeScript passed. Cached whitespace and secret-pattern
checks passed; native-client changes and unrelated IPC extraction are excluded.

Validation limits: the isolated source tree reuses installed node_modules,
where a parallel task upgraded DSH from the committed 0.1.2-rc.1 to 0.1.7-rc.2.
Full typecheck reports 14 DSH errors in three unchanged files; the full-suite
attempt with --bail=1 also fails in deepseek-harness-host.test.ts. These are not
all-green repository or release-package results. Earlier execution-time full
suite failures and fixture repairs remain recorded in the feature progress doc.
This commit is contained in:
mesalogo
2026-09-27 08:17:54 +08:00
parent 55efca3ee1
commit 1094433a7d
51 changed files with 1949 additions and 56 deletions
+5 -1
View File
@@ -73,6 +73,9 @@ import type {
MagicNoteDetail,
MagicNoteEntryCreateResult,
MagicNoteCreateInput,
MagicNoteCreateResult,
MagicNoteSearchInput,
MagicNoteSummary,
MagicNoteEntryCreateInput,
MagicNoteEntryUpdateInput,
MagicNoteContent,
@@ -2325,8 +2328,9 @@ export type DesktopApi = {
}
magicNotes: {
list: () => Promise<MagicNotesSnapshot>
search: (input: MagicNoteSearchInput) => Promise<MagicNoteSummary[]>
get: (noteId: string) => Promise<MagicNoteDetail>
create: (input: MagicNoteCreateInput) => Promise<MagicNoteDetail>
create: (input: MagicNoteCreateInput) => Promise<MagicNoteCreateResult>
update: (input: MagicNoteUpdateInput) => Promise<MagicNoteDetail>
remove: (noteId: string) => Promise<void>
createEntry: (
+1
View File
@@ -319,6 +319,7 @@ export const ipcChannels = {
contextReadClipboard: 'context:read-clipboard',
contextRemove: 'context:remove',
magicNotesList: 'magic-notes:list',
magicNotesSearch: 'magic-notes:search',
magicNotesGet: 'magic-notes:get',
magicNotesCreate: 'magic-notes:create',
magicNotesUpdate: 'magic-notes:update',
+37 -2
View File
@@ -282,11 +282,40 @@ export const magicNoteContentSchema = z.union([magicNoteRichContentSchema, magic
export type MagicNoteContent = z.infer<typeof magicNoteContentSchema>
export type MagicNoteAnalysisInputMode = 'text' | 'images' | 'canvas-images' | 'text-fallback'
export const magicNoteSourceSchema = z.object({
kind: z.enum(['message', 'conversation']),
conversationId: magicNoteIdSchema,
messageIds: z.array(magicNoteIdSchema).min(1),
capturedAt: z.string().datetime(),
conversationTitle: z.string(),
projectId: magicNoteIdSchema.optional(),
projectName: z.string().optional()
}).strict().superRefine((source, context) => {
if (source.kind === 'message' && source.messageIds.length !== 1) {
context.addIssue({ code: 'custom', path: ['messageIds'], message: 'Message sources require exactly one message' })
}
if (new Set(source.messageIds).size !== source.messageIds.length) {
context.addIssue({ code: 'custom', path: ['messageIds'], message: 'Source message IDs must be unique' })
}
})
export type MagicNoteSource = z.infer<typeof magicNoteSourceSchema>
export const magicNoteSearchSchema = z.object({
query: z.string().trim().max(1000),
limit: z.number().int().min(1).max(200).optional()
}).strict()
export type MagicNoteSearchInput = z.infer<typeof magicNoteSearchSchema>
export const magicNoteCreateSchema = z
.object({
title: z.string().trim().min(1).max(100)
title: z.string().trim().min(1).max(100),
content: magicNoteContentSchema.optional(),
source: magicNoteSourceSchema.optional()
})
.strict()
.refine((input) => !input.source || !!input.content, {
path: ['content'], message: 'Source requires initial content'
})
export type MagicNoteCreateInput = z.infer<typeof magicNoteCreateSchema>
export const magicNoteUpdateSchema = z
@@ -311,7 +340,8 @@ export const magicNoteDeleteSchema = z
export const magicNoteEntryCreateSchema = z
.object({
noteId: magicNoteIdSchema,
content: magicNoteContentSchema
content: magicNoteContentSchema,
source: magicNoteSourceSchema.optional()
})
.strict()
export type MagicNoteEntryCreateInput = z.infer<
@@ -440,6 +470,7 @@ export type MagicNoteEntry = {
id: string
noteId: string
content: MagicNoteContent
source?: MagicNoteSource
plainText: string
comments: MagicNoteComment[]
analyzedAt?: string
@@ -467,6 +498,10 @@ export type MagicNoteEntryCreateResult = MagicNoteDetail & {
createdEntryId: string
}
export type MagicNoteCreateResult = MagicNoteDetail & {
createdEntryId?: string
}
export type MagicNotesSnapshot = {
notes: MagicNoteSummary[]
}
+9
View File
@@ -13,6 +13,14 @@ const terminalId = '00000000-0000-4000-8000-000000000102'
const projectId = '00000000-0000-4000-8000-000000000201'
describe('workbar contracts', () => {
it('keeps notes as a context-independent single instance through layout normalization', () => {
const instance = { id: taskId, appId: 'notes', title: 'Notes' } as const
const layout = { instances: [instance, { ...instance, id: terminalId }], activeInstanceId: terminalId, expanded: true, dock: 'right', widthRatio: 0.3 }
expect(workbarLayoutPreferencesSchema.safeParse(layout).success).toBe(false)
expect(normalizeWorkbarLayoutPreferences(layout, [])?.instances).toEqual([instance])
expect(workbarTabInstanceSchema.safeParse({ ...instance, targetRef: { type: 'conversation', conversationId: 'A' } }).success).toBe(false)
expect(workbarTabInstanceSchema.safeParse({ ...instance, targetRef: { type: 'project', projectId } }).success).toBe(false)
})
it('persists supervision conversation and task targets without allowing task terminal bindings', () => {
for (const targetRef of [{ type: 'conversation', conversationId: 'A' }, { type: 'task', taskId: 'task-A' }]) {
const instance = { id: taskId, appId: 'tasks', title: 'Tasks', targetRef }
@@ -36,6 +44,7 @@ describe('workbar contracts', () => {
{ id: 'workspace', instancePolicy: 'single', defaultContext: 'current-project', defaultOpen: true, required: true, closable: false, reorderable: false },
{ id: 'browser', instancePolicy: 'multiple', defaultContext: 'current-conversation', defaultOpen: true, required: false, closable: true, reorderable: true },
{ id: 'results', instancePolicy: 'single', defaultContext: 'current-project', defaultOpen: true, required: false, closable: true, reorderable: true },
{ id: 'notes', instancePolicy: 'single', defaultContext: 'application', defaultOpen: false, required: false, closable: true, reorderable: true },
{
id: 'terminal',
instancePolicy: 'multiple',
+18
View File
@@ -24,6 +24,7 @@ export const workbarAppIdSchema = z.enum([
'workspace',
'browser',
'results',
'notes',
'terminal'
])
export type WorkbarAppId = z.infer<typeof workbarAppIdSchema>
@@ -152,6 +153,20 @@ export const WORKBAR_APP_DEFINITIONS = [
reorderable: true,
availability: { state: 'available' }
},
{
id: 'notes',
visibleAcrossContextSwitches: true,
label: '笔记',
icon: 'notes',
description: '浏览笔记和快速追加文字。',
instancePolicy: 'single',
defaultContext: 'application',
defaultOpen: false,
required: false,
closable: true,
reorderable: true,
availability: { state: 'available' }
},
{
id: 'terminal',
visibleAcrossContextSwitches: true,
@@ -205,6 +220,9 @@ export const workbarTabInstanceSchema = z
})
.strict()
.superRefine((instance, context) => {
if (instance.appId === 'notes' && instance.targetRef) {
context.addIssue({ code: 'custom', path: ['targetRef'], message: 'Notes are application scoped and do not accept target bindings' })
}
if (
instance.appId === 'terminal' &&
(!instance.targetRef || !['local', 'project'].includes(instance.targetRef.type))