Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(ui): check in the two-tab Profile rebuild
rubenluetke10-beep4f17ca99ffe2
diff --git a/jarvis/ui/web/frontend/src/views/ProfileView.tsx b/jarvis/ui/web/frontend/src/views/ProfileView.tsxindex 0c35ec3d84..de357fbb3e 100644--- a/jarvis/ui/web/frontend/src/views/ProfileView.tsx+++ b/jarvis/ui/web/frontend/src/views/ProfileView.tsx@@ -1,1642 +1,224 @@/**- * ProfileView — the profile as ONE view, never a scrolling page.+ * ProfileView — what Jarvis knows about you, and the file it keeps it in.*- * Layout doctrine: the whole section is a single viewport. Nothing here is- * reached by scrolling the page; the view is a thin identity strip over three- * standing rails that each scroll inside themselves only when their own- * content overflows.+ * Two tabs, because the view answers two different questions and mixing them+ * was the old layout's mistake: "what does it know about me" is a ledger of+ * fields, "what does the file say" is a document. They shared one screen as+ * three standing rails, which meant neither got a readable width and both were+ * permanently half-visible.*- * ┌───────────────────────────────────────────────────────────────────┐- * │ ViewHeader │- * ├───────────────────────────────────────────────────────────────────┤- * │ [portrait] who you are · stage things learned · people │- * ├────────────────────┬──────────────────────┬───────────────────────┤- * │ The Ledger │ The Source │ The Margin │- * │ every cluster, │ USER.md rendered as │ the open question, │- * │ every field, │ the document it is, │ the review queue, │- * │ editable in place │ editable in place │ the people │- * └────────────────────┴──────────────────────┴───────────────────────┘+ * ┌──────────────────────────────────────────────────────────────────┐+ * │ PageHeader — Profile · refresh · [ Knowledge | Source file ] │+ * ├──────────────────────────────────────────────────────────────────┤+ * │ Identity card — portrait, address, stage, progress, people │+ * ├───────────────────────────────────┬──────────────────────────────┤+ * │ Cluster cards, two columns │ Rail: the open question, │+ * │ every field, editable in place │ the review queue, the people │+ * └───────────────────────────────────┴──────────────────────────────┘*- * The two halves of the middle answer different questions and are worth- * seeing at the same time: the ledger is USER.md's front matter as structured- * fields, the source rail is the prose the curator writes underneath it. That- * pairing is why the file is rendered in place rather than hidden behind a- * button — reading the profile and reading the file are the same act.+ * Below 1280 px the rail becomes a row under the ledger, and below 1024 px+ * everything is one column. The header never scrolls; the body below it does.*- * The single non-negotiable of that shape is an unbroken `min-h-0` chain from- * the root to each rail: a flex/grid child defaults to `min-height: auto` and- * refuses to shrink below its content, which is what silently turns a- * "one viewport" layout back into a scrolling page.+ * The raw-file query and its live WS subscription are held HERE rather than in+ * the source tab, so a Curator write still refreshes the ledger while the+ * reader is looking at the knowledge tab.*/-import { useEffect, useMemo, useRef, useState } from "react";-import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";-import ReactMarkdown from "react-markdown";-import remarkGfm from "remark-gfm";-import {- UserCircle2,- Users as UsersIcon,- Inbox,- RefreshCw,- Check,- X,- ShieldQuestion,- Sparkles,- Mic,- FileText,- Clock,- ChevronRight,- ChevronDown,- Lock,- Pencil,- Plus,- Save,- Camera,- Trash2,- Loader2,-} from "lucide-react";-import { ViewHeader } from "@/views/ChatsView";+import { useState } from "react";+import { useQuery } from "@tanstack/react-query";+import { AlertTriangle, RefreshCw, UserCircle2 } from "lucide-react";++import { PageHeader } from "@/components/layout/PageHeader";+import { TabBar } from "@/components/layout/SectionTabBar";import { Button } from "@/components/ui/button";-import { Badge } from "@/components/ui/badge";-import { IdentityAvatar } from "@/components/identity/IdentityAvatar";-import { useEventStore } from "@/store/events";-import { cn } from "@/lib/utils";-import { getWSClient } from "@/hooks/useWebSocket";+import { EmptyState } from "@/components/ui/empty-state";import { useT } from "@/i18n";-import { PROSE_BASE, splitFrontMatter } from "@/components/outputs/MarkdownProse";-import {- CLUSTER_FIELD_KEYS,- CLUSTER_ORDER,- TOTAL_FIELDS,- acquaintanceStage,- collectOpenQuestions,- countFilled,- displayAddress,- fieldKind,- isEmptyValue,- type ClusterId,-} from "@/views/profile/ledger";--// -----------------------------------------------------------------------// Types — mirror the backend responses from profile_routes.py-// ------------------------------------------------------------------------interface ProfileResponse {- user: {- name: string | null;- meta: Record<string, unknown>;- path: string;- };- people: PersonSummary[];- reviews_count: number;- has_avatar?: boolean;-}--interface PersonSummary {- name: string;- relationship: string;- aliases: string[];- slug: string;-}--interface ReviewCandidate {- idx: number;- subject: string;- is_person: boolean;- person_name: string | null;- cluster: string;- field: string;- value: unknown;- operation: string;- confidence: number;- evidence: string;- relationship: string | null;- reason: string;-}--interface ReviewsResponse {- reviews: ReviewCandidate[];- total: number;-}--interface RawProfileResponse {- content: string;- path: string;- mtime_ms: number | null;- size_bytes: number;-}--// -----------------------------------------------------------------------// Fetching helpers-// ------------------------------------------------------------------------async function fetchJson<T>(url: string, init?: RequestInit): Promise<T> {- const res = await fetch(url, init);- if (!res.ok) {- if (res.status === 503) {- const data = await res.json().catch(() => ({ detail: "Profile system not ready." }));- const err = new Error(data.detail ?? `HTTP ${res.status}`) as Error & { status?: number };- err.status = 503;- throw err;- }- const txt = await res.text().catch(() => "");- throw new Error(`HTTP ${res.status}: ${txt || res.statusText}`);- }- return res.json();-}--// -----------------------------------------------------------------------// Small shared helpers-// ------------------------------------------------------------------------function clusterDataOf(meta: Record<string, unknown>, cid: ClusterId): Record<string, unknown> {- const raw = meta[cid];- return raw && typeof raw === "object" ? (raw as Record<string, unknown>) : {};-}+import { cn } from "@/lib/utils";+import { AskCard } from "@/views/profile/AskCard";+import { IdentityCard } from "@/views/profile/IdentityCard";+import { KnowledgeLedger } from "@/views/profile/KnowledgeLedger";+import { PeopleCard } from "@/views/profile/PeopleCard";+import { ReviewsCard } from "@/views/profile/ReviewsCard";+import { SourceCard, useSourceDocument } from "@/views/profile/SourceCard";+import { fetchJson, statusOf, type ProfileResponse } from "@/views/profile/api";-/** Render a field value for display; booleans go through i18n yes/no. */-function renderValue(t: (k: string) => string, value: unknown): string {- if (Array.isArray(value)) return value.map(String).join(" · ");- if (typeof value === "boolean") {- return value ? t("profile_view.value_yes") : t("profile_view.value_no");- }- return String(value ?? "");-}+type TabId = "knowledge" | "source";-function Dot() {- return <span className="px-1.5 text-muted-foreground">·</span>;-}--/**- * A group's heading. It used to be an 11px all-caps label over a hairline —- * the exact construction that makes an interface read as an admin panel, and- * twelve of them shared one viewport here. It is now a plain title, and the- * 32px between groups does the separating a rule used to do badly.- */-function RailHeading({- title,- count,- right,-}: {- title: string;- count?: string | number;- right?: React.ReactNode;-}) {- return (- <div className="flex items-baseline gap-2">- <h3 className="text-sm font-medium uppercase tracking-wide text-foreground-faint">{title}</h3>- {count !== undefined && count !== "" && (- <span className="text-sm tabular-nums text-foreground-faint">{count}</span>- )}- <span className="ml-auto flex items-center">{right}</span>- </div>- );-}--// -----------------------------------------------------------------------// ProfileView — Root-// ----------------------------------------------------------------------+/** The main grid: ledger left, rail right, and one column below 1280 px. */+const SPLIT = "grid gap-5 xl:grid-cols-[minmax(0,1fr)_336px]";+/** The rail: a row of cards under the ledger until it can stand beside it. */+const RAIL = "grid gap-5 content-start sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-1";export function ProfileView() {const t = useT();+ const [tab, setTab] = useState<TabId>("knowledge");+const { data, isLoading, error, refetch, isRefetching } = useQuery<ProfileResponse, Error>({queryKey: ["profile"],queryFn: () => fetchJson<ProfileResponse>("/api/profile"),retry: false,});+ // Held at the root on purpose — see the module note.+ const source = useSourceDocument();+const meta = (data?.user.meta ?? {}) as Record<string, unknown>;return (- <div className="relative flex h-full flex-col overflow-hidden bg-background">- <ViewHeader- icon={<UserCircle2 className="h-4 w-4" />}- title={t("profile_view.title")}- subtitle={t("profile_view.subtitle")}- right={- <Button- size="sm"- variant="ghost"- onClick={() => refetch()}- disabled={isRefetching}- title={t("profile_view.reload_tooltip")}- >- <RefreshCw className={cn("h-4 w-4", isRefetching && "animate-spin")} />- </Button>- }- />-- {isLoading && <LoadingState />}- {error && <ErrorState error={error} onRetry={() => refetch()} />}+ <div className="flex h-full flex-col overflow-hidden bg-background">+ <div className="shrink-0 px-8">+ <PageHeader+ icon={<UserCircle2 />}+ title={t("profile_view.title")}+ description={t("profile_view.subtitle")}+ actions={+ <Button+ type="button"+ size="icon"+ variant="ghost"+ className="text-muted-foreground"+ onClick={() => refetch()}+ disabled={isRefetching}+ title={t("profile_view.reload_tooltip")}+ aria-label={t("profile_view.reload_tooltip")}+ >+ <RefreshCw className={cn(isRefetching && "animate-spin")} />+ </Button>+ }+ tabs={+ <TabBar+ tabs={[+ { id: "knowledge", label: t("profile_view.section_knowledge") },+ { id: "source", label: t("profile_view.section_source") },+ ]}+ active={tab}+ onChange={(id) => setTab(id as TabId)}+ />+ }+ />+ </div>- {data && (- <>- <IdentityStrip data={data} meta={meta} />+ <div className="min-h-0 flex-1 overflow-y-auto px-8 pb-8 pt-6 scrollbar-jarvis">+ {isLoading && <ProfileSkeleton label={t("common.loading")} />}- {/* One viewport. On lg+ the three rails stand side by side and- scroll individually; below that they stack and the container- takes over the scrolling — the honest degradation for a window- too narrow to hold three rails at a readable width.+ {error && <ProfileErrorState error={error} onRetry={() => refetch()} />}- Each rail carries its own ground rather than a hairline: the two- standing rails take --sidebar, the document in the middle keeps- --background. That is the reference layout (a rail is lighter- than the stage it flanks) and it is the only separation device- that survives at these widths — a full-height column is far too- wide to earn --card. */}- <div- className={cn(- "grid min-h-0 flex-1 grid-cols-1 overflow-y-auto scrollbar-jarvis",- "lg:grid-cols-[minmax(360px,1fr)_minmax(0,1.25fr)]",- "lg:overflow-hidden",- )}- >- <LedgerRail meta={meta} />- {/* Two columns (v4): the source, with the "would love to know"- prompt and the review queue stacked under it as cards. */}- <div className="flex min-w-0 flex-col lg:min-h-0 lg:overflow-y-auto scrollbar-jarvis">- <SourceRail />- <MarginRail data={data} meta={meta} />+ {data && tab === "knowledge" && (+ <div className="flex flex-col gap-5">+ <IdentityCard data={data} meta={meta} onOpenSource={() => setTab("source")} />+ <div className={SPLIT}>+ <KnowledgeLedger meta={meta} />+ <aside className={RAIL}>+ <AskCard meta={meta} />+ <ReviewsCard reviewsCount={data.reviews_count} />+ <PeopleCard people={data.people} />+ </aside></div></div>- </>- )}- </div>- );-}--// -----------------------------------------------------------------------// Identity strip — the portrait and who you are, on one line-// -----------------------------------------------------------------------//-// Everything a person needs to recognise the page as theirs, in the height of-// a toolbar: the portrait (which is also the upload control), how Jarvis-// addresses them, the acquaintance stage, and the two counts. It replaced a-// full-height left rail built around a generative mark — that rail spent a-// third of the viewport on ornament, and ornament is not what this view is-// for. The facts stayed; the furniture went.--function IdentityStrip({- data,- meta,-}: {- data: ProfileResponse;- meta: Record<string, unknown>;-}) {- const t = useT();- const name = data.user.name?.trim() || null;-- const filled = useMemo(() => countFilled(meta), [meta]);- const stage = acquaintanceStage(filled, TOTAL_FIELDS);-- // Address the user the way they asked to be addressed ("Chef"), falling- // back to their first name — warmer than the full legal name.- const address = displayAddress(meta, name);- const headline = address- ? t(`profile_view.stage_headline.${stage.key}`).replace("{0}", `, ${address}`)- : t("profile_view.hero_name_placeholder");-- const ratio = t("profile_view.entries_ratio")- .replace("{0}", String(filled))- .replace("{1}", String(TOTAL_FIELDS));-- const peopleLine =- data.people.length === 1- ? t("profile_view.person_known").replace("{0}", "1")- : t("profile_view.people_known").replace("{0}", String(data.people.length));-- return (- <div className="profile-rise mx-8 mb-5 flex items-center gap-4 rounded-lg border border-border bg-card p-5">- <AvatarButton name={name} hasAvatar={!!data.has_avatar} />-- <div className="flex min-w-0 flex-col gap-0.5">- <h1 className="truncate text-xl font-semibold text-foreground-strong">{headline}</h1>- <span className="text-base text-muted-foreground">- {t(`profile_view.stages.${stage.key}`)}- </span>- </div>-- <div className="ml-auto flex shrink-0 items-center text-sm text-muted-foreground">- <span- className="mr-3 hidden h-1.5 w-40 overflow-hidden rounded-full bg-secondary sm:block"- role="progressbar"- aria-valuemin={0}- aria-valuemax={TOTAL_FIELDS}- aria-valuenow={filled}- data-testid="profile-progress"- >- <span- className="block h-full rounded-full bg-accent"- style={{ width: `${Math.round((filled / Math.max(TOTAL_FIELDS, 1)) * 100)}%` }}- />- </span>- <span className="tabular-nums text-foreground">{ratio}</span>- <Dot />- {peopleLine}- {data.reviews_count > 0 && (- <>- <Dot />- <span className="text-foreground">- {data.reviews_count} {t("profile_view.reviews_count")}- </span>- </>)}- </div>- </div>- );-}-// -----------------------------------------------------------------------// AvatarButton — the portrait, and the whole upload control-// -----------------------------------------------------------------------//-// The avatar bytes live under user_data_dir()/data and are served by-// GET /api/profile/avatar (see profile_routes.py). A hidden <input-// type="file"> is .click()'d to open the OS picker; a cache-bust query-// param forces the <img> to reload after a replace/delete.-//-// At strip height there is no room for labelled buttons, so the portrait is-// the control: click to pick a file, and a small remove badge appears on-// hover or keyboard focus once there is a picture to remove.--function AvatarButton({ name, hasAvatar }: { name: string | null; hasAvatar: boolean }) {- const t = useT();- const queryClient = useQueryClient();- const pushToast = useEventStore((s) => s.pushToast);- const inputRef = useRef<HTMLInputElement | null>(null);- const [bust, setBust] = useState(0);-- const upload = useMutation({- mutationFn: async (file: File) => {- const fd = new FormData();- fd.append("file", file);- const res = await fetch("/api/profile/avatar", { method: "POST", body: fd });- if (!res.ok) {- const body = (await res.json().catch(() => ({}))) as { detail?: string };- throw new Error(body.detail ?? `HTTP ${res.status}`);- }- return res.json();- },- onSuccess: () => {- setBust(Date.now());- pushToast("success", t("profile_view.avatar_uploaded"));- queryClient.invalidateQueries({ queryKey: ["profile"] });- },- onError: (err: Error) => pushToast("error", err.message),- });-- const remove = useMutation({- mutationFn: async () => {- const res = await fetch("/api/profile/avatar", { method: "DELETE" });- if (!res.ok) throw new Error(`HTTP ${res.status}`);- return res.json();- },- onSuccess: () => {- setBust(Date.now());- pushToast("info", t("profile_view.avatar_removed"));- queryClient.invalidateQueries({ queryKey: ["profile"] });- },- onError: (err: Error) => pushToast("error", err.message),- });-- const openPicker = () => inputRef.current?.click();-- const onFileChosen = (e: React.ChangeEvent<HTMLInputElement>) => {- const file = e.target.files?.[0];- // Reset so picking the *same* file again still fires onChange.- e.target.value = "";- if (file) upload.mutate(file);- };-- const busy = upload.isPending || remove.isPending;-- return (- <div className="group/avatar relative shrink-0">- <input- ref={inputRef}- type="file"- accept="image/png,image/jpeg,image/webp,image/gif"- className="hidden"- aria-hidden="true"- tabIndex={-1}- onChange={onFileChosen}- />- <button- type="button"- onClick={openPicker}- disabled={busy}- title={hasAvatar ? t("profile_view.avatar_change") : t("profile_view.avatar_upload")}- aria-label={hasAvatar ? t("profile_view.avatar_change") : t("profile_view.avatar_upload")}- className="relative flex h-12 w-12 items-center justify-center overflow-hidden rounded-full bg-secondary outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring"- >- {/* The person's own coloured mark, not a grey disc: identity is one of- the three jobs colour has, and this is the app's own owner. */}- {name ? (- <IdentityAvatar- name={name}- src={hasAvatar ? `/api/profile/avatar?t=${bust}` : null}- alt={t("profile_view.avatar_alt")}- />- ) : hasAvatar ? (- <img- src={`/api/profile/avatar?t=${bust}`}- alt={t("profile_view.avatar_alt")}- className="h-full w-full object-cover"- draggable={false}- />- ) : (- <UserCircle2 className="h-6 w-6 text-muted-foreground" />- )}-- <span className="pointer-events-none absolute inset-0 flex items-center justify-center rounded-full bg-scrim/70 opacity-0 transition-opacity duration-200 group-hover/avatar:opacity-100 group-focus-visible/avatar:opacity-100">- <Camera className="h-3.5 w-3.5 text-foreground-strong" />- </span>-- {busy && (- <span className="absolute inset-0 flex items-center justify-center rounded-full bg-scrim/70">- <Loader2 className="h-3.5 w-3.5 animate-spin text-foreground-strong" />- </span>- )}- </button>-- {hasAvatar && (- <button- type="button"- onClick={() => remove.mutate()}- disabled={busy}- title={t("profile_view.avatar_remove")}- aria-label={t("profile_view.avatar_remove")}- className="absolute -bottom-1 -right-1 rounded-full bg-secondary p-1 text-muted-foreground opacity-0 outline-none transition-all hover:text-destructive focus-visible:opacity-100 group-hover/avatar:opacity-100"- >- <Trash2 className="h-2.5 w-2.5" />- </button>- )}- </div>- );-}--// -----------------------------------------------------------------------// The Ledger — every cluster, every field, nothing behind a tab-// -----------------------------------------------------------------------//-// The old view capped blanks at two per card and stacked five cards down a-// scrolling page. In a one-viewer the opposite is right: eighteen fields fit-// a viewport comfortably in two columns, so everything the ledger holds is-// visible at once and a blank line is as informative as a written one.--function LedgerRail({ meta }: { meta: Record<string, unknown> }) {- const t = useT();-- return (- <section className="flex min-w-0 flex-col border-r border-border px-8 pb-6 pt-1 lg:min-h-0 lg:overflow-y-auto scrollbar-jarvis">- <div className="profile-rise" style={{ animationDelay: "60ms" }}>- <h2 className="text-lg font-semibold text-foreground-strong">- {t("profile_view.section_knowledge")}- </h2>- <p className="mt-1 text-base text-muted-foreground">- {t("profile_view.section_knowledge_sub")}- </p>+ {data && tab === "source" && <SourceCard doc={source} />}</div>-- {/* One continuous run of clusters, separated by the 32px group step.- The per-cluster blurb and the "3/4 filled" counter that used to sit- under every heading were both removed: the blurb restated the field- names below it, and nobody acts on a per-cluster count — the strip- at the top already says how complete the profile is. */}- <div className="mt-group space-y-group">- {CLUSTER_ORDER.map((cid, i) => (- <div- key={cid}- className="profile-rise"- style={{ animationDelay: `${100 + i * 45}ms` }}- >- <ClusterGroup cid={cid} meta={meta} />- </div>- ))}- </div>- </section>- );-}--function ClusterGroup({ cid, meta }: { cid: ClusterId; meta: Record<string, unknown> }) {- const t = useT();- const data = clusterDataOf(meta, cid);- const fields = CLUSTER_FIELD_KEYS[cid];-- return (- <div>- <RailHeading title={t(`profile_view.clusters.${cid}.label`)} />- {/* Every row carries its own quiet pencil — learned fields can be- overwritten or cleared, blank ones filled in, all edited in place. */}- <dl className="mt-stack">- {fields.map((key) => (- <EditableFieldRow key={key} cid={cid} fieldKey={key} value={data[key]} />- ))}- </dl></div>);}// -----------------------------------------------------------------------// Inline field editing — a quiet pencil per field, edited in place+// Loading and failure// -----------------------------------------------------------------------type FieldOp = "set" | "clear" | "append" | "remove";--/** Shared mutation for PATCH /api/profile/field. Invalidates the profile query- * on success so the card re-renders with the persisted value. */-function useFieldEdit() {- const queryClient = useQueryClient();- const pushToast = useEventStore((s) => s.pushToast);- return useMutation({- mutationFn: async (body: {- cluster: ClusterId;- field: string;- operation: FieldOp;- value?: unknown;- }) => {- const res = await fetch("/api/profile/field", {- method: "PATCH",- headers: { "Content-Type": "application/json" },- body: JSON.stringify(body),- });- if (!res.ok) {- const data = (await res.json().catch(() => ({}))) as { detail?: string };- throw new Error(data.detail ?? `HTTP ${res.status}`);- }- return res.json();- },- onSuccess: () => queryClient.invalidateQueries({ queryKey: ["profile"] }),- onError: (err: Error) => pushToast("error", err.message),- });-}--function IconBtn({- icon: Icon,- onClick,- title,- tone = "muted",- disabled,-}: {- icon: typeof Check;- onClick: () => void;- title: string;- tone?: "muted" | "primary" | "danger";- disabled?: boolean;-}) {- // --primary is a FILL, never an ink: the affirmative action is a filled- // square, the other two are ghosts that answer hover by stepping up.- const toneCls =- tone === "primary"- ? "bg-primary text-primary-foreground"- : tone === "danger"- ? "text-muted-foreground hover:bg-secondary hover:text-destructive"- : "text-muted-foreground hover:bg-secondary hover:text-foreground";- return (- <button- type="button"- onClick={onClick}- title={title}- aria-label={title}- disabled={disabled}- className={cn(- "shrink-0 rounded-md p-1 outline-none transition-colors focus-visible:ring-2 focus-visible:ring-border-strong disabled:opacity-40",- toneCls,- )}- >- <Icon className="h-3.5 w-3.5" />- </button>- );-}--/** One field row with inline editing: a hover-revealed pencil opens an in-place- * editor whose shape depends on the field kind (scalar text, yes/no toggle, or- * removable chips for lists). Persists through PATCH /api/profile/field. */-function EditableFieldRow({- cid,- fieldKey,- value,-}: {- cid: ClusterId;- fieldKey: string;- value: unknown;-}) {- const t = useT();- const pushToast = useEventStore((s) => s.pushToast);- const edit = useFieldEdit();- const kind = fieldKind(fieldKey);- const empty = isEmptyValue(value);- const label = t(`profile_view.fields.${fieldKey}`);-- const [editing, setEditing] = useState(false);- const [draft, setDraft] = useState("");- const inputRef = useRef<HTMLInputElement | null>(null);-- useEffect(() => {- if (editing) inputRef.current?.focus();- }, [editing]);-- const busy = edit.isPending;- const toast = () => pushToast("success", t("profile_view.field_saved"));-- const startEdit = () => {- setDraft(kind === "scalar" && !empty ? String(value) : "");- setEditing(true);- };- const cancel = () => {- setDraft("");- setEditing(false);- };- const mutate = (- operation: FieldOp,- v?: unknown,- opts?: { keepOpen?: boolean; clearDraft?: boolean },- ) => {- edit.mutate(- { cluster: cid, field: fieldKey, operation, value: v },- {- onSuccess: () => {- toast();- if (opts?.clearDraft) setDraft("");- if (opts?.keepOpen) inputRef.current?.focus();- else cancel();- },- },- );- };-- const saveScalar = () => {- const v = draft.trim();- if (!v) {- mutate("clear");- } else {- mutate("set", v);- }- };- const addItem = () => {- const v = draft.trim();- if (v) mutate("append", v, { keepOpen: true, clearDraft: true });- };-- // ------------------------------------------------------------------ display- //- // No leader dots, and no fifteen repetitions of "not known yet". The dotted- // rule was the construction that made this column read as a printed ledger- // form, and a sentence repeated once per blank field is noise, not an empty- // state: a blank row now says so once, with a dash, and the whole row is the- // affordance that fills it in.- if (!editing) {- return (- <div className="group -mx-2 flex min-h-10 items-center justify-between gap-3 rounded-md px-2 py-1 transition-colors hover:bg-secondary">- <dt className="shrink-0 text-base text-muted-foreground">{label}</dt>- <dd className="flex min-w-0 max-w-[68%] items-center justify-end gap-2">- {kind === "list" && !empty ? (- <div className="flex flex-wrap justify-end gap-1">- {(value as unknown[]).map((item) => (- <span- key={String(item)}- className="rounded-md border border-border bg-secondary px-2 text-sm leading-6 text-foreground"- >- {String(item)}- </span>- ))}- </div>- ) : empty ? (- <span- aria-label={t("profile_view.field_unknown")}- title={t("profile_view.field_unknown")}- className="text-base text-foreground-faint"- >- —- </span>- ) : (- <span className="text-base text-foreground [overflow-wrap:anywhere]">- {renderValue(t, value)}- </span>- )}- {/* Quiet pencil — appears on row hover / keyboard focus only. */}- <button- type="button"- onClick={startEdit}- title={t("profile_view.field_edit")}- aria-label={`${t("profile_view.field_edit")}: ${label}`}- className="shrink-0 rounded-md p-1 text-muted-foreground opacity-0 outline-none transition-opacity hover:text-foreground focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-border-strong group-hover:opacity-100"- >- {empty ? <Plus className="h-3.5 w-3.5" /> : <Pencil className="h-3.5 w-3.5" />}- </button>- </dd>- </div>- );- }-- // ------------------------------------------------------------------- editing- return (- <div className="group flex items-baseline justify-between gap-3 rounded-md bg-secondary px-2 py-1.5 -mx-2">- <dt className="shrink-0 text-meta text-foreground-strong">{label}</dt>- <dd className="flex min-w-0 max-w-[68%] flex-col items-end gap-1.5">- {kind === "bool" ? (- <div className="flex items-center gap-1">- {([true, false] as const).map((b) => (- <button- key={String(b)}- type="button"- disabled={busy}- onClick={() => mutate("set", b)}- className={cn(- "rounded-full px-2.5 py-0.5 text-meta font-medium transition-colors disabled:opacity-40",- value === b- ? "bg-primary text-primary-foreground"- : "bg-popover text-muted-foreground hover:text-foreground",- )}- >- {b ? t("profile_view.value_yes") : t("profile_view.value_no")}- </button>- ))}- <IconBtn icon={X} onClick={cancel} title={t("profile_view.raw_cancel")} disabled={busy} />- {!empty && (- <IconBtn- icon={Trash2}- onClick={() => mutate("clear")}- title={t("profile_view.field_clear")}- tone="danger"- disabled={busy}- />- )}+/**+ * The real layout at its real height with skeleton bars. A centred spinner in+ * an empty window is the state that reads as "broken", because it throws away+ * every bit of structure the section is about to have — and a zero in a slot+ * that has not loaded yet is worse, because it reads as a fact.+ */+function ProfileSkeleton({ label }: { label: string }) {+ return (+ <div role="status" aria-busy="true" aria-label={label} className="flex flex-col gap-5">+ <div className="rounded-lg border border-border bg-card p-5">+ <div className="flex items-center gap-5">+ <div className="h-14 w-14 shrink-0 animate-pulse rounded-full bg-secondary" />+ <div className="flex min-w-0 flex-1 flex-col gap-2">+ <div className="h-5 w-56 max-w-full animate-pulse rounded-md bg-secondary" />+ <div className="h-3 w-32 max-w-full animate-pulse rounded-full bg-secondary" /></div>- ) : kind === "list" ? (- <>- {!empty && (- <div className="flex flex-wrap justify-end gap-1">- {(value as unknown[]).map((item) => (- <span- key={String(item)}- className="inline-flex items-center gap-1 rounded-full bg-popover py-0.5 pl-2 pr-1 text-meta text-foreground"- >- {String(item)}- <button- type="button"- disabled={busy}- onClick={() => mutate("remove", String(item), { keepOpen: true })}- title={t("profile_view.field_remove_item")}- aria-label={`${t("profile_view.field_remove_item")}: ${String(item)}`}- className="rounded-full p-0.5 text-muted-foreground outline-none transition-colors hover:text-destructive focus-visible:ring-2 focus-visible:ring-border-strong disabled:opacity-40"- >- <X className="h-2.5 w-2.5" />- </button>- </span>- ))}- </div>- )}- <div className="flex items-center gap-1">- <input- ref={inputRef}- value={draft}- disabled={busy}- onChange={(e) => setDraft(e.target.value)}- onKeyDown={(e) => {- if (e.key === "Enter") addItem();- if (e.key === "Escape") cancel();- }}- placeholder={t("profile_view.field_add_placeholder")}- className="w-28 min-w-0 rounded-md bg-popover px-2 py-1 text-body text-foreground outline-none placeholder:text-faint-foreground focus:ring-2 focus:ring-border-strong"- />- <IconBtn- icon={Plus}- onClick={addItem}- title={t("profile_view.field_add")}- tone="primary"- disabled={busy}- />- <IconBtn icon={Check} onClick={cancel} title={t("profile_view.raw_save")} disabled={busy} />- {!empty && (- <IconBtn- icon={Trash2}- onClick={() => mutate("clear")}- title={t("profile_view.field_clear")}- tone="danger"- disabled={busy}- />- )}- </div>- </>- ) : (- <div className="flex w-full items-center justify-end gap-1">- <input- ref={inputRef}- value={draft}- disabled={busy}- onChange={(e) => setDraft(e.target.value)}- onKeyDown={(e) => {- if (e.key === "Enter") saveScalar();- if (e.key === "Escape") cancel();- }}- placeholder={t("profile_view.field_value_placeholder")}- className="min-w-0 flex-1 rounded-md bg-popover px-2 py-1 text-right text-body text-foreground outline-none placeholder:text-faint-foreground focus:ring-2 focus:ring-border-strong"- />- <IconBtn- icon={Check}- onClick={saveScalar}- title={t("profile_view.raw_save")}- tone="primary"- disabled={busy}- />- <IconBtn icon={X} onClick={cancel} title={t("profile_view.raw_cancel")} disabled={busy} />- {!empty && (- <IconBtn- icon={Trash2}- onClick={() => mutate("clear")}- title={t("profile_view.field_clear")}- tone="danger"- disabled={busy}- />- )}+ <div className="hidden w-64 shrink-0 flex-col gap-2 sm:flex">+ <div className="h-3 w-40 animate-pulse rounded-full bg-secondary" />+ <div className="h-1.5 w-full animate-pulse rounded-full bg-secondary" /></div>- )}- </dd>- </div>- );-}--// -----------------------------------------------------------------------// The Margin — what the ledger still wants: a question, the queue, the people-// ------------------------------------------------------------------------function MarginRail({- data,- meta,-}: {- data: ProfileResponse;- meta: Record<string, unknown>;-}) {- return (- <aside className="flex min-w-0 flex-col gap-6 border-t border-border px-8 py-6">- <div className="profile-rise" style={{ animationDelay: "80ms" }}>- <AskCard meta={meta} />- </div>- <div className="profile-rise" style={{ animationDelay: "150ms" }}>- <ReviewsSection reviewsCount={data.reviews_count} />- </div>- <div className="profile-rise" style={{ animationDelay: "220ms" }}>- <PeopleSection people={data.people} />- </div>- </aside>- );-}--// -----------------------------------------------------------------------// Ask card — ONE question at a time, with the sentence to speak-// ------------------------------------------------------------------------function AskCard({ meta }: { meta: Record<string, unknown> }) {- const t = useT();- const [idx, setIdx] = useState(0);-- const open = useMemo(() => collectOpenQuestions(meta, TOTAL_FIELDS), [meta]);- if (open.length === 0) return null;-- const q = open[idx % open.length];-- // A card, and it has earned it: this is sized to one question, not to the- // rail. The nested "say this" well steps UP to --secondary rather than down- // into a translucent wash of the page behind it.- return (- <div className="rounded-lg border border-border bg-card p-5">- <div className="flex items-center gap-1.5 text-sm text-muted-foreground">- <Sparkles className="h-3.5 w-3.5" />- {t("profile_view.ask_title")}- <span className="ml-auto tabular-nums">- {(idx % open.length) + 1}/{open.length}- </span>- </div>-- <p className="mt-2.5 text-lg font-semibold text-foreground-strong">- {t(`profile_view.questions.${q.field}`)}- </p>-- <div className="mt-3 flex items-start gap-2 rounded-md bg-secondary px-3 py-2 text-meta text-muted-foreground">- <Mic className="mt-0.5 h-3.5 w-3.5 shrink-0" />- <span className="min-w-0">- {t("profile_view.ask_say_prefix")}:{" "}- <span className="text-foreground">“{t(`profile_view.says.${q.field}`)}”</span>- </span>- </div>-- <div className="mt-3 flex items-center justify-between gap-2">- <span className="text-meta text-muted-foreground">- {t(`profile_view.clusters.${q.cluster}.label`)}- </span>- <button- type="button"- data-testid="ask-next"- onClick={() => setIdx((i) => i + 1)}- className="inline-flex h-8 items-center gap-1 rounded-md border border-border-strong px-3 text-sm font-medium text-foreground transition-colors hover:bg-secondary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"- >- {t("profile_view.ask_next")}- <ChevronRight className="h-3 w-3" />- </button>- </div>- </div>- );-}--// -----------------------------------------------------------------------// Reviews — observations waiting for the user's OK-// ------------------------------------------------------------------------function ReviewsSection({ reviewsCount }: { reviewsCount: number }) {- const t = useT();- const queryClient = useQueryClient();- const pushToast = useEventStore((s) => s.pushToast);-- const { data, isLoading, error, refetch, isRefetching } = useQuery<ReviewsResponse, Error>({- queryKey: ["profile", "reviews"],- queryFn: () => fetchJson<ReviewsResponse>("/api/profile/reviews"),- retry: false,- });-- const accept = useMutation({- mutationFn: (idx: number) =>- fetchJson<{ ok: boolean; applied: number }>(`/api/profile/reviews/${idx}/accept`, {- method: "POST",- }),- onSuccess: (res) => {- pushToast(- "success",- res.applied > 0- ? t("profile_toast.fact_applied").replace("{0}", String(res.applied))- : t("profile_view.accepted"),- );- queryClient.invalidateQueries({ queryKey: ["profile"] });- queryClient.invalidateQueries({ queryKey: ["profile", "reviews"] });- },- onError: (err: Error) => pushToast("error", err.message),- });-- const reject = useMutation({- mutationFn: (idx: number) =>- fetchJson<{ ok: boolean }>(`/api/profile/reviews/${idx}/reject`, { method: "POST" }),- onSuccess: () => {- pushToast("info", t("profile_view.reject_tooltip"));- queryClient.invalidateQueries({ queryKey: ["profile"] });- queryClient.invalidateQueries({ queryKey: ["profile", "reviews"] });- },- onError: (err: Error) => pushToast("error", err.message),- });-- const pendingIdx: number | null = accept.isPending- ? (accept.variables ?? null)- : reject.isPending- ? (reject.variables ?? null)- : null;-- const items = data?.reviews ?? [];-- return (- <div>- <RailHeading- title={t("profile_view.section_reviews")}- count={reviewsCount > 0 ? `${reviewsCount} ${t("profile_view.review_open")}` : ""}- right={- <button- type="button"- onClick={() => refetch()}- disabled={isRefetching}- title={t("profile_view.reload_tooltip")}- aria-label={t("profile_view.reload_tooltip")}- className="rounded-md p-1 text-muted-foreground transition-colors hover:bg-secondary hover:text-foreground disabled:opacity-40"- >- <RefreshCw className={cn("h-3.5 w-3.5", isRefetching && "animate-spin")} />- </button>- }- />-- {/* The real container at its real height with skeleton bars — never a- spinner beside a grey word, and never an invented zero. */}- {isLoading && (- <ul className="mt-stack space-y-stack" aria-hidden>- {[0, 1].map((i) => (- <li key={i} className="space-y-2 rounded-lg bg-card p-3 shadow-rim">- <div className="h-3 w-4/5 animate-pulse rounded-full bg-sheen/[0.06]" />- <div className="h-3 w-2/5 animate-pulse rounded-full bg-sheen/[0.06]" />- <div className="h-7 animate-pulse rounded-md bg-sheen/[0.06]" />- </li>- ))}- </ul>- )}-- {error &&- ((error as Error & { status?: number }).status === 503 ? (- // 503 = the Curator subsystem is intentionally not running (e.g.- // legacy_curator soft-disabled, Mock-Brain). Per the backend- // contract in profile_routes.py this is an expected state and must- // render as a calm empty-state, NOT a destructive red badge.- <EmptyHint- icon={ShieldQuestion}- title={t("profile_view.reviews_disabled_title")}- body={t("profile_view.reviews_disabled_body")}- testId="reviews-disabled"- />- ) : (- <p data-testid="reviews-error" className="mt-stack text-meta text-destructive">- {error.message}- </p>- ))}-- {data && items.length === 0 && (- <EmptyHint- icon={ShieldQuestion}- title={t("profile_view.reviews_empty_title")}- body={t("profile_view.reviews_empty_body")}- />- )}-- {items.length > 0 && (- <ul className="mt-stack space-y-stack">- {items.map((c) => (- <ReviewRow- key={c.idx}- candidate={c}- pending={pendingIdx === c.idx}- onAccept={() => accept.mutate(c.idx)}- onReject={() => reject.mutate(c.idx)}- />- ))}- </ul>- )}- </div>- );-}--/** Calm in-rail empty state shared by People and Reviews. */-function EmptyHint({- icon: Icon,- title,- body,- testId,-}: {- icon: React.ComponentType<{ className?: string }>;- title: string;- body: React.ReactNode;- testId?: string;-}) {- return (- <div data-testid={testId} className="mt-stack flex items-start gap-3">- <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-secondary">- <Icon className="h-4 w-4 text-muted-foreground" />- </div>- <div className="min-w-0 flex-1">- <div className="text-body text-foreground">{title}</div>- <p className="mt-0.5 text-meta text-muted-foreground">{body}</p>- </div>- </div>- );-}--/** One review candidate, sized for the margin rail: the quote leads, the- * cluster→field path and the verdict buttons sit under it. */-function ReviewRow({- candidate,- pending,- onAccept,- onReject,-}: {- candidate: ReviewCandidate;- pending: boolean;- onAccept: () => void;- onReject: () => void;-}) {- const t = useT();- // Who the observation is about. Every person in the app carries a coloured- // mark, this row included — it is what tells "about you" from "about Anna"- // at a glance, without reading the line.- const subject = candidate.is_person- ? (candidate.person_name ?? t("profile_view.review_subject_user"))- : t("profile_view.review_subject_user");-- return (- <li className="rounded-lg bg-card p-3 shadow-rim">- <div className="flex items-center gap-2 text-meta text-muted-foreground">- <IdentityAvatar name={subject} size="sm" />- <span className="min-w-0 truncate text-foreground">{subject}</span>- <span className="ml-auto shrink-0 tabular-nums">- {(candidate.confidence * 100).toFixed(0)}%- </span>- </div>-- {candidate.evidence && (- <blockquote className="mt-2 text-meta italic text-foreground">- “{candidate.evidence}”- </blockquote>- )}-- <div className="mt-2 flex flex-wrap items-center gap-1 text-meta text-muted-foreground">- <span>{candidate.cluster}</span>- <ChevronRight className="h-3 w-3" />- <span className="text-foreground">{candidate.field}</span>- <Badge variant="outline">{candidate.operation}</Badge>- </div>-- <div className="mt-1.5 text-meta">- <span className="text-muted-foreground">{t("profile_view.review_value")}: </span>- <span className="text-foreground [overflow-wrap:anywhere]">- {renderValue(t, candidate.value) || "—"}- </span>- </div>-- {candidate.reason && (- <p className="mt-1 text-meta text-muted-foreground">- {t("profile_view.review_reason")}: {candidate.reason}- </p>- )}-- <div className="mt-2.5 flex gap-1.5">- <Button- size="sm"- variant="default"- className="h-7 flex-1 text-meta"- disabled={pending}- onClick={onAccept}- title={t("profile_view.accept_tooltip")}- >- <Check className="mr-1 h-3 w-3" />- {t("profile_view.review_confirm")}- </Button>- <Button- size="sm"- variant="outline"- className="h-7 flex-1 text-meta"- disabled={pending}- onClick={onReject}- title={t("profile_view.reject_tooltip")}- >- <X className="mr-1 h-3 w-3" />- {t("profile_view.review_strike")}- </Button>+ </div></div>- </li>- );-}--// -----------------------------------------------------------------------// People — quiet rows that expand in place-// -----------------------------------------------------------------------//-// A side-by-side list + detail card cannot fit a 320px rail, so the detail-// opens inside the row instead. One click selects and expands — the row-click-// doctrine the rest of the app follows.--function PeopleSection({ people }: { people: PersonSummary[] }) {- const t = useT();- const [openSlug, setOpenSlug] = useState<string | null>(null);-- return (- <div>- <RailHeading- title={t("profile_view.section_people")}- count={people.length > 0 ? people.length : ""}- />- {people.length === 0 ? (- <EmptyHint- icon={UsersIcon}- title={t("profile_view.people_empty_title")}- body={t("profile_view.people_empty_body")}- />- ) : (- <ul className="mt-stack">- {people.map((p) => (- <PersonRow- key={p.slug}- person={p}- open={p.slug === openSlug}- onToggle={() => setOpenSlug(p.slug === openSlug ? null : p.slug)}- />+ <div className={SPLIT}>+ <div className="grid gap-5 lg:grid-cols-2">+ {[0, 1, 2, 3].map((i) => (+ <SkeletonCard key={i} rows={4} />))}- </ul>- )}- </div>- );-}--function PersonRow({- person,- open,- onToggle,-}: {- person: PersonSummary;- open: boolean;- onToggle: () => void;-}) {- const t = useT();-- // Selection is drawn on the WHOLE row, inset from the column edge — not on- // the 28px avatar box. Rest is the rail's own ground; hover and open both- // step up to --secondary, which is the only direction the ladder goes.- return (- <li>- <button- type="button"- onClick={onToggle}- aria-expanded={open}- className={cn(- "-mx-2 flex w-[calc(100%+1rem)] items-center gap-row rounded-md px-2 py-2 text-left transition-colors",- open ? "bg-secondary" : "hover:bg-secondary",- )}- >- <IdentityAvatar name={person.name} size="sm" />- <span className="min-w-0 flex-1">- <span- className={cn(- "block truncate text-body",- open ? "text-foreground-strong" : "text-foreground",- )}- >- {person.name}- </span>- <span className="block truncate text-meta text-muted-foreground">- {person.relationship}- </span>- </span>- <ChevronDown- className={cn(- "h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform",- open && "rotate-180",- )}- />- </button>-- {open && (- <div className="py-stack pl-[2.375rem] pr-1">- <dl className="space-y-stack text-meta">- <div className="flex items-baseline justify-between gap-3">- <dt className="text-muted-foreground">{t("profile_view.person_relationship")}</dt>- <dd className="text-foreground">{person.relationship}</dd>- </div>- <div className="flex items-baseline justify-between gap-3">- <dt className="text-muted-foreground">{t("profile_view.person_aliases")}</dt>- <dd className="text-right [overflow-wrap:anywhere]">- {person.aliases.length === 0 ? (- <span className="text-faint-foreground">—</span>- ) : (- <span className="text-foreground">{person.aliases.join(" · ")}</span>- )}- </dd>- </div>- </dl>- <p className="mt-stack flex items-start gap-1.5 text-meta text-muted-foreground">- <Inbox className="mt-0.5 h-3.5 w-3.5 shrink-0" />- {t("profile_view.person_file_hint").replace("{0}", person.slug)}- </p>- </div>- )}- </li>- );-}--// -----------------------------------------------------------------------// The Source — USER.md, rendered as the document it is-// -----------------------------------------------------------------------//-// Data flow: GET /api/profile/raw → React-Query cache. Live sync via WS:-// every Curator merge publishes ProfileUpdated on the bus, the WS server-// streams it to the UI, and the subscriber below invalidates both profile-// queries — the file is current seconds after a write. The pulse badge gives-// visual feedback when an update lands.-//-// The file is rendered, not dumped as monospace: the curator writes real-// prose under the front matter ("Observations over time", "Active projects"),-// and reading it as a document is the point of having it on the page. The-// front matter itself is split off — the ledger to the left already IS that-// block, drawn as fields. Editing switches the same rail to the raw text, so-// nothing is hidden from the person who wants to fix a line by hand.--function SourceRail() {- const t = useT();- const queryClient = useQueryClient();- const pushToast = useEventStore((s) => s.pushToast);- const [pulseUntil, setPulseUntil] = useState<number>(0);-- // Edit mode. `draft` is the working copy; `editBaseMtime` is frozen at- // edit-start so the optimistic-concurrency guard on the backend stays- // meaningful even if a background refetch updates `data.mtime_ms`.- const [editing, setEditing] = useState(false);- const [draft, setDraft] = useState("");- const [editBaseMtime, setEditBaseMtime] = useState<number | null>(null);-- const { data, isLoading, error, refetch, isRefetching } = useQuery<RawProfileResponse, Error>({- queryKey: ["profile", "raw"],- queryFn: () => fetchJson<RawProfileResponse>("/api/profile/raw"),- retry: false,- staleTime: 0,- });-- // Live-subscribe to ProfileUpdated events from the bus.- useEffect(() => {- const client = getWSClient();- if (!client) return;- const unsubscribe = client.subscribe((raw) => {- const env = raw as { event_name?: unknown };- if (env.event_name !== "ProfileUpdated") return;- // The ledger always refreshes…- queryClient.invalidateQueries({ queryKey: ["profile"] });- // …but never replace the raw text while the user is editing it — that- // would wipe their draft mid-keystroke.- if (!editing) {- queryClient.invalidateQueries({ queryKey: ["profile", "raw"] });- }- setPulseUntil(Date.now() + 2000);- });- return unsubscribe;- }, [queryClient, editing]);-- const save = useMutation({- mutationFn: async (content: string) => {- const res = await fetch("/api/profile/raw", {- method: "PUT",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ content, mtime_ms: editBaseMtime }),- });- if (!res.ok) {- const body = (await res.json().catch(() => ({}))) as { detail?: string };- const err = new Error(body.detail ?? `HTTP ${res.status}`) as Error & {- status?: number;- };- err.status = res.status;- throw err;- }- return res.json() as Promise<{- ok: boolean;- mtime_ms: number | null;- frontmatter_ok: boolean;- }>;- },- onSuccess: (res) => {- setEditing(false);- if (res.frontmatter_ok === false) {- pushToast("error", t("profile_view.raw_frontmatter_warning"));- } else {- pushToast("success", t("profile_view.raw_saved"));- }- queryClient.invalidateQueries({ queryKey: ["profile"] });- queryClient.invalidateQueries({ queryKey: ["profile", "raw"] });- },- onError: (err: Error) => pushToast("error", err.message),- });-- const startEditing = () => {- setDraft(data?.content ?? "");- setEditBaseMtime(data?.mtime_ms ?? null);- setEditing(true);- };-- // Escape leaves edit mode, the way it cancels every other inline editor- // in this view. The draft is dropped, which is why the button says Cancel.- useEffect(() => {- if (!editing) return;- const onKey = (e: KeyboardEvent) => {- if (e.key === "Escape") setEditing(false);- };- window.addEventListener("keydown", onKey);- return () => window.removeEventListener("keydown", onKey);- }, [editing]);-- const isPulsing = Date.now() < pulseUntil;- const lastUpdate = useMemo(() => {- if (!data?.mtime_ms) return null;- return new Date(data.mtime_ms);- }, [data?.mtime_ms]);-- // The front matter is the ledger's own content; showing it twice would just- // be the same facts in a worse format.- //- // The curator's anchors (`<!-- curator:observations:start -->`) mark where- // it splices its own writes. They are machinery, not text — and because- // react-markdown escapes raw HTML instead of rendering it, leaving them in- // prints them verbatim on the page. Strip them, then close the run of blank- // lines they leave behind.- const body = useMemo(() => {- if (!data) return "";- return splitFrontMatter(data.content)- .body.replace(/<!--[\s\S]*?-->/g, "")- .replace(/[ \t]+$/gm, "")- .replace(/\n{3,}/g, "\n\n")- .trim();- }, [data]);-- return (- <section className="flex min-w-0 flex-col bg-background lg:min-h-0">- <div className="flex flex-wrap items-center gap-2 border-b border-border px-5 py-2.5">- <FileText className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />- <h2 className="text-title font-semibold text-foreground-strong">- {t("profile_view.section_source")}- </h2>- {data && (- <span className="min-w-0 truncate font-mono text-micro text-muted-foreground">- {data.path}- </span>- )}-- <div className="ml-auto flex items-center gap-1.5 text-meta text-muted-foreground">- {editing ? (- <>- <span className="hidden items-center gap-1.5 xl:flex">- <Lock className="h-3 w-3" />- {t("profile_view.raw_editing_hint")}- </span>- <Button- size="sm"- variant="ghost"- className="h-6 px-2 text-meta"- onClick={() => setEditing(false)}- disabled={save.isPending}- >- {t("profile_view.raw_cancel")}- </Button>- <Button- size="sm"- variant="default"- className="h-6 px-2 text-meta"- onClick={() => save.mutate(draft)}- disabled={save.isPending}- >- <Save className={cn("mr-1 h-3 w-3", save.isPending && "animate-pulse")} />- {save.isPending ? t("profile_view.raw_saving") : t("profile_view.raw_save")}- </Button>- </>- ) : (- <>- {/* Something just wrote to the file: that is the section's one- live signal, so it is spent on --success rather than on- another grey pill. */}- {isPulsing && (- <span className="inline-flex items-center gap-1.5 rounded-full bg-secondary px-2 py-0.5 text-foreground">- <span className="relative flex h-1.5 w-1.5">- <span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-success opacity-75" />- <span className="relative inline-flex h-1.5 w-1.5 rounded-full bg-success" />- </span>- {t("profile_view.just_updated")}- </span>- )}- {lastUpdate && (- <span className="hidden items-center gap-1 xl:inline-flex">- <Clock className="h-3 w-3" />- {lastUpdate.toLocaleDateString()}- </span>- )}- {data && <span className="tabular-nums">{(data.size_bytes / 1024).toFixed(1)} KB</span>}- <button- type="button"- onClick={() => refetch()}- disabled={isRefetching}- title={t("profile_view.reload_tooltip")}- aria-label={t("profile_view.reload_tooltip")}- className="rounded-md p-1 text-muted-foreground transition-colors hover:bg-secondary hover:text-foreground disabled:opacity-40"- >- <RefreshCw className={cn("h-3.5 w-3.5", isRefetching && "animate-spin")} />- </button>- {data && (- <Button- size="sm"- variant="outline"- className="h-6 px-2 text-meta"- onClick={startEditing}- >- <Pencil className="mr-1 h-3 w-3" />- {t("profile_view.raw_edit")}- </Button>- )}- </>- )}</div>- </div>-- <div className="min-h-0 flex-1 lg:overflow-hidden">- {/* The document at its real width with skeleton lines, not a spinner- beside a word. */}- {isLoading && (- <div className="max-w-reading space-y-stack px-5 py-4" aria-hidden>- <div className="h-4 w-1/3 animate-pulse rounded-full bg-sheen/[0.06]" />- <div className="h-3 w-full animate-pulse rounded-full bg-sheen/[0.06]" />- <div className="h-3 w-11/12 animate-pulse rounded-full bg-sheen/[0.06]" />- <div className="h-3 w-4/5 animate-pulse rounded-full bg-sheen/[0.06]" />- </div>- )}-- {error && <p className="px-5 py-4 text-body text-destructive">{error.message}</p>}-- {data &&- (editing ? (- <textarea- value={draft}- onChange={(e) => setDraft(e.target.value)}- spellCheck={false}- autoFocus- aria-label="USER.md"- className="block h-full min-h-[24rem] w-full resize-none bg-transparent px-5 py-4 font-mono text-meta text-foreground outline-none scrollbar-jarvis"- />- ) : (- <div className="h-full overflow-y-auto px-5 py-4 scrollbar-jarvis">- {body ? (- // A profile is a document, so it is set at the reading step in- // full ink and bounded to a reading measure. It used to run at- // muted ink under small-caps headings, which reads as text- // somebody disabled rather than text somebody wrote.- <article- data-testid="profile-source-markdown"- className={cn(- PROSE_BASE,- "max-w-3xl text-base leading-7 text-foreground",- "prose-headings:text-foreground-strong",- "prose-h1:text-xl prose-h2:mt-group prose-h2:text-lg prose-h3:text-lg",- "prose-blockquote:border-l-2 prose-blockquote:border-border prose-blockquote:pl-4 prose-blockquote:font-normal prose-blockquote:not-italic prose-blockquote:text-muted-foreground",- "prose-p:text-foreground prose-li:text-foreground prose-strong:text-foreground-strong",- )}- >- <ReactMarkdown remarkPlugins={[remarkGfm]}>{body}</ReactMarkdown>- </article>- ) : (- <p className="text-body text-muted-foreground">- {t("profile_view.raw_empty")}- </p>- )}- </div>+ <div className={RAIL}>+ {[0, 1, 2].map((i) => (+ <SkeletonCard key={i} rows={3} />))}+ </div></div>- </section>+ </div>);}-// -----------------------------------------------------------------------// Loading / Error-// ------------------------------------------------------------------------/**- * The real three-rail shape at its real height, with skeleton bars. A centred- * spinner in an empty window is the state that reads as "broken", because it- * throws away every bit of structure the section is about to have.- */-function LoadingState() {+function SkeletonCard({ rows }: { rows: number }) {return (- <div- role="status"- aria-busy="true"- className="grid min-h-0 flex-1 grid-cols-1 lg:grid-cols-[minmax(320px,1fr)_minmax(0,1.15fr)_minmax(280px,330px)]"- >- <div className="space-y-group bg-sidebar px-6 py-7">- {[0, 1, 2].map((group) => (- <div key={group} className="space-y-stack">- <div className="h-4 w-32 animate-pulse rounded-full bg-sheen/[0.06]" />- {[0, 1, 2, 3].map((row) => (- <div key={row} className="flex items-center justify-between gap-8">- <div className="h-3 w-24 animate-pulse rounded-full bg-sheen/[0.06]" />- <div className="h-3 w-28 animate-pulse rounded-full bg-sheen/[0.06]" />- </div>- ))}+ <div className="rounded-lg border border-border bg-card p-5">+ <div className="h-4 w-28 animate-pulse rounded-md bg-secondary" />+ <div className="mt-4 flex flex-col gap-3">+ {Array.from({ length: rows }, (_, i) => (+ <div key={i} className="flex items-center justify-between gap-8">+ <div className="h-3 w-24 animate-pulse rounded-full bg-secondary" />+ <div className="h-3 w-20 animate-pulse rounded-full bg-secondary" /></div>))}</div>- <div className="max-w-reading space-y-stack bg-background px-5 py-6">- <div className="h-5 w-2/5 animate-pulse rounded-full bg-sheen/[0.06]" />- {[0, 1, 2, 3, 4].map((line) => (- <div key={line} className="h-3 w-full animate-pulse rounded-full bg-sheen/[0.06]" />- ))}- </div>- <div className="space-y-stack bg-sidebar px-5 py-8">- <div className="h-28 animate-pulse rounded-lg bg-sheen/[0.06]" />- <div className="h-20 animate-pulse rounded-lg bg-sheen/[0.06]" />- </div></div>);}-function ErrorState({ error, onRetry }: { error: Error; onRetry: () => void }) {+/**+ * 503 means the profile subsystem is deliberately not running in this session+ * (a mock brain, a provider without memory integration). That is a state, not+ * a fault, and it gets the calm treatment; everything else is a real failure+ * and says so.+ */+function ProfileErrorState({ error, onRetry }: { error: Error; onRetry: () => void }) {const t = useT();- const status = (error as Error & { status?: number }).status;- if (status === 503) {++ if (statusOf(error) === 503) {return (- <div className="flex flex-1 items-center justify-center p-8">- <div className="max-w-form rounded-lg bg-card p-8 text-center shadow-rim">- <div className="mx-auto mb-5 flex h-14 w-14 items-center justify-center rounded-full bg-secondary">- <UserCircle2 className="h-6 w-6 text-muted-foreground" />- </div>- <h3 className="font-display text-page font-semibold text-foreground-strong">- {t("profile_view.hero_name_placeholder")}- </h3>- <p className="mt-2 text-body text-foreground">{error.message}</p>- <p className="mt-4 text-meta text-muted-foreground">{t("profile_view.no_user_hint")}</p>- <Button className="mt-6" size="sm" variant="outline" onClick={onRetry}>- <RefreshCw className="mr-2 h-3.5 w-3.5" /> {t("apikeys_view.retry")}+ <EmptyState+ icon={<UserCircle2 />}+ title={t("profile_view.hero_name_placeholder")}+ description={t("profile_view.no_user_hint")}+ actions={+ <Button size="sm" variant="outline" onClick={onRetry}>+ <RefreshCw />+ {t("common.retry")}</Button>- </div>- </div>+ }+ />);}+return (- <div className="flex items-center gap-3 p-6 text-body">- <span className="text-destructive">- {t("common.error_generic")}: {error.message}- </span>- <Button size="sm" variant="outline" onClick={onRetry}>- {t("apikeys_view.retry")}+ <div className="flex items-start gap-3 rounded-lg border border-destructive/20 bg-destructive/[0.12] p-5">+ <AlertTriangle aria-hidden className="mt-0.5 h-4 w-4 shrink-0 text-destructive" />+ <div className="min-w-0 flex-1">+ <p className="text-base font-medium text-foreground-strong">+ {t("profile_view.error_title")}+ </p>+ <p className="mt-1 text-base text-foreground-secondary [overflow-wrap:anywhere]">+ {error.message}+ </p>+ </div>+ <Button size="sm" variant="outline" className="shrink-0" onClick={onRetry}>+ {t("common.retry")}</Button></div>);diff --git a/jarvis/ui/web/frontend/src/views/profile/AskCard.tsx b/jarvis/ui/web/frontend/src/views/profile/AskCard.tsxnew file mode 100644index 0000000000..721797dd84--- /dev/null+++ b/jarvis/ui/web/frontend/src/views/profile/AskCard.tsx@@ -0,0 +1,88 @@+/**+ * The open question — ONE at a time, with the sentence you can speak.+ *+ * A blank profile has eighteen holes in it. Listing them is a chore list; the+ * card asks a single question in priority order and hands over the literal+ * words to say, so filling the profile is a conversation rather than a form.+ * It is the only accent-washed object in the view, which is what makes it the+ * one thing the eye goes to when the profile is still thin.+ */+import { useMemo, useState } from "react";+import { ChevronRight, Mic, Sparkles } from "lucide-react";++import { Button } from "@/components/ui/button";+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";+import { EmptyState } from "@/components/ui/empty-state";+import { useT } from "@/i18n";+import { TOTAL_FIELDS, collectOpenQuestions } from "@/views/profile/ledger";++export function AskCard({ meta }: { meta: Record<string, unknown> }) {+ const t = useT();+ const [idx, setIdx] = useState(0);++ const open = useMemo(() => collectOpenQuestions(meta, TOTAL_FIELDS), [meta]);++ if (open.length === 0) {+ return (+ <Card>+ <CardHeader className="pb-0">+ <CardTitle>{t("profile_view.ask_title")}</CardTitle>+ </CardHeader>+ <CardContent>+ <EmptyState+ className="max-w-none py-6"+ icon={<Sparkles />}+ title={t("profile_view.ask_empty_title")}+ description={t("profile_view.ask_empty_body")}+ />+ </CardContent>+ </Card>+ );+ }++ const q = open[idx % open.length];++ return (+ <Card className="border-accent/20 bg-accent-soft">+ <CardHeader className="flex-row items-center justify-between gap-3 pb-2">+ <span className="flex min-w-0 items-center gap-2 text-sm font-medium text-accent">+ <Sparkles aria-hidden className="h-4 w-4 shrink-0" />+ <span className="truncate">{t("profile_view.ask_title")}</span>+ </span>+ <span className="shrink-0 text-sm tabular-nums text-muted-foreground">+ {(idx % open.length) + 1}/{open.length}+ </span>+ </CardHeader>++ <CardContent>+ <p className="text-lg font-semibold text-foreground-strong">+ {t(`profile_view.questions.${q.field}`)}+ </p>++ <p className="mt-3 flex items-start gap-2 text-base text-muted-foreground">+ <Mic aria-hidden className="mt-0.5 h-4 w-4 shrink-0" />+ <span className="min-w-0">+ {t("profile_view.ask_say_prefix")}:{" "}+ <span className="text-foreground">“{t(`profile_view.says.${q.field}`)}”</span>+ </span>+ </p>++ <div className="mt-4 flex items-center justify-between gap-3">+ <span className="min-w-0 truncate text-sm text-muted-foreground">+ {t(`profile_view.clusters.${q.cluster}.label`)}+ </span>+ <Button+ type="button"+ size="sm"+ variant="outline"+ data-testid="ask-next"+ onClick={() => setIdx((i) => i + 1)}+ >+ {t("profile_view.ask_next")}+ <ChevronRight />+ </Button>+ </div>+ </CardContent>+ </Card>+ );+}diff --git a/jarvis/ui/web/frontend/src/views/profile/IdentityCard.tsx b/jarvis/ui/web/frontend/src/views/profile/IdentityCard.tsxnew file mode 100644index 0000000000..3e85df7a5f--- /dev/null+++ b/jarvis/ui/web/frontend/src/views/profile/IdentityCard.tsx@@ -0,0 +1,248 @@+/**+ * The identity card — who Jarvis thinks you are, in one calm object.+ *+ * The portrait doubles as the upload control (there is no second "change+ * picture" button anywhere), the headline is how the app addresses you, and+ * the progress bar is the only place completeness is drawn. When nothing has+ * been learned yet the card does not go quiet: it names the two ways to teach+ * it, because an empty profile is a first-run state, not a failure.+ */+import { useMemo, useRef, useState } from "react";+import { useMutation, useQueryClient } from "@tanstack/react-query";+import { Camera, FileText, Loader2, Mic, Trash2, UserCircle2 } from "lucide-react";++import { Button } from "@/components/ui/button";+import { Card } from "@/components/ui/card";+import { IdentityAvatar } from "@/components/identity/IdentityAvatar";+import { useT } from "@/i18n";+import { cn } from "@/lib/utils";+import { useEventStore } from "@/store/events";+import type { ProfileResponse } from "@/views/profile/api";+import {+ TOTAL_FIELDS,+ acquaintanceStage,+ countFilled,+ displayAddress,+} from "@/views/profile/ledger";++export function IdentityCard({+ data,+ meta,+ onOpenSource,+}: {+ data: ProfileResponse;+ meta: Record<string, unknown>;+ /** Switches the view to the source-file tab — the second way to teach it. */+ onOpenSource: () => void;+}) {+ const t = useT();+ const name = data.user.name?.trim() || null;++ const filled = useMemo(() => countFilled(meta), [meta]);+ const stage = acquaintanceStage(filled, TOTAL_FIELDS);+ const percent = Math.round((filled / Math.max(TOTAL_FIELDS, 1)) * 100);++ // Address the user the way they asked to be addressed ("Chef"), falling back+ // to their first name — warmer than the full legal name.+ const address = displayAddress(meta, name);+ const headline = address+ ? t(`profile_view.stage_headline.${stage.key}`).replace("{0}", `, ${address}`)+ : t("profile_view.hero_name_placeholder");++ const ratio = t("profile_view.entries_ratio")+ .replace("{0}", String(filled))+ .replace("{1}", String(TOTAL_FIELDS));++ const peopleLine =+ data.people.length === 1+ ? t("profile_view.person_known").replace("{0}", "1")+ : t("profile_view.people_known").replace("{0}", String(data.people.length));++ return (+ <Card className="profile-rise p-5">+ <div className="flex flex-wrap items-center gap-x-5 gap-y-4">+ <AvatarButton name={name} hasAvatar={!!data.has_avatar} />++ <div className="min-w-0 flex-1 basis-64">+ <h2 className="truncate text-xl font-semibold text-foreground-strong">{headline}</h2>+ <p className="mt-1 text-base text-muted-foreground">+ {t(`profile_view.stages.${stage.key}`)}+ </p>+ </div>++ <div className="flex min-w-0 flex-1 basis-64 flex-col gap-2 sm:max-w-xs">+ <div className="flex items-baseline justify-between gap-3">+ <span className="text-base tabular-nums text-foreground">{ratio}</span>+ <span className="text-sm tabular-nums text-muted-foreground">{peopleLine}</span>+ </div>+ <div+ role="progressbar"+ aria-valuemin={0}+ aria-valuemax={TOTAL_FIELDS}+ aria-valuenow={filled}+ aria-label={ratio}+ data-testid="profile-progress"+ className="h-1.5 w-full overflow-hidden rounded-full bg-secondary"+ >+ <div+ className="h-full rounded-full bg-accent transition-[width] duration-500"+ style={{ width: `${percent}%` }}+ />+ </div>+ </div>+ </div>++ {filled === 0 && (+ <div className="mt-5 border-t border-border pt-4">+ <p className="text-xs font-medium uppercase tracking-wide text-foreground-faint">+ {t("profile_view.hero_teach_intro")}+ </p>+ <div className="mt-3 flex flex-col gap-3 md:flex-row md:gap-8">+ <p className="flex min-w-0 flex-1 items-start gap-2 text-base text-foreground-secondary">+ <Mic aria-hidden className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />+ <span>{t("profile_view.hero_teach_voice")}</span>+ </p>+ <p className="flex min-w-0 flex-1 items-start gap-2 text-base text-foreground-secondary">+ <FileText aria-hidden className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />+ <span>+ {t("profile_view.hero_teach_file")}{" "}+ <Button variant="link" className="align-baseline" onClick={onOpenSource}>+ {t("profile_view.hero_open_source")}+ </Button>+ </span>+ </p>+ </div>+ </div>+ )}+ </Card>+ );+}++// ----------------------------------------------------------------------+// AvatarButton — the portrait, and the whole upload control+// ----------------------------------------------------------------------+//+// The avatar bytes live under user_data_dir()/data and are served by+// GET /api/profile/avatar. A hidden <input type="file"> is .click()'d to open+// the OS picker; a cache-busting query param forces the <img> to reload after+// a replace or a delete. The portrait IS the control — click to pick a file,+// and a small remove badge appears on hover or keyboard focus once there is a+// picture to remove.++function AvatarButton({ name, hasAvatar }: { name: string | null; hasAvatar: boolean }) {+ const t = useT();+ const queryClient = useQueryClient();+ const pushToast = useEventStore((s) => s.pushToast);+ const inputRef = useRef<HTMLInputElement | null>(null);+ const [bust, setBust] = useState(0);++ const upload = useMutation({+ mutationFn: async (file: File) => {+ const fd = new FormData();+ fd.append("file", file);+ const res = await fetch("/api/profile/avatar", { method: "POST", body: fd });+ if (!res.ok) {+ const body = (await res.json().catch(() => ({}))) as { detail?: string };+ throw new Error(body.detail ?? `HTTP ${res.status}`);+ }+ return res.json();+ },+ onSuccess: () => {+ setBust(Date.now());+ pushToast("success", t("profile_view.avatar_uploaded"));+ queryClient.invalidateQueries({ queryKey: ["profile"] });+ },+ onError: (err: Error) => pushToast("error", err.message),+ });++ const remove = useMutation({+ mutationFn: async () => {+ const res = await fetch("/api/profile/avatar", { method: "DELETE" });+ if (!res.ok) throw new Error(`HTTP ${res.status}`);+ return res.json();+ },+ onSuccess: () => {+ setBust(Date.now());+ pushToast("info", t("profile_view.avatar_removed"));+ queryClient.invalidateQueries({ queryKey: ["profile"] });+ },+ onError: (err: Error) => pushToast("error", err.message),+ });++ const onFileChosen = (e: React.ChangeEvent<HTMLInputElement>) => {+ const file = e.target.files?.[0];+ // Reset so picking the *same* file again still fires onChange.+ e.target.value = "";+ if (file) upload.mutate(file);+ };++ const busy = upload.isPending || remove.isPending;++ return (+ <div className="group/avatar relative shrink-0">+ <input+ ref={inputRef}+ type="file"+ accept="image/png,image/jpeg,image/webp,image/gif"+ className="hidden"+ aria-hidden="true"+ tabIndex={-1}+ onChange={onFileChosen}+ />+ <button+ type="button"+ onClick={() => inputRef.current?.click()}+ disabled={busy}+ title={hasAvatar ? t("profile_view.avatar_change") : t("profile_view.avatar_upload")}+ aria-label={hasAvatar ? t("profile_view.avatar_change") : t("profile_view.avatar_upload")}+ className="relative flex h-14 w-14 items-center justify-center overflow-hidden rounded-full bg-secondary transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:opacity-50"+ >+ {/* The person's own coloured mark, not a grey disc: this is the app's+ own owner, and identity is one of the jobs colour is allowed. */}+ {name ? (+ <IdentityAvatar+ name={name}+ size="lg"+ src={hasAvatar ? `/api/profile/avatar?t=${bust}` : null}+ alt={t("profile_view.avatar_alt")}+ />+ ) : hasAvatar ? (+ <img+ src={`/api/profile/avatar?t=${bust}`}+ alt={t("profile_view.avatar_alt")}+ className="h-full w-full object-cover"+ draggable={false}+ />+ ) : (+ <UserCircle2 aria-hidden className="h-6 w-6 text-muted-foreground" />+ )}++ <span className="pointer-events-none absolute inset-0 flex items-center justify-center rounded-full bg-scrim/70 opacity-0 transition-opacity duration-200 group-hover/avatar:opacity-100 group-focus-visible/avatar:opacity-100">+ <Camera aria-hidden className="h-4 w-4 text-foreground-strong" />+ </span>++ {busy && (+ <span className="absolute inset-0 flex items-center justify-center rounded-full bg-scrim/70">+ <Loader2 aria-hidden className="h-4 w-4 animate-spin text-foreground-strong" />+ </span>+ )}+ </button>++ {hasAvatar && (+ <button+ type="button"+ onClick={() => remove.mutate()}+ disabled={busy}+ title={t("profile_view.avatar_remove")}+ aria-label={t("profile_view.avatar_remove")}+ className={cn(+ "absolute -bottom-1 -right-1 rounded-full border border-border bg-card p-1 text-muted-foreground opacity-0 transition-opacity",+ "hover:text-destructive focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring group-hover/avatar:opacity-100",+ )}+ >+ <Trash2 aria-hidden className="h-3 w-3" />+ </button>+ )}+ </div>+ );+}diff --git a/jarvis/ui/web/frontend/src/views/profile/KnowledgeLedger.tsx b/jarvis/ui/web/frontend/src/views/profile/KnowledgeLedger.tsxnew file mode 100644index 0000000000..1a1aee7cbc--- /dev/null+++ b/jarvis/ui/web/frontend/src/views/profile/KnowledgeLedger.tsx@@ -0,0 +1,353 @@+/**+ * The knowledge ledger — one card per cluster, every field on the page.+ *+ * Nothing is hidden behind a "show more": a blank field is as informative as a+ * written one, so all eighteen are listed and the unknown ones say "not known+ * yet" in plain words. That sentence is deliberate — an earlier version drew a+ * redaction bar there, which read as information being withheld rather than+ * information not yet given.+ *+ * Every row is editable in place. The pencil is quiet until the row is hovered+ * or the button is focused, and the editor's shape follows the field kind:+ * text, a yes/no pair, or removable chips for a list.+ */+import { useEffect, useRef, useState } from "react";+import { Check, Pencil, Plus, Trash2, X } from "lucide-react";++import { Badge } from "@/components/ui/badge";+import { Button } from "@/components/ui/button";+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";+import { Input } from "@/components/ui/input";+import { useT } from "@/i18n";+import { useEventStore } from "@/store/events";+import { clusterDataOf, renderValue, useFieldEdit, type FieldOp } from "@/views/profile/api";+import {+ CLUSTER_FIELD_KEYS,+ CLUSTER_ORDER,+ clusterFilledCount,+ fieldKind,+ isEmptyValue,+ type ClusterId,+} from "@/views/profile/ledger";++export function KnowledgeLedger({ meta }: { meta: Record<string, unknown> }) {+ return (+ <div className="grid gap-5 lg:grid-cols-2">+ {CLUSTER_ORDER.map((cid, i) => (+ <ClusterCard key={cid} cid={cid} meta={meta} delayMs={60 + i * 40} />+ ))}+ </div>+ );+}++function ClusterCard({+ cid,+ meta,+ delayMs,+}: {+ cid: ClusterId;+ meta: Record<string, unknown>;+ delayMs: number;+}) {+ const t = useT();+ const data = clusterDataOf(meta, cid);+ const fields = CLUSTER_FIELD_KEYS[cid];+ const filled = clusterFilledCount(meta, cid);+ const complete = filled === fields.length;+ const countLabel = t("profile_view.group_filled")+ .replace("{0}", String(filled))+ .replace("{1}", String(fields.length));++ return (+ <Card className="profile-rise flex flex-col" style={{ animationDelay: `${delayMs}ms` }}>+ <CardHeader className="flex-row items-center justify-between gap-3 pb-2">+ <CardTitle>{t(`profile_view.clusters.${cid}.label`)}</CardTitle>+ <Badge+ variant={complete ? "success" : "secondary"}+ aria-label={countLabel}+ title={countLabel}+ className="tabular-nums"+ >+ {filled}/{fields.length}+ </Badge>+ </CardHeader>+ <CardContent>+ <dl>+ {fields.map((key) => (+ <FieldRow key={key} cid={cid} fieldKey={key} value={data[key]} />+ ))}+ </dl>+ </CardContent>+ </Card>+ );+}++// ----------------------------------------------------------------------+// One field, read and written in place+// ----------------------------------------------------------------------++/** A 32 px square icon control, sized for a 40 px row. */+function RowIconButton({+ icon: Icon,+ onClick,+ title,+ variant = "ghost",+ disabled,+}: {+ icon: typeof Check;+ onClick: () => void;+ title: string;+ variant?: "default" | "ghost" | "outline";+ disabled?: boolean;+}) {+ return (+ <Button+ type="button"+ variant={variant}+ size="icon"+ className="h-8 w-8 shrink-0"+ onClick={onClick}+ title={title}+ aria-label={title}+ disabled={disabled}+ >+ <Icon />+ </Button>+ );+}++function FieldRow({+ cid,+ fieldKey,+ value,+}: {+ cid: ClusterId;+ fieldKey: string;+ value: unknown;+}) {+ const t = useT();+ const pushToast = useEventStore((s) => s.pushToast);+ const edit = useFieldEdit();+ const kind = fieldKind(fieldKey);+ const empty = isEmptyValue(value);+ const label = t(`profile_view.fields.${fieldKey}`);++ const [editing, setEditing] = useState(false);+ const [draft, setDraft] = useState("");+ const inputRef = useRef<HTMLInputElement | null>(null);++ useEffect(() => {+ if (editing) inputRef.current?.focus();+ }, [editing]);++ const busy = edit.isPending;++ const startEdit = () => {+ setDraft(kind === "scalar" && !empty ? String(value) : "");+ setEditing(true);+ };+ const cancel = () => {+ setDraft("");+ setEditing(false);+ };+ const mutate = (+ operation: FieldOp,+ v?: unknown,+ opts?: { keepOpen?: boolean; clearDraft?: boolean },+ ) => {+ edit.mutate(+ { cluster: cid, field: fieldKey, operation, value: v },+ {+ onSuccess: () => {+ pushToast("success", t("profile_view.field_saved"));+ if (opts?.clearDraft) setDraft("");+ if (opts?.keepOpen) inputRef.current?.focus();+ else cancel();+ },+ },+ );+ };++ const saveScalar = () => {+ const v = draft.trim();+ if (v) mutate("set", v);+ else mutate("clear");+ };+ const addItem = () => {+ const v = draft.trim();+ if (v) mutate("append", v, { keepOpen: true, clearDraft: true });+ };++ // ------------------------------------------------------------------ resting+ if (!editing) {+ return (+ <div className="group -mx-2 flex min-h-10 items-center justify-between gap-4 rounded-md px-2 py-1 transition-colors hover:bg-secondary">+ <dt className="shrink-0 text-base text-muted-foreground">{label}</dt>+ <dd className="flex min-w-0 items-center justify-end gap-2">+ {kind === "list" && !empty ? (+ <div className="flex min-w-0 flex-wrap justify-end gap-1">+ {(value as unknown[]).map((item) => (+ <Badge key={String(item)} variant="secondary" className="text-foreground">+ {String(item)}+ </Badge>+ ))}+ </div>+ ) : empty ? (+ <span className="text-base text-foreground-faint">+ {t("profile_view.field_unknown")}+ </span>+ ) : (+ <span className="text-base text-foreground [overflow-wrap:anywhere]">+ {renderValue(t, value)}+ </span>+ )}+ <Button+ type="button"+ variant="ghost"+ size="icon"+ onClick={startEdit}+ title={t("profile_view.field_edit")}+ aria-label={`${t("profile_view.field_edit")}: ${label}`}+ className="h-8 w-8 shrink-0 text-muted-foreground opacity-0 transition-opacity focus-visible:opacity-100 group-hover:opacity-100"+ >+ {empty ? <Plus /> : <Pencil />}+ </Button>+ </dd>+ </div>+ );+ }++ // ------------------------------------------------------------------ editing+ return (+ <div className="-mx-2 rounded-md bg-secondary px-2 py-2">+ <dt className="text-base font-medium text-foreground-strong">{label}</dt>+ <dd className="mt-2">+ {kind === "bool" ? (+ <div className="flex flex-wrap items-center gap-2">+ {([true, false] as const).map((b) => (+ <Button+ key={String(b)}+ type="button"+ size="sm"+ variant={value === b ? "default" : "outline"}+ disabled={busy}+ onClick={() => mutate("set", b)}+ >+ {b ? t("profile_view.value_yes") : t("profile_view.value_no")}+ </Button>+ ))}+ <span className="ml-auto flex items-center gap-1">+ <RowIconButton+ icon={X}+ onClick={cancel}+ title={t("profile_view.raw_cancel")}+ disabled={busy}+ />+ {!empty && (+ <RowIconButton+ icon={Trash2}+ onClick={() => mutate("clear")}+ title={t("profile_view.field_clear")}+ disabled={busy}+ />+ )}+ </span>+ </div>+ ) : kind === "list" ? (+ <div className="flex flex-col gap-2">+ {!empty && (+ <div className="flex flex-wrap gap-1">+ {(value as unknown[]).map((item) => (+ <Badge key={String(item)} variant="outline" className="pr-1 text-foreground">+ {String(item)}+ <button+ type="button"+ disabled={busy}+ onClick={() => mutate("remove", String(item), { keepOpen: true })}+ title={t("profile_view.field_remove_item")}+ aria-label={`${t("profile_view.field_remove_item")}: ${String(item)}`}+ className="rounded-sm p-0.5 text-muted-foreground transition-colors hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50"+ >+ <X aria-hidden className="h-3 w-3" />+ </button>+ </Badge>+ ))}+ </div>+ )}+ <div className="flex items-center gap-1">+ <Input+ ref={inputRef}+ value={draft}+ disabled={busy}+ onChange={(e) => setDraft(e.target.value)}+ onKeyDown={(e) => {+ if (e.key === "Enter") addItem();+ if (e.key === "Escape") cancel();+ }}+ placeholder={t("profile_view.field_add_placeholder")}+ className="h-8"+ />+ <RowIconButton+ icon={Plus}+ onClick={addItem}+ title={t("profile_view.field_add")}+ variant="default"+ disabled={busy}+ />+ <RowIconButton+ icon={Check}+ onClick={cancel}+ title={t("profile_view.raw_save")}+ disabled={busy}+ />+ {!empty && (+ <RowIconButton+ icon={Trash2}+ onClick={() => mutate("clear")}+ title={t("profile_view.field_clear")}+ disabled={busy}+ />+ )}+ </div>+ </div>+ ) : (+ <div className="flex items-center gap-1">+ <Input+ ref={inputRef}+ value={draft}+ disabled={busy}+ onChange={(e) => setDraft(e.target.value)}+ onKeyDown={(e) => {+ if (e.key === "Enter") saveScalar();+ if (e.key === "Escape") cancel();+ }}+ placeholder={t("profile_view.field_value_placeholder")}+ className="h-8"+ />+ <RowIconButton+ icon={Check}+ onClick={saveScalar}+ title={t("profile_view.raw_save")}+ variant="default"+ disabled={busy}+ />+ <RowIconButton+ icon={X}+ onClick={cancel}+ title={t("profile_view.raw_cancel")}+ disabled={busy}+ />+ {!empty && (+ <RowIconButton+ icon={Trash2}+ onClick={() => mutate("clear")}+ title={t("profile_view.field_clear")}+ disabled={busy}+ />+ )}+ </div>+ )}+ </dd>+ </div>+ );+}diff --git a/jarvis/ui/web/frontend/src/views/profile/PeopleCard.tsx b/jarvis/ui/web/frontend/src/views/profile/PeopleCard.tsxnew file mode 100644index 0000000000..8fe6d668d5--- /dev/null+++ b/jarvis/ui/web/frontend/src/views/profile/PeopleCard.tsx@@ -0,0 +1,142 @@+/**+ * The people the curator has written a file for.+ *+ * A side-by-side list and detail pane does not fit a 340 px rail, so the+ * detail opens inside the row instead. One click selects AND expands — the+ * row-click doctrine the rest of the app follows, with the selected row+ * carrying the accent bar every selected row in this product wears.+ */+import { useState } from "react";+import { ChevronDown, Inbox, Users } from "lucide-react";++import { Badge } from "@/components/ui/badge";+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";+import { EmptyState } from "@/components/ui/empty-state";+import { IdentityAvatar } from "@/components/identity/IdentityAvatar";+import { useT } from "@/i18n";+import { cn } from "@/lib/utils";+import type { PersonSummary } from "@/views/profile/api";++export function PeopleCard({ people }: { people: PersonSummary[] }) {+ const t = useT();+ const [openSlug, setOpenSlug] = useState<string | null>(null);++ return (+ <Card className="flex flex-col">+ <CardHeader className="flex-row items-center justify-between gap-3 pb-2">+ <CardTitle className="truncate">{t("profile_view.section_people")}</CardTitle>+ {people.length > 0 && (+ <Badge variant="secondary" className="shrink-0 tabular-nums">+ {people.length}+ </Badge>+ )}+ </CardHeader>++ <CardContent>+ {people.length === 0 ? (+ <EmptyState+ className="max-w-none py-6"+ icon={<Users />}+ title={t("profile_view.people_empty_title")}+ description={t("profile_view.people_empty_body")}+ />+ ) : (+ <ul className="flex flex-col">+ {people.map((p) => (+ <PersonRow+ key={p.slug}+ person={p}+ open={p.slug === openSlug}+ onToggle={() => setOpenSlug(p.slug === openSlug ? null : p.slug)}+ />+ ))}+ </ul>+ )}+ </CardContent>+ </Card>+ );+}++function PersonRow({+ person,+ open,+ onToggle,+}: {+ person: PersonSummary;+ open: boolean;+ onToggle: () => void;+}) {+ const t = useT();++ return (+ <li>+ <button+ type="button"+ onClick={onToggle}+ aria-expanded={open}+ className={cn(+ "-mx-2 flex w-[calc(100%+1rem)] items-center gap-3 rounded-md px-2 py-2 text-left transition-colors",+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",+ open ? "bg-secondary jarvis-nav-active" : "hover:bg-secondary",+ )}+ >+ <IdentityAvatar name={person.name} size="sm" />+ <span className="min-w-0 flex-1">+ <span+ className={cn(+ "block truncate text-base",+ open ? "text-foreground-strong" : "text-foreground",+ )}+ >+ {person.name}+ </span>+ <span className="block truncate text-sm text-muted-foreground">+ {person.relationship}+ </span>+ </span>+ <ChevronDown+ aria-hidden+ className={cn(+ "h-4 w-4 shrink-0 text-muted-foreground transition-transform",+ open && "rotate-180",+ )}+ />+ </button>++ {open && (+ <div className="py-3 pl-11 pr-1">+ <dl className="flex flex-col gap-2">+ <div className="flex items-baseline justify-between gap-3">+ <dt className="shrink-0 text-base text-muted-foreground">+ {t("profile_view.person_relationship")}+ </dt>+ <dd className="min-w-0 text-right text-base text-foreground [overflow-wrap:anywhere]">+ {person.relationship}+ </dd>+ </div>+ <div className="flex items-baseline justify-between gap-3">+ <dt className="shrink-0 text-base text-muted-foreground">+ {t("profile_view.person_aliases")}+ </dt>+ <dd className="min-w-0 text-right [overflow-wrap:anywhere]">+ {person.aliases.length === 0 ? (+ <span className="text-base text-foreground-faint">+ {t("profile_view.person_no_aliases")}+ </span>+ ) : (+ <span className="text-base text-foreground">{person.aliases.join(" · ")}</span>+ )}+ </dd>+ </div>+ </dl>+ <p className="mt-3 flex items-start gap-2 text-sm text-muted-foreground">+ <Inbox aria-hidden className="mt-0.5 h-3.5 w-3.5 shrink-0" />+ <span className="min-w-0 [overflow-wrap:anywhere]">+ {t("profile_view.person_file_hint").replace("{0}", person.slug)}+ </span>+ </p>+ </div>+ )}+ </li>+ );+}diff --git a/jarvis/ui/web/frontend/src/views/profile/ReviewsCard.tsx b/jarvis/ui/web/frontend/src/views/profile/ReviewsCard.tsxnew file mode 100644index 0000000000..7405950074--- /dev/null+++ b/jarvis/ui/web/frontend/src/views/profile/ReviewsCard.tsx@@ -0,0 +1,252 @@+/**+ * The review queue — observations the curator is not confident enough to write+ * on its own.+ *+ * The one contract that must never regress: `GET /api/profile/reviews` answers+ * 503 when the legacy curator is soft-disabled, which is a DESIGNED state, not+ * a fault. It renders as a calm explanation; only a real failure gets the+ * destructive treatment. Both branches are pinned by ProfileView.test.tsx.+ */+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";+import { AlertTriangle, Check, ChevronRight, RefreshCw, ShieldQuestion, X } from "lucide-react";++import { Badge } from "@/components/ui/badge";+import { Button } from "@/components/ui/button";+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";+import { EmptyState } from "@/components/ui/empty-state";+import { IdentityAvatar } from "@/components/identity/IdentityAvatar";+import { useT } from "@/i18n";+import { cn } from "@/lib/utils";+import { useEventStore } from "@/store/events";+import {+ fetchJson,+ renderValue,+ statusOf,+ type ReviewCandidate,+ type ReviewsResponse,+} from "@/views/profile/api";++export function ReviewsCard({ reviewsCount }: { reviewsCount: number }) {+ const t = useT();+ const queryClient = useQueryClient();+ const pushToast = useEventStore((s) => s.pushToast);++ const { data, isLoading, error, refetch, isRefetching } = useQuery<ReviewsResponse, Error>({+ queryKey: ["profile", "reviews"],+ queryFn: () => fetchJson<ReviewsResponse>("/api/profile/reviews"),+ retry: false,+ });++ const accept = useMutation({+ mutationFn: (idx: number) =>+ fetchJson<{ ok: boolean; applied: number }>(`/api/profile/reviews/${idx}/accept`, {+ method: "POST",+ }),+ onSuccess: (res) => {+ pushToast(+ "success",+ res.applied > 0+ ? t("profile_toast.fact_applied").replace("{0}", String(res.applied))+ : t("profile_view.accepted"),+ );+ queryClient.invalidateQueries({ queryKey: ["profile"] });+ queryClient.invalidateQueries({ queryKey: ["profile", "reviews"] });+ },+ onError: (err: Error) => pushToast("error", err.message),+ });++ const reject = useMutation({+ mutationFn: (idx: number) =>+ fetchJson<{ ok: boolean }>(`/api/profile/reviews/${idx}/reject`, { method: "POST" }),+ onSuccess: () => {+ pushToast("info", t("profile_view.reject_tooltip"));+ queryClient.invalidateQueries({ queryKey: ["profile"] });+ queryClient.invalidateQueries({ queryKey: ["profile", "reviews"] });+ },+ onError: (err: Error) => pushToast("error", err.message),+ });++ const pendingIdx: number | null = accept.isPending+ ? (accept.variables ?? null)+ : reject.isPending+ ? (reject.variables ?? null)+ : null;++ const items = data?.reviews ?? [];++ return (+ <Card className="flex flex-col">+ <CardHeader className="flex-row items-center justify-between gap-3 pb-2">+ <span className="flex min-w-0 items-center gap-2">+ <CardTitle className="truncate">{t("profile_view.section_reviews")}</CardTitle>+ {reviewsCount > 0 && (+ <Badge variant="accent" className="shrink-0 tabular-nums">+ {reviewsCount}+ </Badge>+ )}+ </span>+ <Button+ type="button"+ variant="ghost"+ size="icon"+ className="h-8 w-8 shrink-0 text-muted-foreground"+ onClick={() => refetch()}+ disabled={isRefetching}+ title={t("profile_view.reload_tooltip")}+ aria-label={t("profile_view.reload_tooltip")}+ >+ <RefreshCw className={cn(isRefetching && "animate-spin")} />+ </Button>+ </CardHeader>++ <CardContent>+ {isLoading && (+ <div className="flex flex-col gap-3" aria-hidden>+ {[0, 1].map((i) => (+ <div key={i} className="flex flex-col gap-2">+ <div className="h-3 w-4/5 animate-pulse rounded-full bg-secondary" />+ <div className="h-3 w-2/5 animate-pulse rounded-full bg-secondary" />+ <div className="h-8 animate-pulse rounded-md bg-secondary" />+ </div>+ ))}+ </div>+ )}++ {error &&+ (statusOf(error) === 503 ? (+ // The curator is intentionally not running in this session. An+ // expected state, so it reads as an explanation, not an alarm.+ <div data-testid="reviews-disabled">+ <EmptyState+ className="max-w-none py-6"+ icon={<ShieldQuestion />}+ title={t("profile_view.reviews_disabled_title")}+ description={t("profile_view.reviews_disabled_body")}+ />+ </div>+ ) : (+ <p+ data-testid="reviews-error"+ className="flex items-start gap-2 rounded-md border border-destructive/20 bg-destructive/[0.12] p-3 text-base text-destructive"+ >+ <AlertTriangle aria-hidden className="mt-0.5 h-4 w-4 shrink-0" />+ <span className="min-w-0 [overflow-wrap:anywhere]">{error.message}</span>+ </p>+ ))}++ {data && items.length === 0 && (+ <EmptyState+ className="max-w-none py-6"+ icon={<ShieldQuestion />}+ title={t("profile_view.reviews_empty_title")}+ description={t("profile_view.reviews_empty_body")}+ />+ )}++ {items.length > 0 && (+ <ul className="flex flex-col">+ {items.map((c, i) => (+ <ReviewRow+ key={c.idx}+ candidate={c}+ first={i === 0}+ pending={pendingIdx === c.idx}+ onAccept={() => accept.mutate(c.idx)}+ onReject={() => reject.mutate(c.idx)}+ />+ ))}+ </ul>+ )}+ </CardContent>+ </Card>+ );+}++/**+ * One candidate. The evidence quote leads, because that is the sentence the+ * user actually said and the only thing they can judge the claim by; the+ * cluster → field path and the two verdicts sit under it.+ */+function ReviewRow({+ candidate,+ first,+ pending,+ onAccept,+ onReject,+}: {+ candidate: ReviewCandidate;+ first: boolean;+ pending: boolean;+ onAccept: () => void;+ onReject: () => void;+}) {+ const t = useT();+ // Who the observation is about — the coloured mark tells "about you" from+ // "about Anna" without reading the line.+ const subject = candidate.is_person+ ? (candidate.person_name ?? t("profile_view.review_subject_user"))+ : t("profile_view.review_subject_user");++ return (+ <li className={cn("py-4", !first && "border-t border-border")}>+ <div className="flex items-center gap-2">+ <IdentityAvatar name={subject} size="sm" />+ <span className="min-w-0 flex-1 truncate text-base text-foreground">{subject}</span>+ <span className="shrink-0 text-sm tabular-nums text-muted-foreground">+ {(candidate.confidence * 100).toFixed(0)}%+ </span>+ </div>++ {candidate.evidence && (+ <blockquote className="mt-3 border-l-2 border-border pl-3 text-base text-muted-foreground">+ “{candidate.evidence}”+ </blockquote>+ )}++ <div className="mt-3 flex flex-wrap items-center gap-1.5 text-sm text-muted-foreground">+ <span>{candidate.cluster}</span>+ <ChevronRight aria-hidden className="h-3 w-3" />+ <span className="text-foreground">{candidate.field}</span>+ <Badge variant="outline">{candidate.operation}</Badge>+ </div>++ <p className="mt-2 text-base">+ <span className="text-muted-foreground">{t("profile_view.review_value")}: </span>+ <span className="text-foreground [overflow-wrap:anywhere]">+ {renderValue(t, candidate.value) || t("profile_view.field_unknown")}+ </span>+ </p>++ {candidate.reason && (+ <p className="mt-1 text-sm text-muted-foreground">+ {t("profile_view.review_reason")}: {candidate.reason}+ </p>+ )}++ <div className="mt-3 flex gap-2">+ <Button+ size="sm"+ variant="default"+ className="flex-1"+ disabled={pending}+ onClick={onAccept}+ title={t("profile_view.accept_tooltip")}+ >+ <Check />+ {t("profile_view.review_confirm")}+ </Button>+ <Button+ size="sm"+ variant="outline"+ className="flex-1"+ disabled={pending}+ onClick={onReject}+ title={t("profile_view.reject_tooltip")}+ >+ <X />+ {t("profile_view.review_strike")}+ </Button>+ </div>+ </li>+ );+}diff --git a/jarvis/ui/web/frontend/src/views/profile/SourceCard.tsx b/jarvis/ui/web/frontend/src/views/profile/SourceCard.tsxnew file mode 100644index 0000000000..3f24bb8ff5--- /dev/null+++ b/jarvis/ui/web/frontend/src/views/profile/SourceCard.tsx@@ -0,0 +1,330 @@+/**+ * USER.md itself — rendered as the document it is, and editable by hand.+ *+ * Data flow: GET /api/profile/raw → React-Query cache. Live sync over the WS+ * bus: every Curator merge publishes ProfileUpdated, the subscriber below+ * invalidates both profile queries, and the file on screen is current seconds+ * after a write. The subscription lives in `useSourceDocument`, which the view+ * holds at its root — so it keeps running while the reader is on the knowledge+ * tab, and a background write still refreshes the ledger.+ *+ * The front matter is split off before rendering: the ledger already IS that+ * block drawn as fields, and printing it twice is the same facts in a worse+ * format. The curator's HTML anchors (`<!-- curator:observations:start -->`)+ * are machinery, not text — react-markdown escapes raw HTML instead of+ * rendering it, so leaving them in prints them verbatim on the page.+ */+import { useCallback, useEffect, useMemo, useState } from "react";+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";+import ReactMarkdown from "react-markdown";+import remarkGfm from "remark-gfm";+import { AlertTriangle, Clock, FileText, Lock, Pencil, RefreshCw, Save } from "lucide-react";++import { Button } from "@/components/ui/button";+import { Card, CardContent, CardHeader } from "@/components/ui/card";+import { EmptyState } from "@/components/ui/empty-state";+import { Textarea } from "@/components/ui/textarea";+import { PROSE_BASE, splitFrontMatter } from "@/components/outputs/MarkdownProse";+import { getWSClient } from "@/hooks/useWebSocket";+import { useT } from "@/i18n";+import { cn } from "@/lib/utils";+import { useEventStore } from "@/store/events";+import { fetchJson, type RawProfileResponse } from "@/views/profile/api";++export interface SourceDocument {+ data: RawProfileResponse | undefined;+ isLoading: boolean;+ error: Error | null;+ isRefetching: boolean;+ refetch: () => void;+ editing: boolean;+ draft: string;+ setDraft: (value: string) => void;+ startEditing: () => void;+ cancelEditing: () => void;+ save: () => void;+ isSaving: boolean;+ /** True for a couple of seconds after a ProfileUpdated event landed. */+ pulsing: boolean;+ /** The document body with front matter and curator anchors removed. */+ body: string;+}++/**+ * Owns the raw file: the query, the live subscription, the draft and the save.+ * Held by the view root so the subscription survives a tab switch.+ */+export function useSourceDocument(): SourceDocument {+ const t = useT();+ const queryClient = useQueryClient();+ const pushToast = useEventStore((s) => s.pushToast);+ const [pulsing, setPulsing] = useState(false);++ // `draft` is the working copy; `editBaseMtime` is frozen at edit-start so the+ // backend's optimistic-concurrency guard stays meaningful even if a+ // background refetch moves `data.mtime_ms` underneath us.+ const [editing, setEditing] = useState(false);+ const [draft, setDraft] = useState("");+ const [editBaseMtime, setEditBaseMtime] = useState<number | null>(null);++ const { data, isLoading, error, refetch, isRefetching } = useQuery<RawProfileResponse, Error>({+ queryKey: ["profile", "raw"],+ queryFn: () => fetchJson<RawProfileResponse>("/api/profile/raw"),+ retry: false,+ staleTime: 0,+ });++ useEffect(() => {+ const client = getWSClient();+ if (!client) return;+ const unsubscribe = client.subscribe((raw) => {+ const env = raw as { event_name?: unknown };+ if (env.event_name !== "ProfileUpdated") return;+ // The ledger always refreshes…+ queryClient.invalidateQueries({ queryKey: ["profile"] });+ // …but the raw text is never replaced while it is being edited: that+ // would wipe the draft mid-keystroke.+ if (!editing) {+ queryClient.invalidateQueries({ queryKey: ["profile", "raw"] });+ }+ setPulsing(true);+ });+ return unsubscribe;+ }, [queryClient, editing]);++ useEffect(() => {+ if (!pulsing) return;+ const id = window.setTimeout(() => setPulsing(false), 2000);+ return () => window.clearTimeout(id);+ }, [pulsing]);++ const saveMutation = useMutation({+ mutationFn: async (content: string) => {+ const res = await fetch("/api/profile/raw", {+ method: "PUT",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ content, mtime_ms: editBaseMtime }),+ });+ if (!res.ok) {+ const body = (await res.json().catch(() => ({}))) as { detail?: string };+ const err = new Error(body.detail ?? `HTTP ${res.status}`) as Error & { status?: number };+ err.status = res.status;+ throw err;+ }+ return res.json() as Promise<{+ ok: boolean;+ mtime_ms: number | null;+ frontmatter_ok: boolean;+ }>;+ },+ onSuccess: (res) => {+ setEditing(false);+ if (res.frontmatter_ok === false) {+ pushToast("error", t("profile_view.raw_frontmatter_warning"));+ } else {+ pushToast("success", t("profile_view.raw_saved"));+ }+ queryClient.invalidateQueries({ queryKey: ["profile"] });+ queryClient.invalidateQueries({ queryKey: ["profile", "raw"] });+ },+ onError: (err: Error) => pushToast("error", err.message),+ });++ const startEditing = useCallback(() => {+ setDraft(data?.content ?? "");+ setEditBaseMtime(data?.mtime_ms ?? null);+ setEditing(true);+ }, [data?.content, data?.mtime_ms]);++ const cancelEditing = useCallback(() => setEditing(false), []);++ // Escape leaves edit mode, the way it cancels every other inline editor in+ // this view. The draft is dropped, which is why the button says Cancel.+ useEffect(() => {+ if (!editing) return;+ const onKey = (e: KeyboardEvent) => {+ if (e.key === "Escape") setEditing(false);+ };+ window.addEventListener("keydown", onKey);+ return () => window.removeEventListener("keydown", onKey);+ }, [editing]);++ const body = useMemo(() => {+ if (!data) return "";+ return splitFrontMatter(data.content)+ .body.replace(/<!--[\s\S]*?-->/g, "")+ .replace(/[ \t]+$/gm, "")+ .replace(/\n{3,}/g, "\n\n")+ .trim();+ }, [data]);++ return {+ data,+ isLoading,+ error,+ isRefetching,+ refetch: () => void refetch(),+ editing,+ draft,+ setDraft,+ startEditing,+ cancelEditing,+ save: () => saveMutation.mutate(draft),+ isSaving: saveMutation.isPending,+ pulsing,+ body,+ };+}++export function SourceCard({ doc }: { doc: SourceDocument }) {+ const t = useT();+ const lastUpdate = doc.data?.mtime_ms ? new Date(doc.data.mtime_ms) : null;++ return (+ <Card className="profile-rise flex flex-col">+ <CardHeader className="flex-row flex-wrap items-center justify-between gap-x-3 gap-y-2 pb-3">+ <span className="flex min-w-0 items-center gap-2">+ <FileText aria-hidden className="h-4 w-4 shrink-0 text-muted-foreground" />+ <span className="text-lg font-semibold text-foreground-strong">+ {t("profile_view.section_source")}+ </span>+ {doc.data && (+ <span className="min-w-0 truncate font-mono text-sm text-muted-foreground">+ {doc.data.path}+ </span>+ )}+ </span>++ <span className="flex shrink-0 items-center gap-2">+ {doc.editing ? (+ <>+ <span className="hidden items-center gap-1.5 text-sm text-muted-foreground xl:flex">+ <Lock aria-hidden className="h-3.5 w-3.5 shrink-0" />+ {t("profile_view.raw_editing_hint")}+ </span>+ <Button+ size="sm"+ variant="ghost"+ onClick={doc.cancelEditing}+ disabled={doc.isSaving}+ >+ {t("profile_view.raw_cancel")}+ </Button>+ <Button size="sm" variant="default" onClick={doc.save} disabled={doc.isSaving}>+ <Save className={cn(doc.isSaving && "animate-pulse")} />+ {doc.isSaving ? t("profile_view.raw_saving") : t("profile_view.raw_save")}+ </Button>+ </>+ ) : (+ <>+ {/* Something just wrote to the file. That is the section's one+ live signal, so it is what --success is spent on here. */}+ {doc.pulsing && (+ <span className="inline-flex items-center gap-1.5 rounded-md border border-success/20 bg-success/[0.12] px-2 py-0.5 text-sm text-success">+ <span className="relative flex h-1.5 w-1.5">+ <span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-success opacity-75" />+ <span className="relative inline-flex h-1.5 w-1.5 rounded-full bg-success" />+ </span>+ {t("profile_view.just_updated")}+ </span>+ )}+ {lastUpdate && (+ <span className="hidden items-center gap-1.5 text-sm text-muted-foreground xl:inline-flex">+ <Clock aria-hidden className="h-3.5 w-3.5 shrink-0" />+ {t("profile_view.source_updated").replace(+ "{0}",+ lastUpdate.toLocaleDateString(),+ )}+ </span>+ )}+ <Button+ type="button"+ variant="ghost"+ size="icon"+ className="h-8 w-8 text-muted-foreground"+ onClick={doc.refetch}+ disabled={doc.isRefetching}+ title={t("profile_view.reload_tooltip")}+ aria-label={t("profile_view.reload_tooltip")}+ >+ <RefreshCw className={cn(doc.isRefetching && "animate-spin")} />+ </Button>+ {doc.data && (+ <Button size="sm" variant="outline" onClick={doc.startEditing}>+ <Pencil />+ {t("profile_view.raw_edit")}+ </Button>+ )}+ </>+ )}+ </span>+ </CardHeader>++ <CardContent>+ {doc.isLoading && (+ <div className="flex max-w-reading flex-col gap-3" aria-hidden>+ <div className="h-5 w-1/3 animate-pulse rounded-md bg-secondary" />+ {[0, 1, 2, 3].map((i) => (+ <div+ key={i}+ className={cn(+ "h-3 animate-pulse rounded-full bg-secondary",+ i === 3 ? "w-4/5" : "w-full",+ )}+ />+ ))}+ </div>+ )}++ {doc.error && (+ <p className="flex items-start gap-2 rounded-md border border-destructive/20 bg-destructive/[0.12] p-3 text-base text-destructive">+ <AlertTriangle aria-hidden className="mt-0.5 h-4 w-4 shrink-0" />+ <span className="min-w-0 [overflow-wrap:anywhere]">{doc.error.message}</span>+ </p>+ )}++ {doc.data &&+ (doc.editing ? (+ <Textarea+ value={doc.draft}+ onChange={(e) => doc.setDraft(e.target.value)}+ spellCheck={false}+ autoFocus+ rows={26}+ aria-label={doc.data.path}+ className="resize-y font-mono leading-6 scrollbar-jarvis"+ />+ ) : doc.body ? (+ // A profile is a document, so it is set at the reading step in full+ // ink and bounded to a reading measure — not muted text under+ // small-caps headings, which reads as something somebody disabled.+ <article+ data-testid="profile-source-markdown"+ className={cn(+ PROSE_BASE,+ "max-w-reading text-base leading-7 text-foreground",+ "prose-headings:text-foreground-strong",+ "prose-h1:text-xl prose-h2:text-lg prose-h3:text-lg",+ "prose-blockquote:border-l-2 prose-blockquote:border-border prose-blockquote:pl-4 prose-blockquote:font-normal prose-blockquote:not-italic prose-blockquote:text-muted-foreground",+ "prose-p:text-foreground prose-li:text-foreground prose-strong:text-foreground-strong",+ )}+ >+ <ReactMarkdown remarkPlugins={[remarkGfm]}>{doc.body}</ReactMarkdown>+ </article>+ ) : (+ <EmptyState+ icon={<FileText />}+ title={t("profile_view.source_empty_title")}+ description={t("profile_view.source_empty_body")}+ actions={+ <Button size="sm" variant="default" onClick={doc.startEditing}>+ <Pencil />+ {t("profile_view.raw_edit")}+ </Button>+ }+ />+ ))}+ </CardContent>+ </Card>+ );+}diff --git a/jarvis/ui/web/frontend/src/views/profile/api.ts b/jarvis/ui/web/frontend/src/views/profile/api.tsnew file mode 100644index 0000000000..e68b471692--- /dev/null+++ b/jarvis/ui/web/frontend/src/views/profile/api.ts@@ -0,0 +1,153 @@+/**+ * The Profile view's data layer — the shapes `profile_routes.py` returns, one+ * fetch helper, and the shared field mutation.+ *+ * The one subtlety worth keeping: a 503 from the profile endpoints is NOT a+ * failure. The legacy Curator is soft-disabled by design, and the backend+ * contract says the UI renders that as a calm, explained state rather than a+ * red badge — so the status code is carried on the Error and every caller can+ * tell "intentionally off" from "actually broken".+ */+import { useMutation, useQueryClient } from "@tanstack/react-query";++import { useEventStore } from "@/store/events";+import type { ClusterId } from "@/views/profile/ledger";++// ----------------------------------------------------------------------+// Response shapes — mirror jarvis/ui/web/profile_routes.py+// ----------------------------------------------------------------------++export interface PersonSummary {+ name: string;+ relationship: string;+ aliases: string[];+ slug: string;+}++export interface ProfileResponse {+ user: {+ name: string | null;+ meta: Record<string, unknown>;+ path: string;+ };+ people: PersonSummary[];+ reviews_count: number;+ has_avatar?: boolean;+}++export interface ReviewCandidate {+ idx: number;+ subject: string;+ is_person: boolean;+ person_name: string | null;+ cluster: string;+ field: string;+ value: unknown;+ operation: string;+ confidence: number;+ evidence: string;+ relationship: string | null;+ reason: string;+}++export interface ReviewsResponse {+ reviews: ReviewCandidate[];+ total: number;+}++export interface RawProfileResponse {+ content: string;+ path: string;+ mtime_ms: number | null;+ size_bytes: number;+}++/** An Error that carries the HTTP status, so a 503 can be told apart. */+export type HttpError = Error & { status?: number };++/** The status a caller can read off any error thrown by `fetchJson`. */+export function statusOf(error: unknown): number | undefined {+ return (error as HttpError | null)?.status;+}++// ----------------------------------------------------------------------+// Fetching+// ----------------------------------------------------------------------++export async function fetchJson<T>(url: string, init?: RequestInit): Promise<T> {+ const res = await fetch(url, init);+ if (!res.ok) {+ if (res.status === 503) {+ const data = await res.json().catch(() => ({ detail: "Profile system not ready." }));+ const err = new Error(data.detail ?? `HTTP ${res.status}`) as HttpError;+ err.status = 503;+ throw err;+ }+ const txt = await res.text().catch(() => "");+ const err = new Error(`HTTP ${res.status}: ${txt || res.statusText}`) as HttpError;+ err.status = res.status;+ throw err;+ }+ return res.json();+}++// ----------------------------------------------------------------------+// Field editing+// ----------------------------------------------------------------------++export type FieldOp = "set" | "clear" | "append" | "remove";++export interface FieldEditBody {+ cluster: ClusterId;+ field: string;+ operation: FieldOp;+ value?: unknown;+}++/**+ * PATCH /api/profile/field. Invalidates the profile query on success so the+ * ledger re-renders from the persisted value rather than from an optimistic+ * guess — the file on disk is the source of truth here, not this component.+ */+export function useFieldEdit() {+ const queryClient = useQueryClient();+ const pushToast = useEventStore((s) => s.pushToast);+ return useMutation({+ mutationFn: async (body: FieldEditBody) => {+ const res = await fetch("/api/profile/field", {+ method: "PATCH",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify(body),+ });+ if (!res.ok) {+ const data = (await res.json().catch(() => ({}))) as { detail?: string };+ throw new Error(data.detail ?? `HTTP ${res.status}`);+ }+ return res.json();+ },+ onSuccess: () => queryClient.invalidateQueries({ queryKey: ["profile"] }),+ onError: (err: Error) => pushToast("error", err.message),+ });+}++// ----------------------------------------------------------------------+// Display helpers+// ----------------------------------------------------------------------++/** One field value as a readable string; booleans go through the locale. */+export function renderValue(t: (key: string) => string, value: unknown): string {+ if (Array.isArray(value)) return value.map(String).join(" · ");+ if (typeof value === "boolean") {+ return value ? t("profile_view.value_yes") : t("profile_view.value_no");+ }+ return String(value ?? "");+}++/** The sub-object one cluster keeps inside USER.md's front matter. */+export function clusterDataOf(+ meta: Record<string, unknown>,+ cluster: ClusterId,+): Record<string, unknown> {+ const raw = meta[cluster];+ return raw && typeof raw === "object" ? (raw as Record<string, unknown>) : {};+}