Skip to content

Self-hosted MCP server + dashboard giving Claude Code, Cursor & Hermes agents shared long-term memory over a git-backed markdown vault. Agent-native, Obsidian-compatible second brain — markdown RAG, no vector DB.

feat(home): state-aware home — search-first brain home + recents

Ronalds Palacis521b7817cb34
diff --git a/app/(app)/page.tsx b/app/(app)/page.tsx
index a93e731..dccd824 100644
--- a/app/(app)/page.tsx
+++ b/app/(app)/page.tsx
@@ -2,13 +2,15 @@
import Link from "next/link";
import useSWR, { useSWRConfig } from "swr";
-import { useEffect, useState } from "react";
-import { ArrowRight, Brain, Check, GitBranch, Plug, RefreshCw } from "lucide-react";
-import { fetcher } from "@/lib/client";
+import { useEffect, useRef, useState } from "react";
+import { ArrowRight, Brain, Check, GitBranch, Plug, Search } from "lucide-react";
+import { fetcher, folderColor } from "@/lib/client";
import { CuratorChat } from "@/components/curator-chat";
import { ActivityList, type ActivityEntry } from "@/components/activity-list";
+import { RecentNotes } from "@/components/recent-notes";
import { Card } from "@/components/ui/card";
import { Switch } from "@/components/ui/switch";
+import { Input } from "@/components/ui/input";
interface Repo {
id: string;
@@ -29,8 +31,20 @@ interface Settings {
harnessEnabledFlag: boolean;
anthropicApiKeySet: boolean;
}
+interface Stats {
+ notes: number;
+ folders: number;
+ links: number;
+}
+interface Hit {
+ path: string;
+ title: string;
+ folder: string;
+ type?: string;
+}
const iconBox = "flex size-9 shrink-0 items-center justify-center rounded-lg border border-border text-muted-foreground";
+const APP_NAME_FALLBACK = process.env.NEXT_PUBLIC_APP_NAME || "Engram";
function StatusDot({ ok, label }: { ok?: boolean; label: string }) {
return (
@@ -41,19 +55,7 @@ function StatusDot({ ok, label }: { ok?: boolean; label: string }) {
);
}
-function PillarBody({
- icon,
- title,
- desc,
- state,
- ok,
-}: {
- icon: React.ReactNode;
- title: string;
- desc: string;
- state?: string;
- ok?: boolean;
-}) {
+function PillarBody({ icon, title, desc, state, ok }: { icon: React.ReactNode; title: string; desc: string; state?: string; ok?: boolean }) {
return (
<>
<div className={iconBox}>{icon}</div>
@@ -68,16 +70,7 @@ function PillarBody({
);
}
-/** Navigational pillar — the whole card links somewhere. */
-function LinkPillar(props: {
- icon: React.ReactNode;
- title: string;
- desc: string;
- state?: string;
- ok?: boolean;
- href: string;
- cta: string;
-}) {
+function LinkPillar(props: { icon: React.ReactNode; title: string; desc: string; state?: string; ok?: boolean; href: string; cta: string }) {
return (
<Link href={props.href} className="block">
<Card className="group flex-row items-center gap-4 p-4 transition-colors hover:border-ring">
@@ -92,17 +85,7 @@ function LinkPillar(props: {
);
}
-/** Feature pillar with an inline on/off Switch + optional footer note. */
-function TogglePillar(props: {
- icon: React.ReactNode;
- title: string;
- desc: string;
- state?: string;
- ok?: boolean;
- on: boolean;
- onToggle: (v: boolean) => void;
- footer?: React.ReactNode;
-}) {
+function TogglePillar(props: { icon: React.ReactNode; title: string; desc: string; state?: string; ok?: boolean; on: boolean; onToggle: (v: boolean) => void; footer?: React.ReactNode }) {
return (
<Card className="gap-0 overflow-hidden p-0">
<div className="flex items-center gap-4 p-4">
@@ -114,8 +97,6 @@ function TogglePillar(props: {
);
}
-const APP_NAME_FALLBACK = process.env.NEXT_PUBLIC_APP_NAME || "Engram";
-
export default function Home() {
const { mutate } = useSWRConfig();
const { data: repos } = useSWR<{ repos: Repo[]; active: Repo | null }>("/api/repos", fetcher);
@@ -123,13 +104,14 @@ export default function Home() {
const { data: feat } = useSWR<{ harness?: boolean; mcpAuthRequired?: boolean; appName?: string }>("/api/features", fetcher);
const { data: tok } = useSWR<{ tokens: { id: string }[] }>("/api/tokens", fetcher);
const { data: settings } = useSWR<Settings>("/api/settings", fetcher);
- const { data: activity } = useSWR<{ activity: ActivityEntry[] }>("/api/activity?limit=10", fetcher, { refreshInterval: 15000 });
+ const { data: activity } = useSWR<{ activity: ActivityEntry[] }>("/api/activity?limit=8", fetcher, { refreshInterval: 15000 });
+ const { data: stats } = useSWR<Stats>("/api/stats", fetcher);
const active = repos?.active ?? null;
const appName = feat?.appName || APP_NAME_FALLBACK;
const tokenCount = tok?.tokens?.length ?? 0;
- // Toggle state mirrors the saved settings; hydrate once they arrive.
+ // Toggle state mirrors saved settings; hydrate once they arrive.
const [gitSyncOn, setGitSyncOn] = useState(false);
const [curatorOn, setCuratorOn] = useState(false);
useEffect(() => {
@@ -138,6 +120,34 @@ export default function Home() {
setCuratorOn(settings.harnessEnabledFlag);
}, [settings]);
+ // Inline search over the vault.
+ const [q, setQ] = useState("");
+ const [results, setResults] = useState<Hit[]>([]);
+ const [searching, setSearching] = useState(false);
+ const searchSeq = useRef(0);
+ useEffect(() => {
+ const query = q.trim();
+ if (!query) {
+ setResults([]);
+ setSearching(false);
+ return;
+ }
+ setSearching(true);
+ const seq = ++searchSeq.current;
+ const t = setTimeout(async () => {
+ try {
+ const r = await fetch(`/api/search?q=${encodeURIComponent(query)}`);
+ const d = await r.json();
+ if (seq === searchSeq.current) setResults(d.results ?? []);
+ } catch {
+ if (seq === searchSeq.current) setResults([]);
+ } finally {
+ if (seq === searchSeq.current) setSearching(false);
+ }
+ }, 150);
+ return () => clearTimeout(t);
+ }, [q]);
+
async function patch(body: Record<string, unknown>, ...keys: string[]) {
await fetch("/api/settings", { method: "PUT", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
for (const k of keys) mutate(k);
@@ -154,104 +164,154 @@ export default function Home() {
// Curator on → the home is a chat window over your brain.
if (feat?.harness) return <CuratorChat />;
+ const recent = activity?.activity ?? [];
+
+ // ── No vault connected → focused onboarding (the one time setup belongs front-and-center). ──
+ if (!active) {
+ const curatorNeedsKey = curatorOn && !settings?.anthropicApiKeySet;
+ return (
+ <div className="scrollbar-none h-full overflow-y-auto">
+ <div className="mx-auto flex min-h-full max-w-2xl flex-col px-8 py-12">
+ <div className="my-auto space-y-6">
+ <div>
+ <div className="flex items-center gap-2">
+ <div className="size-2 rounded-full bg-primary" />
+ <h1 className="text-lg font-semibold tracking-tight">{appName}</h1>
+ </div>
+ <p className="mt-1.5 text-sm text-muted-foreground">
+ A second brain your agents read and write — a git repo of markdown, live over MCP. Connect a vault to begin.
+ </p>
+ </div>
+ <div className="space-y-2.5">
+ <LinkPillar
+ icon={<GitBranch size={16} />}
+ title="Vault"
+ ok={false}
+ state="not connected"
+ desc="Connect a git repo of markdown — the source of truth for humans and agents. Start here."
+ href="/workspaces"
+ cta="Connect a repo"
+ />
+ <LinkPillar
+ icon={<Plug size={16} />}
+ title="Agents"
+ ok={tokenCount > 0}
+ state={tokenCount > 0 ? `${tokenCount} token${tokenCount === 1 ? "" : "s"}` : "none yet"}
+ desc="Point Claude Code, Cursor, Hermes, or Claude.ai at the MCP endpoint to read + write this brain."
+ href="/connect"
+ cta={tokenCount > 0 ? "Manage" : "Connect an agent"}
+ />
+ <TogglePillar
+ icon={<Brain size={16} />}
+ title="Curator"
+ ok={false}
+ state={curatorNeedsKey ? "needs API key" : curatorOn ? "on" : "off · optional"}
+ desc="An optional chat agent that reads your notes to answer. Turn it on anytime."
+ on={curatorOn}
+ onToggle={toggleCurator}
+ footer={
+ curatorNeedsKey ? (
+ <>
+ Add your Anthropic API key in{" "}
+ <Link href="/settings" className="text-foreground underline underline-offset-2">Settings</Link> to activate it.
+ </>
+ ) : undefined
+ }
+ />
+ </div>
+ <p className="text-center text-xs text-muted-foreground">
+ Press <kbd className="rounded border border-border px-1.5 py-0.5 font-mono text-[11px]">⌘K</kbd> to search the sample vault.
+ </p>
+ </div>
+ </div>
+ </div>
+ );
+ }
+
+ // ── Vault connected → the "brain home": search-first, with recents + activity. ──
const gitDetail = sync?.error
? "sync error"
: sync?.ahead || sync?.behind || sync?.dirty
? `${sync?.dirty || 0} local · ↑${sync?.ahead || 0} ↓${sync?.behind || 0}`
: "synced";
- const gitState = !active ? "no vault yet" : gitSyncOn ? gitDetail : "off";
- const gitOk = !!active && gitSyncOn && !sync?.error;
-
- const curatorNeedsKey = curatorOn && !settings?.anthropicApiKeySet;
- const recent = activity?.activity ?? [];
return (
<div className="scrollbar-none h-full overflow-y-auto">
- <div className="mx-auto flex min-h-full max-w-2xl flex-col px-8 py-12">
- <div className="my-auto space-y-6">
- <div>
- <div className="flex items-center gap-2">
- <div className="size-2 rounded-full bg-primary" />
- <h1 className="text-lg font-semibold tracking-tight">{appName}</h1>
- </div>
- <p className="mt-1.5 text-sm text-muted-foreground">
- A second brain your agents read and write — a git repo of markdown, live over MCP.
- </p>
+ <div className="mx-auto max-w-2xl px-8 py-12">
+ <div className="flex items-baseline justify-between gap-4">
+ <div className="flex items-center gap-2">
+ <div className="size-2 rounded-full bg-primary" />
+ <h1 className="text-lg font-semibold tracking-tight">{appName}</h1>
</div>
+ {stats && (
+ <p className="text-xs text-muted-foreground">
+ {stats.notes} notes · {stats.folders} folders · {stats.links} links
+ </p>
+ )}
+ </div>
- <div className="flex flex-col gap-2.5">
- <LinkPillar
- icon={<GitBranch size={16} />}
- title="Vault"
- ok={!!active}
- state={active ? active.name : "not connected"}
- desc={active ? "Your notes live in this git repo — versioned and portable." : "Connect a git repo of markdown — the source of truth for humans and agents."}
- href="/workspaces"
- cta={active ? "Manage" : "Connect a repo"}
- />
- <TogglePillar
- icon={<RefreshCw size={16} />}
- title="Git sync"
- ok={gitOk}
- state={gitState}
- desc="Auto commit + push every change to the vault's remote. Author + advanced options in Settings."
- on={gitSyncOn}
- onToggle={toggleGitSync}
- footer={
- gitSyncOn && !active ? (
- <>
- Connect a vault in{" "}
- <Link href="/workspaces" className="text-foreground underline underline-offset-2">Workspaces</Link>{" "}
- to start syncing.
- </>
- ) : undefined
- }
- />
- <LinkPillar
- icon={<Plug size={16} />}
- title="Agents"
- ok={tokenCount > 0}
- state={tokenCount > 0 ? `${tokenCount} token${tokenCount === 1 ? "" : "s"}` : "none yet"}
- desc="Point Claude Code, Cursor, Hermes, or Claude.ai at the MCP endpoint to read + write this brain."
- href="/connect"
- cta={tokenCount > 0 ? "Manage" : "Connect an agent"}
- />
- <TogglePillar
- icon={<Brain size={16} />}
- title="Curator"
- ok={false}
- state={curatorNeedsKey ? "needs API key" : curatorOn ? "on" : "off"}
- desc="A chat agent that reads your notes to answer, and files rough dumps into the right place."
- on={curatorOn}
- onToggle={toggleCurator}
- footer={
- curatorNeedsKey ? (
- <>
- Add your Anthropic API key in{" "}
- <Link href="/settings" className="text-foreground underline underline-offset-2">Settings</Link>{" "}
- to activate it.
- </>
- ) : undefined
- }
- />
- </div>
+ <div className="relative mt-6">
+ <Search size={15} className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" />
+ <Input
+ value={q}
+ onChange={(e) => setQ(e.target.value)}
+ placeholder="Search your brain…"
+ className="h-11 pl-9 text-sm"
+ aria-label="Search your brain"
+ />
+ </div>
- {recent.length > 0 && (
- <section>
- <div className="mb-1 flex items-center justify-between">
- <h2 className="text-sm font-medium">Recent activity</h2>
- <Link href="/activity" className="inline-flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground">
- View all <ArrowRight size={12} />
- </Link>
- </div>
- <ActivityList entries={recent} />
- </section>
- )}
+ {q.trim() ? (
+ <div className="mt-3 overflow-hidden rounded-lg border border-border">
+ {results.length === 0 ? (
+ <p className="px-3 py-3 text-sm text-muted-foreground">{searching ? "Searching…" : "No matches."}</p>
+ ) : (
+ <ul className="divide-y divide-border">
+ {results.slice(0, 10).map((r) => (
+ <li key={r.path}>
+ <Link href={`/n/${r.path}`} className="flex items-center gap-2.5 px-3 py-2 transition-colors hover:bg-accent/60">
+ <span className="size-1.5 shrink-0 rounded-full" style={{ background: folderColor(r.folder) }} />
+ <span className="truncate text-sm">{r.title}</span>
+ <span className="ml-auto max-w-[45%] shrink-0 truncate font-mono text-xs text-muted-foreground">{r.path}</span>
+ </Link>
+ </li>
+ ))}
+ </ul>
+ )}
+ </div>
+ ) : (
+ <div className="mt-8 space-y-8">
+ <RecentNotes heading="Jump back in" />
+ {recent.length > 0 && (
+ <section>
+ <div className="mb-1 flex items-center justify-between">
+ <h2 className="text-sm font-medium">Recent activity</h2>
+ <Link href="/activity" className="inline-flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground">
+ View all <ArrowRight size={12} />
+ </Link>
+ </div>
+ <ActivityList entries={recent} />
+ </section>
+ )}
+ </div>
+ )}
- <p className="text-center text-xs text-muted-foreground">
- Select a note, or press{" "}
- <kbd className="rounded border border-border px-1.5 py-0.5 font-mono text-[11px]">⌘K</kbd> to search.
- </p>
+ {/* Neutral controls — settings, not a checklist. */}
+ <div className="mt-10 flex flex-wrap items-center gap-x-5 gap-y-2 border-t border-border pt-4 text-xs text-muted-foreground">
+ <label className="flex items-center gap-2">
+ <Switch checked={gitSyncOn} onCheckedChange={toggleGitSync} />
+ <span>Git sync {gitSyncOn ? <span className="text-muted-foreground/70">· {gitDetail}</span> : null}</span>
+ </label>
+ <label className="flex items-center gap-2">
+ <Switch checked={curatorOn} onCheckedChange={toggleCurator} />
+ <span>Curator {curatorOn && !settings?.anthropicApiKeySet ? <span className="text-amber-500/80">· needs key</span> : null}</span>
+ </label>
+ <Link href="/connect" className="inline-flex items-center gap-1 transition-colors hover:text-foreground">
+ <Plug size={12} /> {tokenCount > 0 ? `${tokenCount} agent${tokenCount === 1 ? "" : "s"}` : "Connect an agent"}
+ </Link>
+ <Link href="/settings" className="inline-flex items-center gap-1 transition-colors hover:text-foreground">
+ Settings
+ </Link>
</div>
</div>
</div>
diff --git a/app/api/stats/route.ts b/app/api/stats/route.ts
new file mode 100644
index 0000000..408360f
--- /dev/null
+++ b/app/api/stats/route.ts
@@ -0,0 +1,10 @@
+import { getGraph, listNotes } from "@/lib/vault/store";
+
+export const dynamic = "force-dynamic";
+
+/** Light vault stats for the home: note / folder / link counts. */
+export function GET() {
+ const notes = listNotes();
+ const folders = new Set(notes.map((n) => n.folder).filter((f) => f && f !== "root"));
+ return Response.json({ notes: notes.length, folders: folders.size, links: getGraph().edges.length });
+}
diff --git a/components/curator-chat.tsx b/components/curator-chat.tsx
index f06e6e9..7ccbbd4 100644
--- a/components/curator-chat.tsx
+++ b/components/curator-chat.tsx
@@ -8,6 +8,7 @@ import { Markdown } from "@/components/markdown";
import { CURATOR_MODELS, DEFAULT_CURATOR_MODEL } from "@/lib/models";
import { fetcher } from "@/lib/client";
import { ActivityList, type ActivityEntry } from "@/components/activity-list";
+import { RecentNotes } from "@/components/recent-notes";
import { Button } from "@/components/ui/button";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
@@ -180,17 +181,20 @@ export function CuratorChat() {
</div>
{error && <p className="mt-2 text-xs text-destructive">{error}</p>}
- {recent.length > 0 && (
- <section className="mt-12">
- <div className="mb-1 flex items-center justify-between">
- <h2 className="text-sm font-medium">Recent activity</h2>
- <Link href="/activity" className="inline-flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground">
- View all <ArrowRight size={12} />
- </Link>
- </div>
- <ActivityList entries={recent} />
- </section>
- )}
+ <div className="mt-12 space-y-8">
+ <RecentNotes heading="Jump back in" />
+ {recent.length > 0 && (
+ <section>
+ <div className="mb-1 flex items-center justify-between">
+ <h2 className="text-sm font-medium">Recent activity</h2>
+ <Link href="/activity" className="inline-flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground">
+ View all <ArrowRight size={12} />
+ </Link>
+ </div>
+ <ActivityList entries={recent} />
+ </section>
+ )}
+ </div>
</div>
</div>
);
diff --git a/components/note-view.tsx b/components/note-view.tsx
index 2319ab8..2a4f497 100644
--- a/components/note-view.tsx
+++ b/components/note-view.tsx
@@ -6,6 +6,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
import { Check, Columns2, Eye, Pencil } from "lucide-react";
import { fetcher, folderColor, type Note, type NoteMeta } from "@/lib/client";
import { cn } from "@/lib/utils";
+import { recordView } from "@/lib/recents";
import { Markdown } from "./markdown";
type Mode = "preview" | "edit" | "split";
@@ -83,6 +84,11 @@ export function NoteView({ path }: { path: string }) {
const note = data?.note;
+ // Track this note in the browser's "recently viewed" list (localStorage only).
+ useEffect(() => {
+ if (note?.title) recordView(path, note.title, path.includes("/") ? path.split("/")[0] : "root");
+ }, [path, note?.title]);
+
async function persist(content: string) {
setSave("saving");
try {
diff --git a/components/recent-notes.tsx b/components/recent-notes.tsx
new file mode 100644
index 0000000..fb23768
--- /dev/null
+++ b/components/recent-notes.tsx
@@ -0,0 +1,40 @@
+"use client";
+
+import Link from "next/link";
+import useSWR from "swr";
+import { fetcher, folderColor } from "@/lib/client";
+import { useRecents } from "@/lib/recents";
+
+/** "Jump back in" — the notes you viewed most recently (from localStorage). Renders nothing when empty. */
+export function RecentNotes({ heading = "Jump back in", limit = 6 }: { heading?: string; limit?: number }) {
+ const recents = useRecents();
+ // Hide recents that aren't in the current vault (deleted, or a different workspace) so a
+ // stale entry never leads to a 404. Reuses the cached notes list (SWR dedupes it).
+ const { data: all } = useSWR<{ notes: { path: string }[] }>("/api/notes", fetcher);
+ const valid = all ? new Set(all.notes.map((n) => n.path)) : null;
+ const items = (valid ? recents.filter((r) => valid.has(r.path)) : recents).slice(0, limit);
+ if (items.length === 0) return null;
+ return (
+ <section>
+ <h2 className="mb-2 text-sm font-medium">{heading}</h2>
+ <div className="grid gap-2 sm:grid-cols-2">
+ {items.map((r) => {
+ const folder = r.folder || (r.path.includes("/") ? r.path.split("/")[0] : "root");
+ return (
+ <Link
+ key={r.path}
+ href={`/n/${r.path}`}
+ className="flex items-center gap-2.5 rounded-lg border border-border bg-card px-3 py-2 transition-colors hover:border-ring"
+ >
+ <span className="size-1.5 shrink-0 rounded-full" style={{ background: folderColor(folder) }} />
+ <span className="min-w-0 flex-1">
+ <span className="block truncate text-sm">{r.title}</span>
+ <span className="block truncate text-xs text-muted-foreground">{folder}</span>
+ </span>
+ </Link>
+ );
+ })}
+ </div>
+ </section>
+ );
+}
diff --git a/lib/recents.ts b/lib/recents.ts
new file mode 100644
index 0000000..36d0b1e
--- /dev/null
+++ b/lib/recents.ts
@@ -0,0 +1,58 @@
+"use client";
+
+import { useEffect, useState } from "react";
+
+/**
+ * Recently-viewed notes, tracked entirely in the browser (localStorage) — a private,
+ * per-device "jump back in" list. Not synced, not sent anywhere; it's a convenience for the
+ * human at the dashboard, independent of the vault/git. Newest first, deduped by path.
+ */
+export interface RecentNote {
+ path: string;
+ title: string;
+ folder?: string;
+ at: number;
+}
+
+const KEY = "engram:recents";
+const MAX = 12;
+const EVENT = "engram:recents-changed";
+
+export function getRecents(): RecentNote[] {
+ if (typeof window === "undefined") return [];
+ try {
+ const list = JSON.parse(localStorage.getItem(KEY) || "[]");
+ return Array.isArray(list) ? list : [];
+ } catch {
+ return [];
+ }
+}
+
+/** Record a note as just-viewed (moves it to the front). Fires an event so open lists refresh. */
+export function recordView(path: string, title: string, folder?: string): void {
+ if (typeof window === "undefined" || !path) return;
+ const list = getRecents().filter((r) => r.path !== path);
+ list.unshift({ path, title: title || path, folder, at: Date.now() });
+ try {
+ localStorage.setItem(KEY, JSON.stringify(list.slice(0, MAX)));
+ window.dispatchEvent(new Event(EVENT));
+ } catch {
+ /* storage full / disabled — non-fatal */
+ }
+}
+
+/** Subscribe to the recents list (updates on view + across tabs). */
+export function useRecents(): RecentNote[] {
+ const [recents, setRecents] = useState<RecentNote[]>([]);
+ useEffect(() => {
+ const read = () => setRecents(getRecents());
+ read();
+ window.addEventListener(EVENT, read);
+ window.addEventListener("storage", read);
+ return () => {
+ window.removeEventListener(EVENT, read);
+ window.removeEventListener("storage", read);
+ };
+ }, []);
+ return recents;
+}