AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
feat(web): optimize companion discovery notifications and action cards UI
tianma-ifcffc6fb4970b
diff --git a/apps/web/src/components/CompanionActionCard.test.mjs b/apps/web/src/components/CompanionActionCard.test.mjsindex dc2674e9..312bc197 100644--- a/apps/web/src/components/CompanionActionCard.test.mjs+++ b/apps/web/src/components/CompanionActionCard.test.mjs@@ -22,8 +22,7 @@ async function render(overrides = {}, busy = false, lng = "zh-CN") {describe("companion suggestion cards", () => {test("keeps merging behind an explicit preview with consequences and source order", async () => {const html = await render();- expect(html).toContain("<details>");- expect(html).not.toContain("<details open");+ expect(html).toContain("合并后的标题:Ideas");expect(html).toContain("确认合并");expect(html).toContain("原公开分享失效");expect(html).toContain("不做 AI 改写或删减");diff --git a/apps/web/src/components/CompanionActionCard.tsx b/apps/web/src/components/CompanionActionCard.tsxindex 1f0d7837..ff0895f3 100644--- a/apps/web/src/components/CompanionActionCard.tsx+++ b/apps/web/src/components/CompanionActionCard.tsx@@ -1,7 +1,7 @@import type { CompanionAction } from "@edgeever/shared";+import { ArrowUpRight, Check, FileText, GitMerge } from "lucide-react";import { useTranslation } from "react-i18next";import { Button } from "@/components/ui/button";-import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";import { CompanionToolActionCard } from "./CompanionToolActionCard";export function CompanionActionCard({ action, busy, onApply, onDismiss, onOpenNote }: {@@ -14,29 +14,129 @@ export function CompanionActionCard({ action, busy, onApply, onDismiss, onOpenNoconst { t } = useTranslation();if (action.plan.kind === "tool") return <CompanionToolActionCard {...{ action, busy, onApply, onDismiss, onOpenNote }} />;const merge = action.plan.kind === "merge";- return <Card className="shadow-none" aria-label={t(merge ? "companion.actions.merge" : "companion.actions.tag")}>- <CardHeader className="p-3">- <CardTitle className="text-sm">{t(merge ? "companion.actions.merge" : "companion.actions.tag")}</CardTitle>- <CardDescription className="line-clamp-3 break-words">{action.plan.reason}</CardDescription>- </CardHeader>- <CardContent className="space-y-3 p-3 pt-0 text-sm">- {action.status === "pending" ? <div className="space-y-3">- {action.plan.kind === "merge" ? <p className="break-words font-medium">{t("companion.actions.resultTitle", { title: action.plan.title })}</p> : null}- <ol className="list-inside list-decimal space-y-3">- {action.notes.map(note => <li key={note.id}>- <Button size="sm" variant="ghost" disabled={busy} className="h-auto min-h-9 max-w-full justify-start whitespace-normal break-words py-1.5 text-left" onClick={() => onOpenNote(note.id, note.notebookId)}>{note.title || t("common.untitledMemo")}</Button>- <p className="mt-1 break-words text-xs text-slate-500">{note.excerpt}</p>- <p className="mt-1 break-words text-xs text-slate-500">{t("companion.actions.existingTags", { tags: note.tags.join(" · ") || "—" })}</p>- </li>)}- </ol>- {action.plan.kind === "tag" ? <p className="break-words text-emerald-700">{t("companion.actions.addTags", { tags: action.plan.tags.join(" · ") })}</p> : null}- <p className="text-xs leading-relaxed text-slate-600">{t(merge ? "companion.actions.mergeHelp" : "companion.actions.tagHelp")}</p>- </div> : <p role="status" className="text-xs text-slate-500">{t(`companion.actions.status.${action.status}`)}</p>}- {action.status === "pending" ? <div className="flex flex-wrap gap-2 border-t border-slate-200/60 pt-3 dark:border-slate-800">- <Button size="sm" disabled={busy} onClick={() => onApply(action)}>{t("companion.actions.confirm")}</Button>- <Button size="sm" variant="ghost" disabled={busy} onClick={() => onDismiss(action)}>{t("companion.actions.dismiss")}</Button>- </div> : null}- {action.status === "applied" && action.resultMemoId ? <Button size="sm" variant="outline" disabled={busy} onClick={() => onOpenNote(action.resultMemoId!, action.notes[0].notebookId)}>{t("companion.actions.openResult")}</Button> : null}- </CardContent>- </Card>;++ return (+ <div className="space-y-3 pt-0.5" aria-label={t(merge ? "companion.actions.merge" : "companion.actions.tag")}>+ <p className="line-clamp-3 whitespace-pre-wrap break-words text-xs leading-relaxed text-slate-600 sm:text-sm dark:text-slate-300">+ {action.plan.reason}+ </p>+ {action.status === "pending" ? (+ <div className="space-y-3">+ {action.plan.kind === "merge" ? (+ <div className="space-y-2 rounded-lg border border-slate-200/70 bg-slate-50/70 p-3 dark:border-slate-800 dark:bg-slate-900/50">+ <p className="break-words text-xs font-semibold text-slate-800 dark:text-slate-200">+ {t("companion.actions.resultTitle", { title: action.plan.title })}+ </p>+ <ol className="list-inside list-decimal space-y-2 pt-1.5 text-xs">+ {action.notes.map(note => (+ <li key={note.id} className="text-slate-700 dark:text-slate-300">+ <button+ type="button"+ disabled={busy}+ className="inline-flex max-w-full items-center gap-1 font-medium hover:text-emerald-600 hover:underline dark:hover:text-emerald-400"+ onClick={() => onOpenNote(note.id, note.notebookId)}+ >+ <FileText className="h-3 w-3 shrink-0 text-slate-400" />+ <span className="truncate">{note.title || t("common.untitledMemo")}</span>+ <ArrowUpRight className="h-2.5 w-2.5 shrink-0 opacity-50" />+ </button>+ {note.excerpt ? (+ <p className="mt-0.5 line-clamp-1 break-words text-[11px] text-slate-500 dark:text-slate-400">+ {note.excerpt}+ </p>+ ) : null}+ <p className="mt-0.5 break-words text-[10px] text-slate-400 dark:text-slate-500">+ {t("companion.actions.existingTags", { tags: note.tags.join(" · ") || "—" })}+ </p>+ </li>+ ))}+ </ol>+ </div>+ ) : (+ <div className="space-y-2 rounded-lg border border-slate-200/70 bg-slate-50/70 p-3 dark:border-slate-800 dark:bg-slate-900/50">+ {action.notes[0] ? (+ <div>+ <button+ type="button"+ disabled={busy}+ onClick={() => onOpenNote(action.notes[0].id, action.notes[0].notebookId)}+ className="group/note inline-flex max-w-full items-center gap-1.5 text-xs font-semibold text-slate-800 hover:text-emerald-600 dark:text-slate-200 dark:hover:text-emerald-400"+ >+ <FileText className="h-3.5 w-3.5 shrink-0 text-slate-400 group-hover/note:text-emerald-600 dark:group-hover/note:text-emerald-400" />+ <span className="truncate">{action.notes[0].title || t("common.untitledMemo")}</span>+ <ArrowUpRight className="h-3 w-3 shrink-0 opacity-40 group-hover/note:opacity-100" />+ </button>+ {action.notes[0].excerpt ? (+ <p className="mt-1 line-clamp-2 break-words text-xs text-slate-500 dark:text-slate-400">+ {action.notes[0].excerpt}+ </p>+ ) : null}+ </div>+ ) : null}+ <div className="space-y-1 border-t border-slate-200/50 pt-2 text-xs dark:border-slate-800">+ <p className="break-words font-medium text-emerald-700 dark:text-emerald-400">+ {t("companion.actions.addTags", { tags: action.plan.tags.join(" · ") })}+ </p>+ {action.notes[0] ? (+ <p className="break-words text-[11px] text-slate-400 dark:text-slate-500">+ {t("companion.actions.existingTags", { tags: action.notes[0].tags.join(" · ") || "—" })}+ </p>+ ) : null}+ </div>+ </div>+ )}++ <p className="text-[11px] leading-relaxed text-slate-400 dark:text-slate-500">+ {t(merge ? "companion.actions.mergeHelp" : "companion.actions.tagHelp")}+ </p>++ <div className="flex items-center justify-end gap-2 border-t border-slate-100 pt-2.5 dark:border-slate-800/80">+ <Button+ size="sm"+ variant="ghost"+ disabled={busy}+ onClick={() => onDismiss(action)}+ className="h-7 px-2.5 text-xs text-slate-500 hover:text-slate-700 dark:text-slate-400 dark:hover:text-slate-200"+ >+ {t("companion.actions.dismiss")}+ </Button>+ <Button+ size="sm"+ variant="solid"+ disabled={busy}+ onClick={() => onApply(action)}+ className="h-7 gap-1 px-3 text-xs"+ >+ {merge ? <GitMerge className="h-3 w-3" /> : <Check className="h-3 w-3" />}+ {t(merge ? "companion.actions.confirmMerge" : "companion.actions.confirmTags", {+ defaultValue: t("companion.actions.confirm"),+ })}+ </Button>+ </div>+ </div>+ ) : action.status === "applied" ? (+ <div className="flex items-center justify-between gap-2 rounded-lg border border-emerald-200/50 bg-emerald-50/60 p-2.5 text-xs text-emerald-700 dark:border-emerald-800/50 dark:bg-emerald-950/30 dark:text-emerald-300">+ <span className="flex items-center gap-1.5 font-medium">+ <Check className="h-3.5 w-3.5" />+ {t("companion.actions.status.applied")}+ </span>+ {action.resultMemoId ? (+ <Button+ size="sm"+ variant="outline"+ disabled={busy}+ onClick={() => onOpenNote(action.resultMemoId!, action.notes[0]?.notebookId ?? "")}+ className="h-6 px-2 text-xs"+ >+ {t("companion.actions.openResult")}+ </Button>+ ) : null}+ </div>+ ) : (+ <p role="status" className="text-xs text-slate-400 dark:text-slate-500">+ {t(`companion.actions.status.${action.status}`)}+ </p>+ )}+ </div>+ );}diff --git a/apps/web/src/components/CompanionDiscoveryHub.tsx b/apps/web/src/components/CompanionDiscoveryHub.tsxindex 3c684f87..15917880 100644--- a/apps/web/src/components/CompanionDiscoveryHub.tsx+++ b/apps/web/src/components/CompanionDiscoveryHub.tsx@@ -3,13 +3,17 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";import { useTranslation } from "react-i18next";import {ArrowUpRight,+ FilePlus,FileText,+ GitMerge,PawPrint,Settings,+ Sparkles,+ Tag,} from "lucide-react";import type { CompanionAction, CompanionDiscoveryItem } from "@edgeever/shared";import { Button } from "@/components/ui/button";-import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";+import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog";import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";import { api, ApiRequestError } from "@/lib/api";import { assertCompanionChangesSynced } from "@/lib/companion-actions";@@ -117,53 +121,63 @@ export default function CompanionDiscoveryHub({ scope, onOpenNote, onNotesChange</Tooltip></TooltipProvider><Dialog open={open} onOpenChange={setOpen}>- <DialogContent className="max-h-[85dvh] w-[calc(100%-2rem)] max-w-xl overflow-y-auto p-5 sm:p-6">- <DialogHeader className="space-y-2 pb-1">- <div className="flex items-center gap-2.5">- <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-emerald-50 text-emerald-600 ring-1 ring-emerald-500/20 dark:bg-emerald-950/50 dark:text-emerald-400 dark:ring-emerald-500/30">- <PawPrint className="h-4 w-4" strokeWidth={2.5} />- </div>- <div className="flex items-center gap-2">- <DialogTitle className="text-base font-semibold text-slate-900 dark:text-slate-100">- {t("companion.discovery.title")}- </DialogTitle>- {items.length > 0 ? (- <span className="inline-flex items-center rounded-full bg-emerald-50 px-2 py-0.5 text-xs font-medium text-emerald-700 ring-1 ring-inset ring-emerald-600/20 dark:bg-emerald-950/40 dark:text-emerald-300 dark:ring-emerald-500/30">- {items.length}- </span>- ) : null}+ <DialogContent className="grid max-h-[min(760px,calc(100dvh-2rem))] w-[calc(100%-2rem)] max-w-xl grid-rows-[auto_minmax(0,1fr)_auto] gap-0 overflow-hidden p-0">+ <DialogHeader className="border-b border-slate-100 px-5 py-4 text-left dark:border-slate-800">+ <div className="flex items-center justify-between pr-8">+ <div className="flex items-center gap-2.5">+ <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-emerald-50 text-emerald-600 ring-1 ring-emerald-500/20 dark:bg-emerald-950/50 dark:text-emerald-400 dark:ring-emerald-500/30">+ <PawPrint className="h-4 w-4" strokeWidth={2.5} />+ </div>+ <div className="flex items-center gap-2">+ <DialogTitle className="text-base font-semibold text-slate-900 dark:text-slate-100">+ {t("companion.discovery.title")}+ </DialogTitle>+ {items.length > 0 ? (+ <span className="inline-flex items-center rounded-full bg-emerald-50 px-2 py-0.5 text-xs font-medium text-emerald-700 ring-1 ring-inset ring-emerald-600/20 dark:bg-emerald-950/40 dark:text-emerald-300 dark:ring-emerald-500/30">+ {items.length}+ </span>+ ) : null}+ </div></div></div>+ <DialogDescription className="mt-1 text-xs text-slate-500 dark:text-slate-400">+ {t("companion.discovery.panelDescription")}+ </DialogDescription></DialogHeader>- {error ? (- <div role="alert" className="rounded-lg border border-red-200 bg-red-50/50 p-2.5 text-xs text-red-600 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-400">- {error}- </div>- ) : null}- {feed.isError ? (- <div role="alert" className="rounded-lg border border-red-200 bg-red-50/50 p-2.5 text-xs text-red-600 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-400">- {t("companion.discovery.loadFailed")}- </div>- ) : null}- {!feed.isPending && !feed.isError && !items.length ? (- <div className="flex flex-col items-center justify-center py-10 text-center">- <div className="mb-3 flex h-12 w-12 items-center justify-center rounded-2xl bg-slate-50 text-slate-400 ring-1 ring-slate-200 dark:bg-slate-900 dark:text-slate-500 dark:ring-slate-800">- <PawPrint className="h-6 w-6 stroke-[1.5]" />+ <div className="min-h-0 space-y-3.5 overflow-y-auto px-5 py-4">+ {error ? (+ <div role="alert" className="rounded-lg border border-red-200 bg-red-50/50 p-2.5 text-xs text-red-600 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-400">+ {error}</div>- <p className="max-w-xs text-sm font-medium text-slate-600 dark:text-slate-300">- {t("companion.discovery.empty")}- </p>- </div>- ) : null}- <div className="space-y-3.5">{items.map(item => <DiscoveryCard key={item.id} item={item} busy={busy} open={open}- onApply={apply} onDismiss={() => dismiss(item)} onOpenNote={openNote}- onSeen={() => { void api.acknowledgeCompanionDiscovery(item.id).then(() => client.setQueryData<CompanionDiscoveryItem[]>(discoveryFeedKey(scope),- current => current?.map(entry => entry.id === item.id ? { ...entry, seen: true } : entry))).catch(() => {}); }} />)}</div>- <div className="mt-2 flex justify-end border-t border-slate-100 pt-3 dark:border-slate-800">+ ) : null}+ {feed.isError ? (+ <div role="alert" className="rounded-lg border border-red-200 bg-red-50/50 p-2.5 text-xs text-red-600 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-400">+ {t("companion.discovery.loadFailed")}+ </div>+ ) : null}+ {!feed.isPending && !feed.isError && !items.length ? (+ <div className="flex flex-col items-center justify-center py-10 text-center">+ <div className="mb-3 flex h-12 w-12 items-center justify-center rounded-2xl bg-slate-50 text-slate-400 ring-1 ring-slate-200 dark:bg-slate-900 dark:text-slate-500 dark:ring-slate-800">+ <PawPrint className="h-6 w-6 stroke-[1.5]" />+ </div>+ <p className="max-w-xs text-sm font-medium text-slate-600 dark:text-slate-300">+ {t("companion.discovery.empty")}+ </p>+ </div>+ ) : null}+ {items.map(item => <DiscoveryCard key={item.id} item={item} busy={busy} open={open}+ onApply={apply} onDismiss={() => dismiss(item)} onOpenNote={openNote}+ onSeen={() => { void api.acknowledgeCompanionDiscovery(item.id).then(() => client.setQueryData<CompanionDiscoveryItem[]>(discoveryFeedKey(scope),+ current => current?.map(entry => entry.id === item.id ? { ...entry, seen: true } : entry))).catch(() => {}); }} />)}+ </div>+ <div className="flex items-center justify-between border-t border-slate-100 bg-slate-50/50 px-5 py-2.5 text-xs text-slate-400 dark:border-slate-800 dark:bg-slate-900/50 dark:text-slate-500">+ <span className="max-w-[320px] truncate">+ {t("companion.discovery.tagline")}+ </span><Buttonsize="sm"variant="ghost"- className="h-8 shrink-0 gap-1.5 text-xs text-slate-600 hover:text-slate-900 dark:text-slate-400 dark:hover:text-slate-100"+ className="h-7 shrink-0 gap-1.5 px-2 text-xs text-slate-600 hover:text-slate-900 dark:text-slate-400 dark:hover:text-slate-100"onClick={() => { setOpen(false); onOpenSettings(); }}><Settings className="h-3.5 w-3.5" />@@ -198,32 +212,104 @@ function DiscoveryCard({ item, busy, open, onApply, onDismiss, onOpenNote, onSee}): null;- return <article ref={ref} className="group relative flex flex-col gap-3 rounded-xl border border-slate-200/80 bg-slate-50/50 p-4 transition-colors hover:border-slate-300 hover:bg-slate-50/80 dark:border-slate-800 dark:bg-slate-900/40 dark:hover:border-slate-700">- {formattedDate ? <span className="self-end text-[11px] text-slate-400 dark:text-slate-500">{formattedDate}</span> : null}- <h3 className="line-clamp-1 break-words text-sm font-semibold leading-snug text-slate-900 dark:text-slate-100">{item.title}</h3>- {!item.action ? <p className="line-clamp-3 whitespace-pre-wrap break-words text-sm leading-relaxed text-slate-600 dark:text-slate-300">{item.body}</p> : null}- {item.kind === "append" ? <p className="rounded-lg border border-emerald-100 bg-emerald-50/50 p-2.5 text-xs leading-relaxed text-emerald-700 dark:border-emerald-900/40 dark:bg-emerald-950/30 dark:text-emerald-400">{t("companion.discovery.appendHelp")}</p> : null}- {item.action ? <CompanionActionCard action={item.action} busy={busy} onApply={onApply} onDismiss={onDismiss} onOpenNote={onOpenNote} />- : item.sources.length > 0 ? (+ const typeBadge = (() => {+ if (item.kind === "insight") {+ return (+ <span className="inline-flex items-center gap-1 rounded-md bg-sky-50 px-2 py-0.5 text-[11px] font-medium text-sky-700 ring-1 ring-inset ring-sky-600/20 dark:bg-sky-950/40 dark:text-sky-300 dark:ring-sky-500/30">+ <Sparkles className="h-3 w-3" />+ {t("companion.discovery.types.insight", { defaultValue: "灵感关联" })}+ </span>+ );+ }+ if (item.kind === "merge" || item.action?.plan.kind === "merge") {+ return (+ <span className="inline-flex items-center gap-1 rounded-md bg-amber-50 px-2 py-0.5 text-[11px] font-medium text-amber-700 ring-1 ring-inset ring-amber-600/20 dark:bg-amber-950/40 dark:text-amber-300 dark:ring-amber-500/30">+ <GitMerge className="h-3 w-3" />+ {t("companion.discovery.types.merge", { defaultValue: "合并建议" })}+ </span>+ );+ }+ if (item.kind === "append") {+ return (+ <span className="inline-flex items-center gap-1 rounded-md bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-700 ring-1 ring-inset ring-emerald-600/20 dark:bg-emerald-950/40 dark:text-emerald-300 dark:ring-emerald-500/30">+ <FilePlus className="h-3 w-3" />+ {t("companion.discovery.types.append", { defaultValue: "补入建议" })}+ </span>+ );+ }+ return (+ <span className="inline-flex items-center gap-1 rounded-md bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-700 ring-1 ring-inset ring-emerald-600/20 dark:bg-emerald-950/40 dark:text-emerald-300 dark:ring-emerald-500/30">+ <Tag className="h-3 w-3" />+ {t("companion.discovery.types.tag", { defaultValue: "标签建议" })}+ </span>+ );+ })();++ return (+ <article+ ref={ref}+ className="group relative flex flex-col gap-3 rounded-xl border border-slate-200/90 bg-white p-4 shadow-xs transition-all hover:border-slate-300 hover:shadow-sm dark:border-slate-800 dark:bg-slate-900/60 dark:hover:border-slate-700"+ >+ <div className="flex items-start justify-between gap-3">+ <div className="flex min-w-0 flex-wrap items-center gap-2">+ {typeBadge}+ <h3 className="line-clamp-1 break-words text-sm font-semibold leading-snug text-slate-900 dark:text-slate-100">+ {item.title}+ </h3>+ </div>+ {formattedDate ? (+ <time className="shrink-0 pt-0.5 font-mono text-[11px] text-slate-400 dark:text-slate-500">+ {formattedDate}+ </time>+ ) : null}+ </div>+ {!item.action ? (+ <p className="line-clamp-4 whitespace-pre-wrap break-words text-xs leading-relaxed text-slate-600 sm:text-sm dark:text-slate-300">+ {item.body}+ </p>+ ) : null}+ {item.kind === "append" ? (+ <p className="rounded-lg border border-emerald-100 bg-emerald-50/50 p-2.5 text-xs leading-relaxed text-emerald-700 dark:border-emerald-900/40 dark:bg-emerald-950/30 dark:text-emerald-400">+ {t("companion.discovery.appendHelp")}+ </p>+ ) : null}+ {item.action ? (+ <CompanionActionCard+ action={item.action}+ busy={busy}+ onApply={onApply}+ onDismiss={onDismiss}+ onOpenNote={onOpenNote}+ />+ ) : item.sources.length > 0 ? (<div className="flex flex-wrap items-center gap-1.5 pt-0.5">{item.sources.map(source => (<buttonkey={source.id}type="button"onClick={() => onOpenNote(source.id, source.notebookId)}- className="inline-flex max-w-full items-center gap-1.5 rounded-lg border border-slate-200 bg-white px-2.5 py-1 text-xs font-medium text-slate-700 shadow-xs transition-colors hover:border-emerald-400 hover:bg-emerald-50/40 hover:text-emerald-700 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-300 dark:hover:border-emerald-600 dark:hover:bg-emerald-950/30 dark:hover:text-emerald-300"+ className="group/btn inline-flex max-w-full items-center gap-1.5 rounded-lg border border-slate-200/80 bg-slate-50/70 px-2.5 py-1 text-xs font-medium text-slate-700 shadow-2xs transition-colors hover:border-emerald-400 hover:bg-emerald-50/50 hover:text-emerald-700 dark:border-slate-700 dark:bg-slate-800/80 dark:text-slate-300 dark:hover:border-emerald-600 dark:hover:bg-emerald-950/30 dark:hover:text-emerald-300">- <FileText className="h-3 w-3 shrink-0 text-slate-400" />- <span className="truncate max-w-[260px]">{source.title || t("common.untitledMemo")}</span>- <ArrowUpRight className="h-3 w-3 shrink-0 opacity-40 hover:opacity-100" />+ <FileText className="h-3 w-3 shrink-0 text-slate-400 group-hover/btn:text-emerald-600 dark:group-hover/btn:text-emerald-400" />+ <span className="max-w-[260px] truncate">{source.title || t("common.untitledMemo")}</span>+ <ArrowUpRight className="h-3 w-3 shrink-0 opacity-40 group-hover/btn:opacity-100" /></button>))}</div>) : null}- {!item.action ? <div className="flex items-center justify-end border-t border-slate-200/60 pt-2.5 dark:border-slate-800">- <Button size="sm" variant="ghost" disabled={busy} onClick={onDismiss} className="h-7 px-2 text-xs text-slate-400 hover:text-slate-700 dark:hover:text-slate-200">- {t("companion.discovery.dismiss")}- </Button>- </div> : null}- </article>;+ {!item.action ? (+ <div className="flex items-center justify-end border-t border-slate-100 pt-2.5 dark:border-slate-800/80">+ <Button+ size="sm"+ variant="ghost"+ disabled={busy}+ onClick={onDismiss}+ className="h-7 px-2 text-xs text-slate-400 hover:text-slate-700 dark:hover:text-slate-200"+ >+ {t("companion.discovery.dismiss")}+ </Button>+ </div>+ ) : null}+ </article>+ );}diff --git a/apps/web/src/components/CompanionToolActionCard.tsx b/apps/web/src/components/CompanionToolActionCard.tsxindex a8cff99d..2e887df8 100644--- a/apps/web/src/components/CompanionToolActionCard.tsx+++ b/apps/web/src/components/CompanionToolActionCard.tsx@@ -1,7 +1,7 @@import type { CompanionAction } from "@edgeever/shared";+import { ArrowUpRight, Check, FileText } from "lucide-react";import { useTranslation } from "react-i18next";import { Button } from "@/components/ui/button";-import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";export function CompanionToolActionCard({ action, busy, onApply, onDismiss, onOpenNote }: {action: CompanionAction; busy: boolean;@@ -20,32 +20,120 @@ export function CompanionToolActionCard({ action, busy, onApply, onDismiss, onOpreturn JSON.stringify(value, null, 2);};const special = ["merge_memos", "trash_memos", "rename_tag", "delete_tag", "update_memo", "restore_memo_revision"].includes(name);- return <Card className="shadow-none" aria-label={title}>- <CardHeader className="p-3"><CardTitle className="text-sm">{title}</CardTitle>- <CardDescription className="line-clamp-3 break-words">{action.plan.reason}</CardDescription></CardHeader>- <CardContent className="space-y-3 p-3 pt-0 text-sm">- {action.status === "pending" ? <div className="space-y-3">- {action.preview?.affectedCount ? <p>{t("companion.actions.affected", { count: action.preview.affectedCount })}</p> : null}- {action.notes.map(note => <div key={note.id}>- <Button variant="ghost" size="sm" className="h-auto max-w-full whitespace-normal break-words text-left" disabled={busy}- onClick={() => onOpenNote(note.id, note.notebookId)}>{note.title || t("common.untitledMemo")}</Button>- <p className="break-words text-xs text-muted-foreground">{note.excerpt}</p>- </div>)}- <dl className="space-y-2">{Object.entries(action.plan.arguments).map(([key, value]) => <div key={key}>- <dt className="font-medium">{t(`companion.actions.fields.${key}`, { defaultValue: key })}</dt>- <dd className="max-h-64 overflow-y-auto whitespace-pre-wrap break-words rounded bg-muted p-2 text-xs">{display(value)}</dd>- </div>)}</dl>- {special ? <p className="text-xs text-destructive">{t(`companion.actions.effects.${name}`)}</p> : null}- <p className="text-xs text-muted-foreground">{t("companion.actions.toolHelp")}</p>- </div> : <p role="status" className="text-xs text-muted-foreground">{t(`companion.actions.status.${action.status}`)}</p>}- {action.status === "pending" ? <div className="flex flex-wrap gap-2 border-t pt-3">- <Button size="sm" disabled={busy} onClick={() => onApply(action)}>{t("companion.actions.confirm")}</Button>- <Button size="sm" variant="ghost" disabled={busy} onClick={() => onDismiss(action)}>{t("companion.actions.dismiss")}</Button>- </div> : null}- {action.status === "applied" && action.resultMemoId && action.resultNotebookId ? <Button variant="outline" size="sm" disabled={busy}- onClick={() => onOpenNote(action.resultMemoId!, action.resultNotebookId!)}>{t("companion.actions.openResult")}</Button> : null}- {action.status === "applied" && action.result ? <details><summary className="cursor-pointer">{t("companion.actions.receipt")}</summary>- <pre className="mt-2 max-h-48 overflow-y-auto whitespace-pre-wrap break-words text-xs">{JSON.stringify(action.result, null, 2)}</pre></details> : null}- </CardContent>- </Card>;++ return (+ <div className="space-y-3 pt-0.5" aria-label={title}>+ <div className="space-y-1">+ <h4 className="text-xs font-semibold text-slate-900 dark:text-slate-100">{title}</h4>+ <p className="line-clamp-3 whitespace-pre-wrap break-words text-xs leading-relaxed text-slate-600 dark:text-slate-300">{action.plan.reason}</p>+ </div>+ {action.status === "pending" ? (+ <div className="space-y-2.5">+ {action.preview?.affectedCount ? (+ <p className="text-xs font-medium text-slate-500 dark:text-slate-400">+ {t("companion.actions.affected", { count: action.preview.affectedCount })}+ </p>+ ) : null}+ {action.notes.length > 0 ? (+ <div className="space-y-1.5 rounded-lg border border-slate-200/70 bg-slate-50/70 p-2.5 dark:border-slate-800 dark:bg-slate-900/50">+ {action.notes.map(note => (+ <div key={note.id}>+ <button+ type="button"+ disabled={busy}+ onClick={() => onOpenNote(note.id, note.notebookId)}+ className="inline-flex max-w-full items-center gap-1 text-xs font-medium text-slate-800 hover:text-emerald-600 hover:underline dark:text-slate-200 dark:hover:text-emerald-400"+ >+ <FileText className="h-3 w-3 shrink-0 text-slate-400" />+ <span className="truncate">{note.title || t("common.untitledMemo")}</span>+ <ArrowUpRight className="h-2.5 w-2.5 shrink-0 opacity-50" />+ </button>+ {note.excerpt ? (+ <p className="line-clamp-1 break-words text-[11px] text-slate-500 dark:text-slate-400">+ {note.excerpt}+ </p>+ ) : null}+ </div>+ ))}+ </div>+ ) : null}+ <dl className="space-y-2 text-xs">+ {Object.entries(action.plan.arguments).map(([key, value]) => (+ <div key={key}>+ <dt className="font-medium text-slate-700 dark:text-slate-300">+ {t(`companion.actions.fields.${key}`, { defaultValue: key })}+ </dt>+ <dd className="mt-1 max-h-48 overflow-y-auto whitespace-pre-wrap break-words rounded bg-slate-100/80 p-2 text-[11px] text-slate-800 dark:bg-slate-800 dark:text-slate-200">+ {display(value)}+ </dd>+ </div>+ ))}+ </dl>+ {special ? (+ <p className="rounded-lg border border-rose-200/60 bg-rose-50/60 p-2.5 text-xs text-rose-600 dark:border-rose-900/40 dark:bg-rose-950/30 dark:text-rose-400">+ {t(`companion.actions.effects.${name}`)}+ </p>+ ) : null}+ <p className="text-[11px] leading-relaxed text-slate-400 dark:text-slate-500">+ {t("companion.actions.toolHelp")}+ </p>+ <div className="flex items-center justify-end gap-2 border-t border-slate-100 pt-2.5 dark:border-slate-800/80">+ <Button+ size="sm"+ variant="ghost"+ disabled={busy}+ onClick={() => onDismiss(action)}+ className="h-7 px-2.5 text-xs text-slate-500 hover:text-slate-700 dark:text-slate-400 dark:hover:text-slate-200"+ >+ {t("companion.actions.dismiss")}+ </Button>+ <Button+ size="sm"+ variant="solid"+ disabled={busy}+ onClick={() => onApply(action)}+ className="h-7 gap-1 px-3 text-xs"+ >+ <Check className="h-3 w-3" />+ {t("companion.actions.confirmTool", { defaultValue: t("companion.actions.confirm") })}+ </Button>+ </div>+ </div>+ ) : action.status === "applied" ? (+ <div className="space-y-2">+ <div className="flex items-center justify-between gap-2 rounded-lg border border-emerald-200/50 bg-emerald-50/60 p-2.5 text-xs text-emerald-700 dark:border-emerald-800/50 dark:bg-emerald-950/30 dark:text-emerald-300">+ <span className="flex items-center gap-1.5 font-medium">+ <Check className="h-3.5 w-3.5" />+ {t("companion.actions.status.applied")}+ </span>+ {action.resultMemoId && action.resultNotebookId ? (+ <Button+ variant="outline"+ size="sm"+ disabled={busy}+ onClick={() => onOpenNote(action.resultMemoId!, action.resultNotebookId!)}+ className="h-6 px-2 text-xs"+ >+ {t("companion.actions.openResult")}+ </Button>+ ) : null}+ </div>+ {action.result ? (+ <details className="text-xs text-slate-500">+ <summary className="cursor-pointer hover:text-slate-800 dark:hover:text-slate-200">+ {t("companion.actions.receipt")}+ </summary>+ <pre className="mt-2 max-h-48 overflow-y-auto whitespace-pre-wrap break-words rounded bg-slate-100 p-2 text-[11px] dark:bg-slate-800">+ {JSON.stringify(action.result, null, 2)}+ </pre>+ </details>+ ) : null}+ </div>+ ) : (+ <p role="status" className="text-xs text-slate-400 dark:text-slate-500">+ {t(`companion.actions.status.${action.status}`)}+ </p>+ )}+ </div>+ );}diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.tsindex b6a14cdb..36dbfe5d 100644--- a/packages/shared/src/i18n/en-US.ts+++ b/packages/shared/src/i18n/en-US.ts@@ -22,6 +22,7 @@ export const enUS = {appendHelp: "Appends the fragment's original text to the target note and keeps both notes. No automatic deletion or rewriting. Currently suggested for plain-text notes only.",dismiss: "Skip this",kind: { insight: "Knowledge connection · No action needed", merge: "Suggestion · Combine ideas", append: "Suggestion · Add to an existing note" },+ types: { insight: "Insight", tag: "Tags", merge: "Merge", append: "Append", tool: "Action" },checkStatus: { quiet: "Checks happen as needed and may incur model charges. No useful result means no notification.", ready: "The latest check completed.", running: "Checking related notes.", failed: "The latest check did not finish. Check your default model and connection; this attempt is not retried automatically." },transparency: {title: "Paw status",@@ -38,6 +39,9 @@ export const enUS = {},"actions": {"confirm": "Confirm",+ "confirmMerge": "Confirm merge",+ "confirmTags": "Confirm additional tags",+ "confirmTool": "Confirm this operation","receipt": "View execution record","affected": "Affects {{count}} notes","toolHelp": "Only the listed arguments will execute; AI does not decide again at confirmation. Suggestions expire after 24 hours. Note or notebook changes require a fresh proposal. Multi-write operations do not guarantee a complete rollback; uncertain results are never automatically replayed.",diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.tsindex 6b9d5ea5..7b664af3 100644--- a/packages/shared/src/i18n/zh-CN.ts+++ b/packages/shared/src/i18n/zh-CN.ts@@ -22,6 +22,7 @@ export const zhCN = {appendHelp: "将随手记的正文原样追加到目标笔记末尾,保留两篇原笔记;不自动删除或改写。本期仅对纯文字笔记生成此建议。",dismiss: "略过这条",kind: { insight: "知识关联 · 无需操作", merge: "整理建议 · 合并点子", append: "整理建议 · 补入已有笔记" },+ types: { insight: "灵感关联", tag: "标签建议", merge: "合并建议", append: "补入建议", tool: "操作建议" },checkStatus: { quiet: "检查按需发生,可能产生模型费用;没有有价值的结果就保持安静。", ready: "最近一次检查已完成。", running: "正在检查相关笔记。", failed: "最近一次检查未完成。请检查默认模型和网络;同一轮检查不自动重试。" },transparency: {title: "猫爪状态",@@ -38,6 +39,9 @@ export const zhCN = {},"actions": {"confirm": "确认",+ "confirmMerge": "确认合并",+ "confirmTags": "确认追加标签",+ "confirmTool": "确认执行此操作","receipt": "查看执行记录","affected": "涉及 {{count}} 篇笔记","toolHelp": "仅执行上面列出的参数,不会在确认时让 AI 重新决定。建议 24 小时后失效;生成方案后笔记或笔记本发生变化,需要重新生成。多次写入的操作不保证整体撤销,结果不确定时不会自动重跑。",