Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(ai): link created notes and default mind map theme

tianma-if378c80712bb8
diff --git a/apps/api/src/companion-tool-actions.test.mjs b/apps/api/src/companion-tool-actions.test.mjs
index 151e7aa0..7bd33352 100644
--- a/apps/api/src/companion-tool-actions.test.mjs
+++ b/apps/api/src/companion-tool-actions.test.mjs
@@ -198,6 +198,7 @@ describe("shared companion MCP adapter", () => {
notebookId: "ideas",
title: "RAG 原理思维导图",
kind: "mind-map",
+ theme: "mint",
nodes: [
{ id: "root", label: "RAG" },
{ id: "retrieve", label: "检索", parentId: "root" },
@@ -208,7 +209,7 @@ describe("shared companion MCP adapter", () => {
expect(created.id).toBeTruthy();
expect(JSON.stringify(created)).not.toContain("edgeever-diagram-v1");
const memo = await getMemoDetail(f.db, scope.workspaceId, created.id);
- expect(parseDiagramDocument(memo.contentMarkdown)).toMatchObject({ kind: "mind-map" });
+ expect(parseDiagramDocument(memo.contentMarkdown)).toMatchObject({ kind: "mind-map", theme: "plain" });
expect(memo.contentMarkdown).not.toContain("## RAG");
expect(sources.map(source => source.id)).toContain(created.id);
const diagramMemo = await tools.get_memo.execute({ memoId: created.id });
diff --git a/apps/api/src/mcp-management-tools.test.mjs b/apps/api/src/mcp-management-tools.test.mjs
index 453596fd..7ed544d1 100644
--- a/apps/api/src/mcp-management-tools.test.mjs
+++ b/apps/api/src/mcp-management-tools.test.mjs
@@ -105,7 +105,7 @@ describe("MCP template and AI instruction management", () => {
expect(created.diagram.nodes[0].layout).toBeUndefined();
const stored = sqlite.query("SELECT content_markdown FROM memo_contents WHERE memo_id = ?").get(created.memo.id);
const diagram = parseDiagramDocument(stored.content_markdown);
- expect(diagram).toMatchObject({ kind, theme: "brand" });
+ expect(diagram).toMatchObject({ kind, theme: kind === "mind-map" ? "plain" : "brand" });
expect(diagram.nodes.map((node) => node.id)).toEqual(nodes.map((node) => node.id));
expect(diagram.nodes.every((node) => Number.isFinite(node.x) && Number.isFinite(node.y))).toBeTrue();
expect(diagram.nodes.every((node) => node.width > 0 && node.height > 0)).toBeTrue();
diff --git a/apps/api/src/mcp-tool-service.ts b/apps/api/src/mcp-tool-service.ts
index 02cfd421..d098e639 100644
--- a/apps/api/src/mcp-tool-service.ts
+++ b/apps/api/src/mcp-tool-service.ts
@@ -4,6 +4,7 @@ import {
TemplateCreateSchema,
TemplateUpdateSchema,
compileInfographicNote,
+ DIAGRAM_DEFAULT_THEME,
docToText,
hasInfographicDocumentMarker,
INFOGRAPHIC_SCHEMA_VERSION,
@@ -484,7 +485,9 @@ export const callMcpTool = async (
const notebookId = getRequiredString(args.notebookId, "notebookId");
const ir = parseDiagramMemoIr(args);
const { compileDiagramIr } = await import("@edgeever/shared/diagram-layout");
- const document = compileDiagramIr(ir);
+ // Generated mind maps must start with the same theme as a note created
+ // in the editor, even when an agent supplies an arbitrary color scheme.
+ const document = compileDiagramIr(ir.kind === "mind-map" ? { ...ir, theme: DIAGRAM_DEFAULT_THEME } : ir);
const contentMarkdown = serializeDiagramDocument(document);
if (!parseDiagramDocument(contentMarkdown)) {
throw new AppError("invalid_params", "The diagram graph could not be compiled", 400);
diff --git a/apps/api/src/mcp-tools.ts b/apps/api/src/mcp-tools.ts
index 2c5932a9..4321e2db 100644
--- a/apps/api/src/mcp-tools.ts
+++ b/apps/api/src/mcp-tools.ts
@@ -330,7 +330,7 @@ const MCP_TOOL_DEFINITIONS = [
{
name: "create_diagram_memo",
description:
- "Create an editable visual diagram memo from a semantic graph; EdgeEver generates node sizes, coordinates, edge IDs, and a deterministic layout. For mind maps, omit node type and use parentId for hierarchy. Flowchart node types are process, decision, start, or end. Architecture node types are client, frontend, service, database, storage, queue, security, external, or boundary; boundary nodes may contain nodes through parentId but cannot be edge endpoints.",
+ "Create an editable visual diagram memo from a semantic graph; EdgeEver generates node sizes, coordinates, edge IDs, and a deterministic layout. Mind maps always start with the default plain theme; any supplied theme is ignored for mind maps. For mind maps, omit node type and use parentId for hierarchy. Flowchart node types are process, decision, start, or end. Architecture node types are client, frontend, service, database, storage, queue, security, external, or boundary; boundary nodes may contain nodes through parentId but cannot be edge endpoints.",
inputSchema: {
type: "object",
required: ["notebookId", "kind", "nodes"],
@@ -339,7 +339,7 @@ const MCP_TOOL_DEFINITIONS = [
notebookId: { type: "string", minLength: 1 },
title: { type: "string", maxLength: 160 },
kind: { type: "string", enum: ["mind-map", "flowchart", "architecture"] },
- theme: { type: "string", enum: ["plain", "brand", "sun", "wa", "island", "rose", "mint", "cosmos", "tea", "naive", "macaron", "ocean", "ink", "classic", "paper"] },
+ theme: { type: "string", description: "Color scheme for non-mind-map diagrams. Mind maps always start with the default plain theme.", enum: ["plain", "brand", "sun", "wa", "island", "rose", "mint", "cosmos", "tea", "naive", "macaron", "ocean", "ink", "classic", "paper"] },
structure: { type: "string", enum: ["map", "line", "capsule", "box", "circle", "ellipse", "hexagon", "logic", "tree", "brace", "org", "timeline", "fishbone"] },
layout: {
type: "object",
diff --git a/apps/desktop/src/main/acp-host.mjs b/apps/desktop/src/main/acp-host.mjs
index 4d1d2c97..736432ca 100644
--- a/apps/desktop/src/main/acp-host.mjs
+++ b/apps/desktop/src/main/acp-host.mjs
@@ -943,7 +943,7 @@ export function createAcpHostRuntime(options = {}) {
if (mcpBridge) {
content.blocks.splice(input.adapterId === "codex" ? 1 : 0, 0, {
type: "text",
- text: "For EdgeEver note operations in this conversation, use only the session-provided MCP server named edgeever-current-workspace. It is connected to the account currently signed in to EdgeEver. Ignore any EdgeEver MCP server from your persistent configuration, which may target a different instance or account.",
+ text: "For EdgeEver note operations in this conversation, use only the session-provided MCP server named edgeever-current-workspace. It is connected to the account currently signed in to EdgeEver. Ignore any EdgeEver MCP server from your persistent configuration, which may target a different instance or account. When you create a note, include a clickable Markdown link to it in your final answer: [note title](#memo=exact_memo_id_from_tool_result). Do not show the note ID as plain text.",
});
}
} catch (error) {
diff --git a/apps/desktop/src/main/acp-host.test.mjs b/apps/desktop/src/main/acp-host.test.mjs
index fc486b02..d5ad2b8d 100644
--- a/apps/desktop/src/main/acp-host.test.mjs
+++ b/apps/desktop/src/main/acp-host.test.mjs
@@ -705,6 +705,7 @@ describe("ACP stdio session", () => {
const report = await readReport(reportPath);
expect(report.prompt[0]).toEqual({ type: "text", text: "分析资金往来" });
expect(report.prompt[1].text).toContain("edgeever-current-workspace");
+ expect(report.prompt[1].text).toContain("[note title](#memo=exact_memo_id_from_tool_result)");
expect(report.prompt[2]).toEqual({ type: "text", text: "Current note and earlier turns" });
expect(report.newSession.mcpServers[0].name).toBe("edgeever-current-workspace");
} finally {
diff --git a/apps/web/src/components/CompanionChat.tsx b/apps/web/src/components/CompanionChat.tsx
index cc3c6df7..251e3c96 100644
--- a/apps/web/src/components/CompanionChat.tsx
+++ b/apps/web/src/components/CompanionChat.tsx
@@ -9,6 +9,7 @@ import { Button } from "@/components/ui/button";
import { api, ApiRequestError } from "@/lib/api";
import { companionLocale } from "@/lib/companion-locale";
import { CompanionActionCard } from "./CompanionActionCard";
+import { CompanionCreatedNoteLinks } from "./CompanionCreatedNoteLinks";
import { CompanionNoteText } from "./CompanionNoteText";
import { CompanionQuestionForm } from "./CompanionQuestionForm";
import { CompanionRunTimeline } from "./CompanionRunTimeline";
@@ -323,6 +324,7 @@ export function CompanionChat({
onNotesChanged={onNotesChanged}
/>
{turn.response ? <CompanionNoteText text={turn.response} sources={turn.sources} onOpenNote={onOpenNote} /> : null}
+ <CompanionCreatedNoteLinks response={turn.response} tools={turn.tools ?? []} onOpenNote={onOpenNote} />
{turn.status === "interrupted" && turn.questions?.length && !running ? (
<CompanionQuestionForm questions={turn.questions} busy={busy} onSubmit={answers => resume(turn, answers)} />
) : null}
diff --git a/apps/web/src/components/CompanionCreatedNoteLinks.test.mjs b/apps/web/src/components/CompanionCreatedNoteLinks.test.mjs
new file mode 100644
index 00000000..7a079c62
--- /dev/null
+++ b/apps/web/src/components/CompanionCreatedNoteLinks.test.mjs
@@ -0,0 +1,32 @@
+import { describe, expect, test } from "bun:test";
+import { createElement } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { CompanionCreatedNoteLinks, missingCreatedNoteLinks } from "./CompanionCreatedNoteLinks.tsx";
+
+const created = { id: "tool-1", name: "create_diagram_memo", status: "done", effects: [
+ { kind: "created", memoId: "memo_abc", notebookId: "nb_inbox", title: "个人理财入门" },
+] };
+
+describe("created note links", () => {
+ test("adds a real note link when the model reports only an ID", () => {
+ expect(missingCreatedNoteLinks("已创建(ID:memo_abc)", [created])).toEqual([
+ { memoId: "memo_abc", notebookId: "nb_inbox", title: "个人理财入门" },
+ ]);
+ const html = renderToStaticMarkup(createElement(CompanionCreatedNoteLinks, {
+ response: "已创建(ID:memo_abc)", tools: [created], onOpenNote() {},
+ }));
+ expect(html).toContain('href="#memo=memo_abc"');
+ expect(html).toContain("个人理财入门");
+ });
+
+ test("does not duplicate a note link already in the answer", () => {
+ expect(missingCreatedNoteLinks("[个人理财入门](#memo=memo_abc)", [created])).toEqual([]);
+ expect(missingCreatedNoteLinks("[note:memo_abc]", [created])).toEqual([]);
+ });
+
+ test("ignores failed tools and links each successful creation once", () => {
+ expect(missingCreatedNoteLinks("", [
+ { ...created, status: "error" }, created, created,
+ ])).toHaveLength(1);
+ });
+});
diff --git a/apps/web/src/components/CompanionCreatedNoteLinks.tsx b/apps/web/src/components/CompanionCreatedNoteLinks.tsx
new file mode 100644
index 00000000..54ad6a95
--- /dev/null
+++ b/apps/web/src/components/CompanionCreatedNoteLinks.tsx
@@ -0,0 +1,51 @@
+import { createMemoLinkHref, parseMemoLinkHref, type CompanionToolCall } from "@edgeever/shared";
+
+export function missingCreatedNoteLinks(response: string, tools: CompanionToolCall[]) {
+ const linkedIds = new Set<string>();
+ for (const match of response.matchAll(/\[[^\]\n]+\]\(([^)\s]+)\)/g)) {
+ const memoId = parseMemoLinkHref(match[1]);
+ if (memoId) linkedIds.add(memoId);
+ }
+ for (const match of response.matchAll(/\[note:([^\]]+)\]/g)) linkedIds.add(match[1]);
+
+ const missing = new Map<string, { memoId: string; notebookId: string; title: string }>();
+ for (const tool of tools) {
+ if (tool.status !== "done") continue;
+ for (const effect of tool.effects) {
+ if (effect.kind !== "created" && effect.kind !== "merged") continue;
+ if (!effect.memoId || linkedIds.has(effect.memoId)) continue;
+ missing.set(effect.memoId, {
+ memoId: effect.memoId,
+ notebookId: effect.notebookId ?? "",
+ title: effect.title || effect.memoId,
+ });
+ }
+ }
+ return [...missing.values()];
+}
+
+export function CompanionCreatedNoteLinks({
+ response, tools, onOpenNote,
+}: {
+ response: string;
+ tools: CompanionToolCall[];
+ onOpenNote: (id: string, notebookId: string) => void;
+}) {
+ const links = missingCreatedNoteLinks(response, tools);
+ if (!links.length) return null;
+ return (
+ <ul className="space-y-1 text-sm">
+ {links.map(({ memoId, notebookId, title }) => (
+ <li key={memoId}>
+ <a
+ className="wrap-anywhere rounded-sm font-medium text-primary underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-400"
+ href={createMemoLinkHref(memoId)}
+ onClick={(event) => { event.preventDefault(); event.stopPropagation(); onOpenNote(memoId, notebookId); }}
+ >
+ {title}
+ </a>
+ </li>
+ ))}
+ </ul>
+ );
+}
diff --git a/apps/web/src/components/ai-sidebar/AiSidebar.tsx b/apps/web/src/components/ai-sidebar/AiSidebar.tsx
index 4a7f4835..5189e878 100644
--- a/apps/web/src/components/ai-sidebar/AiSidebar.tsx
+++ b/apps/web/src/components/ai-sidebar/AiSidebar.tsx
@@ -81,6 +81,7 @@ import {
} from "@/lib/selection-ai";
import { cn } from "@/lib/utils";
import { CompanionQuestionForm } from "../CompanionQuestionForm";
+import { CompanionCreatedNoteLinks } from "../CompanionCreatedNoteLinks";
import { AiSidebarMessage } from "./AiSidebarMessage";
import { AiSidebarLocalProcess } from "./AiSidebarLocalProcess";
import { BuiltinAgentStatus } from "./BuiltinAgentStatus";
@@ -1597,6 +1598,9 @@ function AiSidebarSession({
{linkedCompanionText(turn.response, turn)}
</AiSidebarMessage>
) : null}
+ {onOpenCompanionNote ? (
+ <CompanionCreatedNoteLinks response={turn.response} tools={turn.tools ?? []} onOpenNote={onOpenCompanionNote} />
+ ) : null}
{turn.status === "interrupted" && turn.questions?.length && !running ? (
<CompanionQuestionForm questions={turn.questions} busy={busy || acting} onSubmit={(answers) => resume(turn, answers)} />
) : null}
diff --git a/apps/web/src/components/ai-sidebar/sidebar-note-links.test.mjs b/apps/web/src/components/ai-sidebar/sidebar-note-links.test.mjs
index 02403ebb..6bfe60df 100644
--- a/apps/web/src/components/ai-sidebar/sidebar-note-links.test.mjs
+++ b/apps/web/src/components/ai-sidebar/sidebar-note-links.test.mjs
@@ -35,4 +35,14 @@ describe("sidebar note links", () => {
expect(rewritten).toContain("a&lt;b &quot;c&quot;");
expect(rewritten).not.toContain("<b");
});
+
+ test("turns a local agent's inline-code note ID into a workspace link", () => {
+ const id = "memo_b99f11cbeae74e558df1a1ce96ab8381";
+ const markdown = `已新建思维导图笔记(ID:\`${id}\`)。\n\n\`普通代码\`\n\n\`\`\`\n${id}\n\`\`\``;
+ const rewritten = rewriteSidebarNoteLinks(markdown);
+ expect(rewritten).toContain(`<edgeever-note data-memo-id="${id}">${id}</edgeever-note>`);
+ expect(rewritten).toContain("`普通代码`");
+ expect(rewritten).toContain(`\`\`\`\n${id}\n\`\`\``);
+ expect(render(markdown)).toContain(`href="#memo=${id}"`);
+ });
});
diff --git a/apps/web/src/components/ai-sidebar/sidebar-note-links.tsx b/apps/web/src/components/ai-sidebar/sidebar-note-links.tsx
index daf5f99e..a5790418 100644
--- a/apps/web/src/components/ai-sidebar/sidebar-note-links.tsx
+++ b/apps/web/src/components/ai-sidebar/sidebar-note-links.tsx
@@ -18,7 +18,12 @@ const escapeAttr = (value: string) => escapeText(value).replace(/"/g, "&quot;");
*/
export function rewriteSidebarNoteLinks(markdown: string): string {
return markdown.split(CODE_REGION).map((part, index) => {
- if (index % 2 === 1) return part;
+ if (index % 2 === 1) {
+ // Local agents sometimes report a new note only as an inline-code ID.
+ // Turn that exact ID into the same workspace link as a Markdown citation.
+ const memoId = /^`(memo_[0-9a-f]{32})`$/i.exec(part)?.[1];
+ return memoId ? `<edgeever-note data-memo-id="${memoId}">${memoId}</edgeever-note>` : part;
+ }
return part.replace(MARKDOWN_LINK, (match, label: string, href: string) => {
const memoId = parseMemoLinkHref(href);
if (!memoId) return match;