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(contacts): profile fields, vCard, deep link + narrow layout in the UI
rubenluetke10-beep83482a45a65b
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.jsonindex 72bdd0306e..9e68e1ba1f 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json@@ -229,6 +229,20 @@"discardBody": "Du hast ungespeicherte Änderungen.","discard": "Verwerfen","keepEditing": "Weiter bearbeiten",+ "organization": "Firma",+ "role": "Rolle",+ "birthday": "Geburtstag",+ "urls": "Links",+ "addUrl": "Link hinzufügen",+ "tags": "Tags",+ "addTag": "Tag hinzufügen…",+ "favorite": "Favorit",+ "favorites": "Favoriten",+ "back": "Zurück",+ "import": "vCard importieren",+ "export": "vCard exportieren",+ "importDone": "Import: {0} neu, {1} aktualisiert, {2} übersprungen.",+ "importFailed": "Import fehlgeschlagen:","rel": {"family": "Familie","friend": "Freund",diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.jsonindex ac8cc9ddbe..2645be7d18 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json@@ -229,6 +229,20 @@"discardBody": "You have unsaved changes.","discard": "Discard","keepEditing": "Keep editing",+ "organization": "Organization",+ "role": "Role",+ "birthday": "Birthday",+ "urls": "Links",+ "addUrl": "Add link",+ "tags": "Tags",+ "addTag": "Add tag…",+ "favorite": "Favorite",+ "favorites": "Favorites",+ "back": "Back",+ "import": "Import vCard",+ "export": "Export vCard",+ "importDone": "Imported: {0} new, {1} updated, {2} skipped.",+ "importFailed": "Import failed:","rel": {"family": "Family","friend": "Friend",diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.jsonindex 4581d65db4..78376e198d 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json@@ -229,6 +229,20 @@"discardBody": "Tienes cambios sin guardar.","discard": "Descartar","keepEditing": "Seguir editando",+ "organization": "Organización",+ "role": "Cargo",+ "birthday": "Cumpleaños",+ "urls": "Enlaces",+ "addUrl": "Añadir enlace",+ "tags": "Etiquetas",+ "addTag": "Añadir etiqueta…",+ "favorite": "Favorito",+ "favorites": "Favoritos",+ "back": "Atrás",+ "import": "Importar vCard",+ "export": "Exportar vCard",+ "importDone": "Importación: {0} nuevos, {1} actualizados, {2} omitidos.",+ "importFailed": "Error de importación:","rel": {"family": "Familia","friend": "Amigo",diff --git a/jarvis/ui/web/frontend/src/views/contacts/ContactDetail.tsx b/jarvis/ui/web/frontend/src/views/contacts/ContactDetail.tsxindex 533a604159..84ddd1355a 100644--- a/jarvis/ui/web/frontend/src/views/contacts/ContactDetail.tsx+++ b/jarvis/ui/web/frontend/src/views/contacts/ContactDetail.tsx@@ -1,24 +1,30 @@import { useEffect, useState } from "react";import {+ ArrowLeft,BookOpen,+ Cake,Check,Copy,+ Link2,Loader2,Mail,MapPin,Pencil,Phone,PhoneCall,+ Star,+ Tag,Trash2,} from "lucide-react";import ReactMarkdown from "react-markdown";import remarkGfm from "remark-gfm";import { useT } from "@/i18n";+import { cn } from "@/lib/utils";import { useEventStore } from "@/store/events";import { relationshipLabel } from "./constants";import { contactAvatarStyle, contactInitials } from "./avatar";-import type { Contact } from "./api";+import { updateContact, type Contact } from "./api";/*** The detail (right) pane for the selected contact — a read view with actions:@@ -49,10 +55,16 @@ export function ContactDetail({contact,onEdit,onDelete,+ onBack,+ onChanged,}: {contact: Contact;onEdit: () => void;onDelete: () => void;+ /** Present only in the narrow (stacked) layout: return to the list. */+ onBack?: () => void;+ /** Inform the parent after an in-place PATCH (favorite toggle). */+ onChanged?: (contact: Contact) => void;}) {const t = useT();const requestWikiPage = useEventStore((s) => s.requestWikiPage);@@ -60,10 +72,25 @@ export function ContactDetail({const rel = relationshipLabel(t, contact.relationship);const addr = formatAddress(contact);const updated = formatUpdated(contact.last_updated);+ const orgLine = [contact.organization, contact.role].filter(Boolean).join(" · ");const [callable, setCallable] = useState(false);const [confirmCall, setConfirmCall] = useState<string | null>(null);const [calling, setCalling] = useState(false);+ const [togglingFav, setTogglingFav] = useState(false);++ async function toggleFavorite() {+ if (togglingFav) return;+ setTogglingFav(true);+ try {+ const next = await updateContact(contact.slug, { favorite: !contact.favorite });+ onChanged?.(next);+ } catch (e) {+ pushToast("error", e instanceof Error ? e.message : String(e));+ } finally {+ setTogglingFav(false);+ }+ }useEffect(() => {let cancelled = false;@@ -106,6 +133,16 @@ export function ContactDetail({<div className="flex h-full flex-col overflow-y-auto scrollbar-jarvis"><div className="border-b border-border p-6"><div className="flex items-start gap-4">+ {onBack && (+ <button+ type="button"+ onClick={onBack}+ aria-label={t("contacts.back")}+ className="mt-1 shrink-0 rounded-md border border-border p-1.5 text-muted-foreground hover:border-primary/40 hover:text-foreground"+ >+ <ArrowLeft className="h-4 w-4" />+ </button>+ )}<spanaria-hiddenstyle={contactAvatarStyle(contact.name)}@@ -115,6 +152,9 @@ export function ContactDetail({</span><div className="min-w-0 flex-1"><h3 className="font-display text-lg font-semibold tracking-tight">{contact.name}</h3>+ {orgLine && (+ <p className="truncate text-xs text-muted-foreground">{orgLine}</p>+ )}{contact.aliases.length > 0 && (<p className="truncate text-xs text-muted-foreground">{t("contacts.aliases")}: {contact.aliases.join(", ")}@@ -134,6 +174,21 @@ export function ContactDetail({</div></div><div className="flex shrink-0 items-center gap-2">+ <button+ type="button"+ onClick={() => void toggleFavorite()}+ aria-label={t("contacts.favorite")}+ title={t("contacts.favorite")}+ disabled={togglingFav}+ className={cn(+ "rounded-md border border-border p-1.5 transition-colors disabled:opacity-50",+ contact.favorite+ ? "border-primary/40 text-primary"+ : "text-muted-foreground hover:border-primary/40 hover:text-foreground",+ )}+ >+ <Star className={cn("h-3.5 w-3.5", contact.favorite && "fill-current")} />+ </button><buttontype="button"onClick={onEdit}@@ -212,6 +267,32 @@ export function ContactDetail({</Field>)}+ {contact.birthday && (+ <Field icon={<Cake className="h-4 w-4" />} label={t("contacts.birthday")}>+ <p className="text-sm text-foreground">{formatBirthday(contact.birthday)}</p>+ </Field>+ )}++ {contact.urls.length > 0 && (+ <Field icon={<Link2 className="h-4 w-4" />} label={t("contacts.urls")}>+ <ul className="space-y-1">+ {contact.urls.map((u) => (+ <li key={u} className="flex items-center gap-1.5">+ <a+ href={u.includes("://") ? u : `https://${u}`}+ target="_blank"+ rel="noreferrer"+ className="truncate text-sm text-primary hover:underline"+ >+ {u}+ </a>+ <CopyButton value={u} label={t("contacts.copy")} />+ </li>+ ))}+ </ul>+ </Field>+ )}+{addr && (<Field icon={<MapPin className="h-4 w-4" />} label={t("contacts.address")}><div className="flex items-start gap-1.5">@@ -221,6 +302,21 @@ export function ContactDetail({</Field>)}+ {contact.tags.length > 0 && (+ <Field icon={<Tag className="h-4 w-4" />} label={t("contacts.tags")}>+ <div className="flex flex-wrap gap-1.5">+ {contact.tags.map((tag) => (+ <span+ key={tag}+ className="rounded-full border border-border px-2 py-0.5 text-xs text-muted-foreground"+ >+ #{tag}+ </span>+ ))}+ </div>+ </Field>+ )}+{contact.note.trim() && (<Field label={t("contacts.readme")}><article className="prose prose-neutral max-w-none text-sm dark:prose-invert prose-a:text-primary prose-code:text-foreground prose-pre:border prose-pre:border-border prose-pre:bg-card/80">@@ -333,3 +429,10 @@ function formatUpdated(iso: string | null): string | null {if (Number.isNaN(date.getTime())) return null;return date.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" });}++function formatBirthday(iso: string): string {+ // Parse as a plain date (no timezone shifts): "1990-04-12" stays April 12.+ const [y, m, d] = iso.split("-").map(Number);+ if (!y || !m || !d) return iso;+ return new Date(y, m - 1, d).toLocaleDateString(undefined, { dateStyle: "long" });+}diff --git a/jarvis/ui/web/frontend/src/views/contacts/ContactEditDialog.tsx b/jarvis/ui/web/frontend/src/views/contacts/ContactEditDialog.tsxindex 8cc9580a95..1476a41940 100644--- a/jarvis/ui/web/frontend/src/views/contacts/ContactEditDialog.tsx+++ b/jarvis/ui/web/frontend/src/views/contacts/ContactEditDialog.tsx@@ -14,12 +14,12 @@ import {/*** Create / edit a contact. `initial === null` → create (POST); otherwise edit* (PATCH the existing slug). Non-blocking modal, same shape as PairDialog —- * but closing with unsaved changes asks before discarding. Aliases are chips- * (Enter/comma commits, Backspace removes), e-mail/phone fields validate with- * the same rules the store applies server-side, and a phone that will be- * normalised shows its stored form up front. Esc closes (guarded),- * Ctrl/Cmd+Enter saves. The README field keeps its live word counter (the- * store is designed for a short ~300-word bio).+ * but closing with unsaved changes asks before discarding. Aliases and tags+ * are chips (Enter/comma commits, Backspace removes), e-mail/phone fields+ * validate with the same rules the store applies server-side, and a phone+ * that will be normalised shows its stored form up front. Esc closes+ * (guarded), Ctrl/Cmd+Enter saves. The README field keeps its live word+ * counter (the store is designed for a short ~300-word bio).*/// Mirrors jarvis/contacts/store.py: _EMAIL_RE and _normalize_phone. Kept in@@ -51,12 +51,20 @@ export function ContactEditDialog({const [relationship, setRelationship] = useState<Relationship | "">(initial?.relationship ?? "",);+ const [organization, setOrganization] = useState(initial?.organization ?? "");+ const [role, setRole] = useState(initial?.role ?? "");+ const [birthday, setBirthday] = useState(initial?.birthday ?? "");+ const [tags, setTags] = useState<string[]>(initial?.tags ?? []);+ const [tagDraft, setTagDraft] = useState("");const [emails, setEmails] = useState<string[]>(initial?.emails?.length ? initial.emails : [""],);const [phones, setPhones] = useState<string[]>(initial?.phones?.length ? initial.phones : [""],);+ const [urls, setUrls] = useState<string[]>(+ initial?.urls?.length ? initial.urls : [""],+ );const [street, setStreet] = useState(initial?.address?.street ?? "");const [postal, setPostal] = useState(initial?.address?.postal_code ?? "");const [city, setCity] = useState(initial?.address?.city ?? "");@@ -69,10 +77,10 @@ export function ContactEditDialog({const wordCount = note.trim() ? note.trim().split(/\s+/).length : 0;// Dirty tracking: snapshot the form once on mount, compare on every close- // request. Cheap (JSON of a dozen small strings) and exact.+ // request. Cheap (JSON of a few small strings) and exact.const formSnapshot = JSON.stringify({- name, aliases, aliasDraft, relationship, emails, phones,- street, postal, city, country, note,+ name, aliases, aliasDraft, relationship, organization, role, birthday,+ tags, tagDraft, emails, phones, urls, street, postal, city, country, note,});const initialSnapshot = useRef(formSnapshot);const dirty = formSnapshot !== initialSnapshot.current;@@ -107,17 +115,10 @@ export function ContactEditDialog({const hasInvalidField =emailErrors.some(Boolean) || phoneErrors.some(Boolean);- function commitAliasDraft(): string[] {- const value = aliasDraft.trim().replace(/,+$/, "");- if (!value) return aliases;- if (aliases.includes(value)) {- setAliasDraft("");- return aliases;- }- const next = [...aliases, value];- setAliases(next);- setAliasDraft("");- return next;+ function commitDraft(values: string[], draft: string): string[] {+ const value = draft.trim().replace(/,+$/, "");+ if (!value || values.includes(value)) return values;+ return [...values, value];}async function handleSave() {@@ -129,8 +130,14 @@ export function ContactEditDialog({if (hasInvalidField || saving) return;const payload: ContactInput = {name: name.trim(),- aliases: commitAliasDraft(),+ aliases: commitDraft(aliases, aliasDraft),relationship: relationship === "" ? null : relationship,+ favorite: initial?.favorite ?? false,+ birthday: birthday.trim() || null,+ organization: organization.trim() || null,+ role: role.trim() || null,+ urls: urls.map((u) => u.trim()).filter(Boolean),+ tags: commitDraft(tags, tagDraft),emails: emails.map((e) => e.trim()).filter(Boolean),phones: phones.map((p) => p.trim()).filter(Boolean),address: {@@ -204,63 +211,15 @@ export function ContactEditDialog({/></Labeled>- <Labeled label={t("contacts.aliases")}>- <div- className={cn(- inputClass,- "flex min-h-[2.1rem] flex-wrap items-center gap-1.5 py-1",- )}- >- {aliases.map((alias) => (- <span- key={alias}- className="inline-flex items-center gap-1 rounded-full bg-primary/15 px-2 py-0.5 text-xs text-primary"- >- {alias}- <button- type="button"- aria-label={`${t("contacts.delete")} ${alias}`}- onClick={() => setAliases(aliases.filter((a) => a !== alias))}- className="text-primary/70 hover:text-primary"- >- <X className="h-3 w-3" />- </button>- </span>- ))}- <input- value={aliasDraft}- onChange={(e) => {- // A comma commits, exactly like Enter — people paste- // "Chris, Chrissi" and expect chips.- if (e.target.value.includes(",")) {- const parts = e.target.value.split(",");- const last = parts.pop() ?? "";- const committed = parts.map((p) => p.trim()).filter(Boolean);- if (committed.length) {- setAliases((prev) => [- ...prev,- ...committed.filter((p) => !prev.includes(p)),- ]);- }- setAliasDraft(last);- } else {- setAliasDraft(e.target.value);- }- }}- onKeyDown={(e) => {- if (e.key === "Enter") {- e.preventDefault();- commitAliasDraft();- } else if (e.key === "Backspace" && !aliasDraft && aliases.length) {- setAliases(aliases.slice(0, -1));- }- }}- onBlur={() => commitAliasDraft()}- placeholder={aliases.length ? "" : t("contacts.addAlias")}- className="min-w-[6rem] flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground/60"- />- </div>- </Labeled>+ <ChipsField+ label={t("contacts.aliases")}+ values={aliases}+ onChange={setAliases}+ draft={aliasDraft}+ onDraftChange={setAliasDraft}+ placeholder={t("contacts.addAlias")}+ removeLabel={t("contacts.delete")}+ /><Labeled label={t("contacts.relationship")}><BrandedSelect@@ -280,6 +239,38 @@ export function ContactEditDialog({/></Labeled>+ <div className="flex gap-2">+ <div className="flex-1">+ <Labeled label={t("contacts.organization")}>+ <input+ value={organization}+ onChange={(e) => setOrganization(e.target.value)}+ className={inputClass}+ placeholder="ACME GmbH"+ />+ </Labeled>+ </div>+ <div className="flex-1">+ <Labeled label={t("contacts.role")}>+ <input+ value={role}+ onChange={(e) => setRole(e.target.value)}+ className={inputClass}+ placeholder="CTO"+ />+ </Labeled>+ </div>+ </div>++ <Labeled label={t("contacts.birthday")}>+ <input+ type="date"+ value={birthday}+ onChange={(e) => setBirthday(e.target.value)}+ className={inputClass}+ />+ </Labeled>+<ListFieldlabel={t("contacts.emails")}values={emails}@@ -301,6 +292,25 @@ export function ContactEditDialog({hints={phoneHints}/>+ <ListField+ label={t("contacts.urls")}+ values={urls}+ onChange={setUrls}+ placeholder="https://example.com"+ type="url"+ addLabel={t("contacts.addUrl")}+ />++ <ChipsField+ label={t("contacts.tags")}+ values={tags}+ onChange={setTags}+ draft={tagDraft}+ onDraftChange={setTagDraft}+ placeholder={t("contacts.addTag")}+ removeLabel={t("contacts.delete")}+ />+<Labeled label={t("contacts.address")}><div className="space-y-2"><input@@ -416,6 +426,96 @@ function Labeled({ label, children }: { label: string; children: React.ReactNode);}+/** Chip editor for short string lists (aliases, tags): Enter/comma commits+ * the draft, Backspace on an empty draft removes the last chip. The draft+ * lives in the parent so an uncommitted value still lands on Save. */+function ChipsField({+ label,+ values,+ onChange,+ draft,+ onDraftChange,+ placeholder,+ removeLabel,+}: {+ label: string;+ values: string[];+ onChange: (next: string[]) => void;+ draft: string;+ onDraftChange: (next: string) => void;+ placeholder: string;+ removeLabel: string;+}) {+ function commit() {+ const value = draft.trim().replace(/,+$/, "");+ if (!value) return;+ if (!values.includes(value)) onChange([...values, value]);+ onDraftChange("");+ }+ return (+ <div className="space-y-1">+ <span className="text-[10px] uppercase tracking-wider text-muted-foreground">+ {label}+ </span>+ <div+ className={cn(+ inputClass,+ "flex min-h-[2.1rem] flex-wrap items-center gap-1.5 py-1",+ )}+ >+ {values.map((value) => (+ <span+ key={value}+ className="inline-flex items-center gap-1 rounded-full bg-primary/15 px-2 py-0.5 text-xs text-primary"+ >+ {value}+ <button+ type="button"+ aria-label={`${removeLabel} ${value}`}+ onClick={() => onChange(values.filter((v) => v !== value))}+ className="text-primary/70 hover:text-primary"+ >+ <X className="h-3 w-3" />+ </button>+ </span>+ ))}+ <input+ value={draft}+ onChange={(e) => {+ // A comma commits, exactly like Enter — people paste+ // "Chris, Chrissi" and expect chips.+ if (e.target.value.includes(",")) {+ const parts = e.target.value.split(",");+ const last = parts.pop() ?? "";+ const committed = parts.map((p) => p.trim()).filter(Boolean);+ if (committed.length) {+ onChange([+ ...values,+ ...committed.filter((p) => !values.includes(p)),+ ]);+ }+ onDraftChange(last);+ } else {+ onDraftChange(e.target.value);+ }+ }}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ e.preventDefault();+ commit();+ } else if (e.key === "Backspace" && !draft && values.length) {+ onChange(values.slice(0, -1));+ }+ }}+ onBlur={commit}+ placeholder={values.length ? "" : placeholder}+ className="min-w-[6rem] flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground/60"+ />+ </div>+ </div>+ );+}+function ListField({label,values,diff --git a/jarvis/ui/web/frontend/src/views/contacts/ContactRow.tsx b/jarvis/ui/web/frontend/src/views/contacts/ContactRow.tsxindex fd7a0d0d1d..050e8c775a 100644--- a/jarvis/ui/web/frontend/src/views/contacts/ContactRow.tsx+++ b/jarvis/ui/web/frontend/src/views/contacts/ContactRow.tsx@@ -1,3 +1,5 @@+import { Star } from "lucide-react";+import { cn } from "@/lib/utils";import { useT } from "@/i18n";import { relationshipLabel } from "./constants";@@ -42,6 +44,9 @@ export function ContactRow({<span className="truncate text-xs text-muted-foreground">{subtitle}</span>)}</span>+ {contact.favorite && (+ <Star aria-hidden className="h-3 w-3 shrink-0 fill-current text-primary/70" />+ )}{rel && (<span className="rounded-full bg-primary/15 px-2 py-0.5 text-[10px] font-medium text-primary">{rel}diff --git a/jarvis/ui/web/frontend/src/views/contacts/ContactsView.test.tsx b/jarvis/ui/web/frontend/src/views/contacts/ContactsView.test.tsxindex 3e01dadd98..f1d5b7a821 100644--- a/jarvis/ui/web/frontend/src/views/contacts/ContactsView.test.tsx+++ b/jarvis/ui/web/frontend/src/views/contacts/ContactsView.test.tsx@@ -52,6 +52,9 @@ const CHRISTOPH_SUMMARY = {name: "Christoph Meyer",aliases: ["Chris"],relationship: "friend",+ favorite: false,+ organization: null,+ tags: ["uni"],primary_email: "[email protected]",primary_phone: "+4915123456789",email_count: 1,@@ -62,6 +65,9 @@ const LAURA_SUMMARY = {name: "Laura",aliases: [],relationship: "partner",+ favorite: true,+ organization: null,+ tags: [],primary_email: null,primary_phone: null,email_count: 0,@@ -72,6 +78,12 @@ const CHRISTOPH_FULL = {name: "Christoph Meyer",aliases: ["Chris"],relationship: "friend",+ favorite: false,+ birthday: null,+ organization: "ACME GmbH",+ role: null,+ urls: [],+ tags: ["uni"],emails: ["[email protected]"],phones: ["+4915123456789"],address: { city: "Berlin" },@@ -186,6 +198,50 @@ describe("ContactsView (master–detail)", () => {expect(await screen.findByText("Laura")).toBeTruthy();});+ it("preselects a contact from the ?contact= deep link", async () => {+ window.history.replaceState({}, "", "/?view=contacts&contact=christoph_meyer");+ installFetchMock({+ "GET /api/contacts/christoph_meyer": () => ({ body: CHRISTOPH_FULL }),+ "GET /api/contacts": () => ({ body: { contacts: [CHRISTOPH_SUMMARY, LAURA_SUMMARY] } }),+ });+ render(<ContactsView />);+ expect(+ await screen.findByRole("link", { name: /christoph@example\.com/i }),+ ).toBeTruthy();+ window.history.replaceState({}, "", "/");+ });++ it("pins favorites in their own group", async () => {+ installFetchMock({+ "GET /api/contacts": () => ({ body: { contacts: [CHRISTOPH_SUMMARY, LAURA_SUMMARY] } }),+ });+ render(<ContactsView />);+ await screen.findByText("Laura");+ expect(screen.getByText("Favorites")).toBeTruthy();+ });++ it("filters by tag chips", async () => {+ installFetchMock({+ "GET /api/contacts": () => ({ body: { contacts: [CHRISTOPH_SUMMARY, LAURA_SUMMARY] } }),+ });+ render(<ContactsView />);+ await screen.findByText("Christoph Meyer");++ fireEvent.click(screen.getByRole("button", { name: /#uni · 1/i }));+ expect(screen.getByText("Christoph Meyer")).toBeTruthy();+ expect(screen.queryByText("Laura")).toBeNull();+ });++ it("offers vCard import and export in the header", async () => {+ installFetchMock({+ "GET /api/contacts": () => ({ body: { contacts: [CHRISTOPH_SUMMARY] } }),+ });+ render(<ContactsView />);+ await screen.findByText("Christoph Meyer");+ expect(screen.getByRole("button", { name: /import vcard/i })).toBeTruthy();+ expect(screen.getByRole("button", { name: /export vcard/i })).toBeTruthy();+ });+it("asks before discarding unsaved dialog changes", async () => {installFetchMock({"GET /api/contacts": () => ({ body: { contacts: [] } }),diff --git a/jarvis/ui/web/frontend/src/views/contacts/ContactsView.tsx b/jarvis/ui/web/frontend/src/views/contacts/ContactsView.tsxindex 34a2d255b5..f3429f8a11 100644--- a/jarvis/ui/web/frontend/src/views/contacts/ContactsView.tsx+++ b/jarvis/ui/web/frontend/src/views/contacts/ContactsView.tsx@@ -1,46 +1,77 @@-import { useCallback, useEffect, useMemo, useState } from "react";-import { Contact as ContactIcon, Loader2, Mic, Plus, Search } from "lucide-react";+import { useCallback, useEffect, useMemo, useRef, useState } from "react";+import {+ Contact as ContactIcon,+ Download,+ Loader2,+ Mic,+ Plus,+ Search,+ Star,+ Upload,+} from "lucide-react";import { ViewHeader } from "@/views/ChatsView";import { useT } from "@/i18n";import { cn } from "@/lib/utils";+import { useEventStore } from "@/store/events";import { ContactRow } from "./ContactRow";import { ContactDetail } from "./ContactDetail";import { ContactEditDialog } from "./ContactEditDialog";import { RELATIONSHIPS, relationshipLabel, type Relationship } from "./constants";import {deleteContact,+ exportVcf,getContact,+ importVcf,listContacts,type Contact,type ContactSummary,} from "./api";/**- * Contacts — a user-curated address book (master–detail). Left: a searchable,- * relationship-filterable list grouped by first letter; right: the selected- * contact's detail with actions. The "Add" button and the edit pencil open the- * same dialog (create vs. PATCH).+ * Contacts — a user-curated address book (master–detail). Left: a searchable+ * list, filterable by relationship or tag, grouped favorites-first then by+ * first letter; right: the selected contact's detail with actions. The "Add"+ * button and the edit pencil open the same dialog (create vs. PATCH); the+ * header also imports/exports the whole book as vCard.** Live: the view listens for the `jarvis:contact-changed` window event (the* bus `ContactChanged` envelope relayed by useWebSocket), so a contact saved* by voice (`contact-upsert`) appears without a manual refresh.*- * Distinct from the read-only "People around you" tab in ProfileView (the- * auto-extracted Curator list) — this section is fully managed by the user and- * is what Jarvis resolves names against (Chunk B).+ * Deep link: `?view=contacts&contact=<slug>` preselects a contact — usable+ * from solo windows and cross-links (e.g. the wiki person page).+ *+ * Narrow containers (solo windows) stack the layout: list first, the detail+ * takes over with a back button once a contact is selected.*/++/** Below this width the master–detail splits into stacked screens. */+const NARROW_PX = 620;++type Filter = { kind: "rel"; value: Relationship } | { kind: "tag"; value: string };++/** Cap the tag chip row — every tag stays reachable through search. */+const MAX_TAG_CHIPS = 12;+export function ContactsView() {const t = useT();+ const pushToast = useEventStore((s) => s.pushToast);const [contacts, setContacts] = useState<ContactSummary[]>([]);const [loading, setLoading] = useState(true);const [error, setError] = useState<string | null>(null);const [query, setQuery] = useState("");- const [relFilter, setRelFilter] = useState<Relationship | null>(null);- const [selectedSlug, setSelectedSlug] = useState<string | null>(null);+ const [filter, setFilter] = useState<Filter | null>(null);+ const [selectedSlug, setSelectedSlug] = useState<string | null>(() =>+ new URLSearchParams(window.location.search).get("contact"),+ );const [selected, setSelected] = useState<Contact | null>(null);const [dialog, setDialog] = useState<"create" | "edit" | null>(null);const [confirmingDelete, setConfirmingDelete] = useState(false);+ const [importing, setImporting] = useState(false);+ const [narrow, setNarrow] = useState(false);+ const rootRef = useRef<HTMLDivElement>(null);+ const fileInputRef = useRef<HTMLInputElement>(null);const loadList = useCallback(async () => {setError(null);@@ -57,6 +88,19 @@ export function ContactsView() {void loadList();}, [loadList]);+ // Stacked layout for narrow containers (solo windows, split screens).+ // Container width, not window width: the view can share the window.+ useEffect(() => {+ const el = rootRef.current;+ if (!el || typeof ResizeObserver === "undefined") return;+ const observer = new ResizeObserver((entries) => {+ const width = entries[0]?.contentRect.width ?? 0;+ setNarrow(width > 0 && width < NARROW_PX);+ });+ observer.observe(el);+ return () => observer.disconnect();+ }, []);+// Load the full record whenever the selection changes.useEffect(() => {if (!selectedSlug) {@@ -99,8 +143,8 @@ export function ContactsView() {return () => window.removeEventListener("jarvis:contact-changed", onChanged);}, [loadList, selectedSlug]);- // Relationship counts over the whole book (not the current search) — the- // chips are a stable map of the book, not of the query.+ // Relationship/tag counts over the whole book (not the current search) —+ // the chips are a stable map of the book, not of the query.const relCounts = useMemo(() => {const counts = new Map<Relationship, number>();for (const c of contacts) {@@ -111,32 +155,57 @@ export function ContactsView() {return counts;}, [contacts]);+ const tagCounts = useMemo(() => {+ const counts = new Map<string, number>();+ for (const c of contacts) {+ for (const tag of c.tags ?? []) {+ counts.set(tag, (counts.get(tag) ?? 0) + 1);+ }+ }+ return [...counts.entries()]+ .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))+ .slice(0, MAX_TAG_CHIPS);+ }, [contacts]);+const filtered = useMemo(() => {const q = query.trim().toLowerCase();return contacts.filter((c) => {- if (relFilter && c.relationship !== relFilter) return false;+ if (filter?.kind === "rel" && c.relationship !== filter.value) return false;+ if (filter?.kind === "tag" && !(c.tags ?? []).includes(filter.value)) return false;if (!q) return true;return (c.name.toLowerCase().includes(q) ||c.aliases.some((a) => a.toLowerCase().includes(q)) ||(c.primary_email ?? "").toLowerCase().includes(q) ||- (c.primary_phone ?? "").toLowerCase().includes(q)+ (c.primary_phone ?? "").toLowerCase().includes(q) ||+ (c.organization ?? "").toLowerCase().includes(q) ||+ (c.tags ?? []).some((tag) => tag.toLowerCase().includes(q)));});- }, [contacts, query, relFilter]);+ }, [contacts, query, filter]);- // Group the (already name-sorted) list by first letter; non-letters → "#".+ // Favorites first as their own group, the rest by first letter ("#" for+ // non-letters). The list arrives name-sorted from the API.const groups = useMemo(() => {- const out: { letter: string; items: ContactSummary[] }[] = [];- for (const c of filtered) {+ const out: { key: string; label: string; starred?: boolean; items: ContactSummary[] }[] = [];+ const favorites = filtered.filter((c) => c.favorite);+ if (favorites.length) {+ out.push({+ key: "favorites",+ label: t("contacts.favorites"),+ starred: true,+ items: favorites,+ });+ }+ for (const c of filtered.filter((c) => !c.favorite)) {const first = c.name.trim()[0] ?? "#";const letter = /\p{L}/u.test(first) ? first.toUpperCase() : "#";const last = out[out.length - 1];- if (last && last.letter === letter) last.items.push(c);- else out.push({ letter, items: [c] });+ if (last && !last.starred && last.key === letter) last.items.push(c);+ else out.push({ key: letter, label: letter, items: [c] });}return out;- }, [filtered]);+ }, [filtered, t]);async function handleSaved(saved: Contact) {setDialog(null);@@ -160,124 +229,235 @@ export function ContactsView() {await loadList();}+ async function handleImportFile(file: File) {+ setImporting(true);+ try {+ const text = await file.text();+ const stats = await importVcf(text);+ pushToast(+ "success",+ t("contacts.importDone")+ .replace("{0}", String(stats.created))+ .replace("{1}", String(stats.updated))+ .replace("{2}", String(stats.skipped)),+ );+ await loadList();+ } catch (e) {+ pushToast(+ "error",+ `${t("contacts.importFailed")} ${e instanceof Error ? e.message : e}`,+ );+ } finally {+ setImporting(false);+ }+ }++ async function handleExport() {+ try {+ const blob = await exportVcf();+ const url = URL.createObjectURL(blob);+ const a = document.createElement("a");+ a.href = url;+ a.download = "contacts.vcf";+ a.click();+ URL.revokeObjectURL(url);+ } catch (e) {+ pushToast("error", e instanceof Error ? e.message : String(e));+ }+ }+const hasContacts = contacts.length > 0;+ const showList = !narrow || !selected;+ const showDetail = !narrow || Boolean(selected);return (- <div className="flex h-full flex-col">+ <div ref={rootRef} className="flex h-full flex-col"><ViewHeadericon={<ContactIcon className="h-4 w-4 text-primary" />}title={t("nav.contacts")}subtitle={t("contacts.subtitle")}right={- <button- type="button"- onClick={() => setDialog("create")}- className="inline-flex items-center gap-1.5 rounded-md border border-primary/40 bg-primary/10 px-3 py-1.5 text-xs font-medium text-primary hover:bg-primary/20"- >- <Plus className="h-3.5 w-3.5" />- {t("contacts.add")}- </button>+ <div className="flex items-center gap-2">+ <input+ ref={fileInputRef}+ type="file"+ accept=".vcf,text/vcard"+ className="hidden"+ onChange={(e) => {+ const file = e.target.files?.[0];+ e.target.value = "";+ if (file) void handleImportFile(file);+ }}+ />+ <button+ type="button"+ onClick={() => fileInputRef.current?.click()}+ disabled={importing}+ aria-label={t("contacts.import")}+ title={t("contacts.import")}+ className="rounded-md border border-border p-1.5 text-muted-foreground hover:border-primary/40 hover:text-foreground disabled:opacity-50"+ >+ {importing ? (+ <Loader2 className="h-3.5 w-3.5 animate-spin" />+ ) : (+ <Upload className="h-3.5 w-3.5" />+ )}+ </button>+ <button+ type="button"+ onClick={() => void handleExport()}+ disabled={!hasContacts}+ aria-label={t("contacts.export")}+ title={t("contacts.export")}+ className="rounded-md border border-border p-1.5 text-muted-foreground hover:border-primary/40 hover:text-foreground disabled:opacity-50"+ >+ <Download className="h-3.5 w-3.5" />+ </button>+ <button+ type="button"+ onClick={() => setDialog("create")}+ className="inline-flex items-center gap-1.5 rounded-md border border-primary/40 bg-primary/10 px-3 py-1.5 text-xs font-medium text-primary hover:bg-primary/20"+ >+ <Plus className="h-3.5 w-3.5" />+ {t("contacts.add")}+ </button>+ </div>}/><div className="flex min-h-0 flex-1">{/* Master list */}- <div className="flex w-[320px] shrink-0 flex-col border-r border-border">- <div className="space-y-2 border-b border-border p-3">- <div className="flex items-center gap-2 rounded-md border border-border bg-background/40 px-2.5 py-1.5">- <Search className="h-3.5 w-3.5 text-muted-foreground" />- <input- value={query}- onChange={(e) => setQuery(e.target.value)}- placeholder={t("contacts.search")}- className="w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground/60"- />- </div>- {hasContacts && (- <div className="flex flex-wrap gap-1">- <FilterChip- active={relFilter === null}- onClick={() => setRelFilter(null)}- label={`${t("contacts.filterAll")} · ${contacts.length}`}+ {showList && (+ <div+ className={cn(+ "flex shrink-0 flex-col",+ narrow ? "w-full" : "w-[320px] border-r border-border",+ )}+ >+ <div className="space-y-2 border-b border-border p-3">+ <div className="flex items-center gap-2 rounded-md border border-border bg-background/40 px-2.5 py-1.5">+ <Search className="h-3.5 w-3.5 text-muted-foreground" />+ <input+ value={query}+ onChange={(e) => setQuery(e.target.value)}+ placeholder={t("contacts.search")}+ className="w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground/60"/>- {RELATIONSHIPS.filter((r) => (relCounts.get(r) ?? 0) > 0).map((r) => (+ </div>+ {hasContacts && (+ <div className="flex flex-wrap gap-1"><FilterChip- key={r}- active={relFilter === r}- onClick={() => setRelFilter(relFilter === r ? null : r)}- label={`${relationshipLabel(t, r)} · ${relCounts.get(r)}`}+ active={filter === null}+ onClick={() => setFilter(null)}+ label={`${t("contacts.filterAll")} · ${contacts.length}`}/>- ))}- </div>- )}- </div>- <nav className="flex-1 overflow-y-auto scrollbar-jarvis p-2">- {loading ? (- <div className="flex items-center justify-center py-10 text-muted-foreground">- <Loader2 className="h-5 w-5 animate-spin" />- </div>- ) : error ? (- <p className="px-3 py-6 text-center text-sm text-destructive">{error}</p>- ) : !hasContacts ? (- <div className="flex flex-col items-center gap-3 px-3 py-8 text-center">- <ContactIcon className="h-8 w-8 text-muted-foreground/40" />- <p className="text-sm text-muted-foreground">{t("contacts.empty")}</p>- <button- type="button"- onClick={() => setDialog("create")}- className="inline-flex items-center gap-1.5 rounded-md border border-primary/40 bg-primary/10 px-3 py-1.5 text-xs font-medium text-primary hover:bg-primary/20"- >- <Plus className="h-3.5 w-3.5" />- {t("contacts.add")}- </button>- <p className="flex items-start gap-1.5 text-xs text-muted-foreground/80">- <Mic className="mt-0.5 h-3.5 w-3.5 shrink-0" />- {t("contacts.voiceHint")}+ {RELATIONSHIPS.filter((r) => (relCounts.get(r) ?? 0) > 0).map((r) => (+ <FilterChip+ key={`rel:${r}`}+ active={filter?.kind === "rel" && filter.value === r}+ onClick={() =>+ setFilter(+ filter?.kind === "rel" && filter.value === r+ ? null+ : { kind: "rel", value: r },+ )+ }+ label={`${relationshipLabel(t, r)} · ${relCounts.get(r)}`}+ />+ ))}+ {tagCounts.map(([tag, count]) => (+ <FilterChip+ key={`tag:${tag}`}+ active={filter?.kind === "tag" && filter.value === tag}+ onClick={() =>+ setFilter(+ filter?.kind === "tag" && filter.value === tag+ ? null+ : { kind: "tag", value: tag },+ )+ }+ label={`#${tag} · ${count}`}+ />+ ))}+ </div>+ )}+ </div>+ <nav className="flex-1 overflow-y-auto scrollbar-jarvis p-2">+ {loading ? (+ <div className="flex items-center justify-center py-10 text-muted-foreground">+ <Loader2 className="h-5 w-5 animate-spin" />+ </div>+ ) : error ? (+ <p className="px-3 py-6 text-center text-sm text-destructive">{error}</p>+ ) : !hasContacts ? (+ <div className="flex flex-col items-center gap-3 px-3 py-8 text-center">+ <ContactIcon className="h-8 w-8 text-muted-foreground/40" />+ <p className="text-sm text-muted-foreground">{t("contacts.empty")}</p>+ <button+ type="button"+ onClick={() => setDialog("create")}+ className="inline-flex items-center gap-1.5 rounded-md border border-primary/40 bg-primary/10 px-3 py-1.5 text-xs font-medium text-primary hover:bg-primary/20"+ >+ <Plus className="h-3.5 w-3.5" />+ {t("contacts.add")}+ </button>+ <p className="flex items-start gap-1.5 text-xs text-muted-foreground/80">+ <Mic className="mt-0.5 h-3.5 w-3.5 shrink-0" />+ {t("contacts.voiceHint")}+ </p>+ </div>+ ) : filtered.length === 0 ? (+ <p className="px-3 py-6 text-center text-sm text-muted-foreground">+ {t("contacts.noMatches")}</p>- </div>- ) : filtered.length === 0 ? (- <p className="px-3 py-6 text-center text-sm text-muted-foreground">- {t("contacts.noMatches")}- </p>- ) : (- <div className="space-y-1">- {groups.map((group) => (- <div key={group.letter}>- <div className="px-3 pb-0.5 pt-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground/70">- {group.letter}+ ) : (+ <div className="space-y-1">+ {groups.map((group) => (+ <div key={group.key}>+ <div className="flex items-center gap-1 px-3 pb-0.5 pt-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground/70">+ {group.starred && <Star className="h-3 w-3 fill-current text-primary/70" />}+ {group.label}+ </div>+ <ul className="space-y-0.5">+ {group.items.map((c) => (+ <ContactRow+ key={c.slug}+ contact={c}+ active={c.slug === selectedSlug}+ onClick={() => setSelectedSlug(c.slug)}+ />+ ))}+ </ul></div>- <ul className="space-y-0.5">- {group.items.map((c) => (- <ContactRow- key={c.slug}- contact={c}- active={c.slug === selectedSlug}- onClick={() => setSelectedSlug(c.slug)}- />- ))}- </ul>- </div>- ))}- </div>- )}- </nav>- </div>+ ))}+ </div>+ )}+ </nav>+ </div>+ )}{/* Detail */}- <div className="min-w-0 flex-1">- {selected ? (- <ContactDetail- contact={selected}- onEdit={() => setDialog("edit")}- onDelete={() => setConfirmingDelete(true)}- />- ) : (- <div className="flex h-full flex-col items-center justify-center gap-3 text-center text-muted-foreground">- <ContactIcon className="h-8 w-8 text-muted-foreground/40" />- <p className="text-sm">{t("contacts.selectHint")}</p>- </div>- )}- </div>+ {showDetail && (+ <div className="min-w-0 flex-1">+ {selected ? (+ <ContactDetail+ contact={selected}+ onEdit={() => setDialog("edit")}+ onDelete={() => setConfirmingDelete(true)}+ onBack={narrow ? () => setSelectedSlug(null) : undefined}+ onChanged={(c) => {+ setSelected(c);+ void loadList();+ }}+ />+ ) : (+ <div className="flex h-full flex-col items-center justify-center gap-3 text-center text-muted-foreground">+ <ContactIcon className="h-8 w-8 text-muted-foreground/40" />+ <p className="text-sm">{t("contacts.selectHint")}</p>+ </div>+ )}+ </div>+ )}</div>{dialog && (diff --git a/jarvis/ui/web/frontend/src/views/contacts/api.ts b/jarvis/ui/web/frontend/src/views/contacts/api.tsindex b29887b37b..918206ecdd 100644--- a/jarvis/ui/web/frontend/src/views/contacts/api.ts+++ b/jarvis/ui/web/frontend/src/views/contacts/api.ts@@ -18,6 +18,9 @@ export interface ContactSummary {name: string;aliases: string[];relationship: Relationship | null;+ favorite: boolean;+ organization: string | null;+ tags: string[];primary_email: string | null;primary_phone: string | null;email_count: number;@@ -30,6 +33,12 @@ export interface Contact {name: string;aliases: string[];relationship: Relationship | null;+ favorite: boolean;+ birthday: string | null;+ organization: string | null;+ role: string | null;+ urls: string[];+ tags: string[];emails: string[];phones: string[];address: ContactAddress;@@ -44,12 +53,27 @@ export interface ContactInput {name: string;aliases: string[];relationship: Relationship | null;+ favorite: boolean;+ birthday: string | null;+ organization: string | null;+ role: string | null;+ urls: string[];+ tags: string[];emails: string[];phones: string[];address: ContactAddress;note: string;}+/** Result of POST /import (merge semantics live server-side). */+export interface ImportStats {+ ok: boolean;+ created: number;+ updated: number;+ skipped: number;+ errors: string[];+}+const BASE = "/api/contacts";async function asError(res: Response): Promise<never> {@@ -103,3 +127,20 @@ export async function deleteContact(slug: string): Promise<void> {const res = await fetch(`${BASE}/${encodeURIComponent(slug)}`, { method: "DELETE" });if (!res.ok) return asError(res);}++export async function importVcf(vcf: string): Promise<ImportStats> {+ const res = await fetch(`${BASE}/import`, {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ vcf }),+ });+ if (!res.ok) return asError(res);+ return (await res.json()) as ImportStats;+}++/** The whole book as a .vcf blob (caller triggers the download). */+export async function exportVcf(): Promise<Blob> {+ const res = await fetch(`${BASE}/export`);+ if (!res.ok) return asError(res);+ return res.blob();+}