Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Assist UI: readable memory import on phones, "Use a skill" adds a skill, skill menu in a popover, labelled icon buttons

Claude233f84186172
diff --git a/src/components/assist-view.tsx b/src/components/assist-view.tsx
index 7b0e18a9..b44a1f33 100644
--- a/src/components/assist-view.tsx
+++ b/src/components/assist-view.tsx
@@ -164,7 +164,7 @@ export function AssistView() {
<div className="flex shrink-0 items-center gap-1">
{agentBadge}
{id && (
- <Button variant="ghost" size="sm" onClick={() => go(null)}>
+ <Button variant="ghost" size="sm" onClick={() => go(null)} aria-label="New chat">
<MessageSquarePlus /> <span className="hidden sm:inline">New chat</span>
</Button>
)}
diff --git a/src/components/assist/composer.tsx b/src/components/assist/composer.tsx
index c7a64153..e96cfdd9 100644
--- a/src/components/assist/composer.tsx
+++ b/src/components/assist/composer.tsx
@@ -6,9 +6,10 @@ import { useEffect, useId, useMemo, useRef, useState } from "react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Kbd } from "@/components/ui/kbd";
+import { Popover, PopoverAnchor, PopoverContent } from "@/components/ui/popover";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { uploadFile } from "@/lib/api";
-import { slashQuery, slashSkills, type SkillSummary } from "@/lib/assist";
+import { insertSlash, pickSlash, slashQuery, slashSkills, type SkillSummary } from "@/lib/assist";
import type { MediaKind } from "@/lib/catalog/types";
import { cn } from "@/lib/utils";
import { SkillIcon } from "./skill-icon";
@@ -50,6 +51,7 @@ export function AssistComposer({
const [menuClosed, setMenuClosed] = useState(false);
const input = useRef<HTMLInputElement>(null);
const area = useRef<HTMLTextAreaElement>(null);
+ const box = useRef<HTMLDivElement>(null);
const listId = useId();
const uploading = files.some((f) => !f.url);
const ready = text.trim().length > 0 && !uploading && !sending && !disabled;
@@ -110,20 +112,20 @@ export function AssistComposer({
if (f.preview.startsWith("blob:")) release(f.preview);
};
- const pick = (s: SkillSummary) => {
- if (!query) return;
- const before = text.slice(0, query.start);
- const after = text.slice(caret).replace(/^\S*/, "").replace(/^\s*/, "");
- const next = `${before}/${s.name} ${after}`;
+ const place = (next: string, pos: number) => {
setText(next);
- const pos = before.length + s.name.length + 2;
setCaret(pos);
- setMenuIndex(0);
requestAnimationFrame(() => {
area.current?.focus();
area.current?.setSelectionRange(pos, pos);
});
};
+ const pick = (s: SkillSummary) => {
+ if (!query) return;
+ const r = pickSlash(text, caret, query.start, s.name);
+ setMenuIndex(0);
+ place(r.text, r.caret);
+ };
const unuse = (name: string) => {
setText((t) => t.replace(new RegExp(`(^|\\s)/${name}(?=\\s|$)\\s*`), "$1").trimStart());
@@ -146,6 +148,7 @@ export function AssistComposer({
return (
<div
+ ref={box}
className="relative rounded-[20px] border bg-background p-2.5 shadow-soft transition-[border-color,box-shadow] focus-within:border-primary focus-within:ring-4 focus-within:ring-brand-faint sm:rounded-composer"
onDragOver={(e) => e.preventDefault()}
onDrop={(e) => {
@@ -153,33 +156,48 @@ export function AssistComposer({
add(e.dataTransfer.files);
}}
>
- {menuOpen && (
- <div className="absolute inset-x-2 bottom-full z-30 mb-2 max-h-[min(18rem,42svh)] overflow-y-auto rounded-2xl border bg-popover p-1 shadow-strong" role="listbox" id={listId} aria-label="Skills">
- <p className="px-2.5 pt-1.5 pb-1 text-[11px] font-medium text-subtle-foreground">Skills</p>
- {matches.map((s, i) => (
- <button
- key={s.name}
- type="button"
- role="option"
- id={`${listId}-${s.name}`}
- aria-selected={i === active}
- onMouseDown={(e) => e.preventDefault()}
- onMouseEnter={() => setMenuIndex(i)}
- onClick={() => pick(s)}
- ref={i === active ? (el) => el?.scrollIntoView({ block: "nearest" }) : undefined}
- className={cn("flex w-full items-center gap-2.5 rounded-xl px-2.5 py-1.5 text-left", i === active && "bg-accent")}
- >
- <SkillIcon name={s.name} icon={s.icon} size="sm" />
- <span className="min-w-0 flex-1">
- <span className="block truncate text-[13px] font-medium">
- {s.title} <span className="font-mono text-[11px] font-normal text-muted-foreground">/{s.name}</span>
+ {/* The skill menu: a popover anchored to the composer, so it flips below when there's no room
+ above and is never clipped by the scrolling page or hidden under the header. Focus stays in
+ the message box, which drives the list (↑↓, Enter, Esc). */}
+ <Popover open={menuOpen} onOpenChange={(o) => !o && setMenuClosed(true)}>
+ <PopoverAnchor virtualRef={box} />
+ <PopoverContent
+ side="top"
+ align="start"
+ sideOffset={8}
+ collisionPadding={8}
+ onOpenAutoFocus={(e) => e.preventDefault()}
+ onCloseAutoFocus={(e) => e.preventDefault()}
+ onInteractOutside={(e) => box.current?.contains(e.target as Node) && e.preventDefault()}
+ className="max-h-[min(18rem,var(--radix-popover-content-available-height))] w-[min(var(--radix-popover-trigger-width),40rem)] gap-0 overflow-y-auto rounded-2xl border bg-popover p-1 shadow-strong ring-0"
+ >
+ <div role="listbox" id={listId} aria-label="Skills">
+ <p className="px-2.5 pt-1.5 pb-1 text-[11px] font-medium text-subtle-foreground">Skills</p>
+ {matches.map((s, i) => (
+ <button
+ key={s.name}
+ type="button"
+ role="option"
+ id={`${listId}-${s.name}`}
+ aria-selected={i === active}
+ onMouseDown={(e) => e.preventDefault()}
+ onMouseEnter={() => setMenuIndex(i)}
+ onClick={() => pick(s)}
+ ref={i === active ? (el) => el?.scrollIntoView({ block: "nearest" }) : undefined}
+ className={cn("flex w-full items-center gap-2.5 rounded-xl px-2.5 py-1.5 text-left", i === active && "bg-accent")}
+ >
+ <SkillIcon name={s.name} icon={s.icon} size="sm" />
+ <span className="min-w-0 flex-1">
+ <span className="block truncate text-[13px] font-medium">
+ {s.title} <span className="font-mono text-[11px] font-normal text-muted-foreground">/{s.name}</span>
+ </span>
+ <span className="block truncate text-[12px] text-muted-foreground">{s.description}</span>
</span>
- <span className="block truncate text-[12px] text-muted-foreground">{s.description}</span>
- </span>
- </button>
- ))}
- </div>
- )}
+ </button>
+ ))}
+ </div>
+ </PopoverContent>
+ </Popover>
{files.length > 0 && (
<div className="mb-2 flex flex-wrap gap-2 px-1 pt-1">
{files.map((f) => (
@@ -276,14 +294,10 @@ export function AssistComposer({
<button
type="button"
onClick={() => {
- const next = text.startsWith("/") ? text : `/${text ? ` ${text}` : ""}`;
- setText(next);
- setCaret(1);
+ // A new "/" after the skills already chosen, so another one is added (not swapped).
+ const r = insertSlash(text, [...known.keys()]);
setMenuClosed(false);
- requestAnimationFrame(() => {
- area.current?.focus();
- area.current?.setSelectionRange(1, 1);
- });
+ place(r.text, r.caret);
}}
className="hidden size-9 shrink-0 place-items-center rounded-full text-muted-foreground hover:bg-accent hover:text-foreground sm:grid"
aria-label="Use a skill"
diff --git a/src/components/assist/memory-view.tsx b/src/components/assist/memory-view.tsx
index 37a49da3..99e1b2ad 100644
--- a/src/components/assist/memory-view.tsx
+++ b/src/components/assist/memory-view.tsx
@@ -1,6 +1,6 @@
"use client";
-import { Brain, Check, ClipboardCopy, Download, Loader2, Pencil, Plus, Trash2 } from "lucide-react";
+import { Brain, Check, ClipboardCopy, Import, Loader2, Pencil, Plus, Trash2 } from "lucide-react";
import { useId, useMemo, useState } from "react";
import { toast } from "sonner";
import {
@@ -26,6 +26,7 @@ import { copyText } from "@/lib/clipboard";
import { guessCategory, MEMORY_CATEGORIES, MEMORY_HINTS, MEMORY_MAX_CHARS, parseMemoryImport, type AssistMemory, type AssistProject, type MemoryCategory, type MemoryScope } from "@/lib/assist";
import { timeAgo } from "@/lib/format";
import { cn } from "@/lib/utils";
+import { radioKeys, radioTab } from "@/components/studio/radio-keys";
import { useMemories, useMemoryActions, useProjects } from "./hooks";
import { ProjectDot, RailButton } from "./shell";
@@ -64,8 +65,8 @@ export function MemoryView({ projectId }: { projectId?: string } = {}) {
<RailButton />
<h1 className="font-heading text-[22px] leading-none">Memory</h1>
<div className="ml-auto flex items-center gap-1.5">
- <Button variant="outline" size="sm" onClick={() => setImporting(true)}>
- <Download /> <span className="hidden sm:inline">Import</span>
+ <Button variant="outline" size="sm" onClick={() => setImporting(true)} aria-label="Import memories">
+ <Import /> <span className="hidden sm:inline">Import</span>
</Button>
<Button size="sm" onClick={() => setAdding(true)}>
<Plus /> <span className="hidden sm:inline">Add a memory</span>
@@ -81,7 +82,7 @@ export function MemoryView({ projectId }: { projectId?: string } = {}) {
<p className="text-[13px] text-muted-foreground">Only this project&apos;s chats see these.</p>
<div className="flex gap-1.5">
<Button variant="outline" size="sm" onClick={() => setImporting(true)}>
- <Download /> Import
+ <Import /> Import
</Button>
<Button size="sm" onClick={() => setAdding(true)}>
<Plus /> Add
@@ -106,15 +107,18 @@ export function MemoryView({ projectId }: { projectId?: string } = {}) {
</SelectContent>
</Select>
)}
- <div className="-mx-1 flex min-w-0 flex-1 gap-1 overflow-x-auto px-1 scrollbar-none" role="radiogroup" aria-label="Category">
+ <div className="-mx-1 flex min-w-0 flex-1 gap-1 overflow-x-auto px-1 scrollbar-none" role="radiogroup" aria-label="Category" onKeyDown={radioKeys}>
{(["all", ...MEMORY_CATEGORIES] as const).map((c) => {
const n = c === "all" ? (memories.data?.length ?? 0) : (counts.get(c) ?? 0);
- if (c !== "all" && !n) return null;
+ // Empty categories are hidden, except the picked one (it stays the group's Tab stop).
+ if (c !== "all" && !n && category !== c) return null;
return (
<button
key={c}
+ type="button"
role="radio"
aria-checked={category === c}
+ tabIndex={radioTab(category === c)}
onClick={() => setCategory(c)}
className={cn(
"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full px-3 text-[13px] font-medium transition-colors",
@@ -151,7 +155,7 @@ export function MemoryView({ projectId }: { projectId?: string } = {}) {
</EmptyHeader>
<EmptyContent className="flex-row justify-center">
<Button variant="outline" onClick={() => setImporting(true)}>
- <Download /> Import
+ <Import /> Import
</Button>
<Button onClick={() => setAdding(true)}>
<Plus /> Add a memory
@@ -246,16 +250,20 @@ function MemoryRow({ m, project }: { m: AssistMemory; project?: AssistProject })
);
}
-function CategorySelect({ value, onChange, id }: { value: MemoryCategory; onChange: (c: MemoryCategory) => void; id?: string }) {
+/** A memory's category: the trigger shows just the name; the list adds what each one is for. */
+function CategorySelect({ value, onChange, id, className, label = "Category" }: { value: MemoryCategory; onChange: (c: MemoryCategory) => void; id?: string; className?: string; label?: string }) {
return (
<Select value={value} onValueChange={(v) => onChange(v as MemoryCategory)}>
- <SelectTrigger id={id} size="sm" className="rounded-full" aria-label="Category">
- <SelectValue />
+ <SelectTrigger id={id} size="sm" className={cn("max-w-full rounded-full", className)} aria-label={label}>
+ <SelectValue>{value}</SelectValue>
</SelectTrigger>
- <SelectContent>
+ <SelectContent className="max-w-[min(22rem,calc(100vw-2rem))]">
{MEMORY_CATEGORIES.map((c) => (
- <SelectItem key={c} value={c}>
- {c} <span className="text-[11px] text-muted-foreground">— {MEMORY_HINTS[c]}</span>
+ <SelectItem key={c} value={c} className="py-1.5">
+ <span className="flex min-w-0 flex-col items-start gap-0">
+ <span>{c}</span>
+ <span className="text-[11px] leading-snug whitespace-normal text-muted-foreground">{MEMORY_HINTS[c]}</span>
+ </span>
</SelectItem>
))}
</SelectContent>
@@ -420,8 +428,10 @@ function ImportForm({ place, projects, onDone }: { place: Place; projects: Assis
{items.map((it, i) => (
<li key={i} className={cn("flex items-start gap-3 px-3 py-2.5", !it.keep && "opacity-50")}>
<Checkbox className="mt-0.5" checked={it.keep} onCheckedChange={(v) => setItems((xs) => xs!.map((x, j) => (j === i ? { ...x, keep: !!v } : x)))} aria-label={`Import “${it.text}”`} />
- <p className="min-w-0 flex-1 text-[13px] break-words">{it.text}</p>
- <CategorySelect value={it.category} onChange={(c) => setItems((xs) => xs!.map((x, j) => (j === i ? { ...x, category: c } : x)))} />
+ <div className="flex min-w-0 flex-1 flex-col items-start gap-1.5 sm:flex-row sm:gap-3">
+ <p className="w-full min-w-0 text-[13px] break-words sm:w-auto sm:flex-1">{it.text}</p>
+ <CategorySelect className="shrink-0" label={`Category for “${it.text.slice(0, 40)}”`} value={it.category} onChange={(c) => setItems((xs) => xs!.map((x, j) => (j === i ? { ...x, category: c } : x)))} />
+ </div>
</li>
))}
</ul>
diff --git a/src/components/assist/project-view.tsx b/src/components/assist/project-view.tsx
index 068c2c5a..3f7b765d 100644
--- a/src/components/assist/project-view.tsx
+++ b/src/components/assist/project-view.tsx
@@ -92,7 +92,7 @@ function Project({ p }: { p: AssistProject }) {
<ProjectDot project={p} className="ml-1" />
<h1 className="min-w-0 truncate font-heading text-[22px] leading-none">{p.name}</h1>
<div className="ml-auto flex items-center gap-1">
- <Button variant="ghost" size="sm" onClick={() => setSettings(true)}>
+ <Button variant="ghost" size="sm" onClick={() => setSettings(true)} aria-label="Project settings">
<Settings2 /> <span className="hidden sm:inline">Settings</span>
</Button>
<DropdownMenu>
diff --git a/src/components/assist/skills-view.tsx b/src/components/assist/skills-view.tsx
index bef9ebbd..04d0564a 100644
--- a/src/components/assist/skills-view.tsx
+++ b/src/components/assist/skills-view.tsx
@@ -102,7 +102,7 @@ function Skills() {
if (f) void upload(f);
}}
/>
- <Button variant="outline" size="sm" onClick={() => file.current?.click()} disabled={uploading}>
+ <Button variant="outline" size="sm" onClick={() => file.current?.click()} disabled={uploading} aria-label="Upload a skill">
{uploading ? <Loader2 className="animate-spin" /> : <Upload />} <span className="hidden sm:inline">Upload</span>
</Button>
<Button size="sm" onClick={() => setEditing("new")}>
diff --git a/src/lib/assist.ts b/src/lib/assist.ts
index a8db42f0..6d242dfd 100644
--- a/src/lib/assist.ts
+++ b/src/lib/assist.ts
@@ -334,6 +334,39 @@ export function slashSkills(text: string, known: (name: string) => boolean): { s
return { skills, text: rest };
}
+/** Where the skill tokens at the start of a message end (after the space that follows them). */
+function skillTokensEnd(text: string, known: (name: string) => boolean): number {
+ let pos = /^\s*/.exec(text)![0].length;
+ for (;;) {
+ const m = /^\/([a-z0-9]+(?:-[a-z0-9]+)*)(?=\s|$)/.exec(text.slice(pos));
+ if (!m || !known(m[1])) return pos;
+ pos += m[0].length;
+ pos += /^\s*/.exec(text.slice(pos))![0].length;
+ }
+}
+
+/**
+ * The composer's "Use a skill" button: open a `/` after the skills already chosen (never inside
+ * one), keeping the rest of the message. A lone `/`, or the start of a skill's name, already there
+ * just gets the caret.
+ */
+export function insertSlash(text: string, names: readonly string[]): { text: string; caret: number } {
+ const pos = skillTokensEnd(text, (n) => names.includes(n));
+ const partial = /^\/([a-z0-9-]*)(?=\s|$)/.exec(text.slice(pos));
+ if (partial && names.some((n) => n.startsWith(partial[1]))) return { text, caret: pos + partial[0].length };
+ const head = text.slice(0, pos);
+ const gap = head && !/\s$/.test(head) ? " " : "";
+ const rest = text.slice(pos);
+ return { text: `${head}${gap}/${rest ? ` ${rest}` : ""}`, caret: pos + gap.length + 1 };
+}
+
+/** Put a picked skill in place of the `/partial` that starts at `start` (the caret is in or after it). */
+export function pickSlash(text: string, caret: number, start: number, name: string): { text: string; caret: number } {
+ const before = text.slice(0, start);
+ const after = text.slice(caret).replace(/^\S*/, "").replace(/^\s*/, "");
+ return { text: `${before}/${name} ${after}`, caret: before.length + name.length + 2 };
+}
+
/** The `/partial` being typed at the caret, for the composer's skill menu (null when none). */
export function slashQuery(text: string, caret: number): { start: number; query: string } | null {
const before = text.slice(0, caret);
diff --git a/tests/assist-skills.test.ts b/tests/assist-skills.test.ts
index a25eacae..bd2eaf6a 100644
--- a/tests/assist-skills.test.ts
+++ b/tests/assist-skills.test.ts
@@ -8,9 +8,11 @@ import {
contextUpdate,
factMap,
guessCategory,
+ insertSlash,
parseFrontmatter,
parseMemoryImport,
parseSkillMd,
+ pickSlash,
renderContext,
skillSlug,
slashQuery,
@@ -138,6 +140,29 @@ describe("/name in the composer", () => {
expect(slashSkills("make /product-photoshoot", known)).toEqual({ skills: [], text: "make /product-photoshoot" });
expect(slashSkills("/product-photoshoot", known)).toEqual({ skills: ["product-photoshoot"], text: "" });
});
+ it("“Use a skill” adds a / after the chosen skills, and picking fills it in without touching them", () => {
+ const k = ["katana", "narration", "product-photoshoot"];
+ // The reviewer's case: /katana stays, narration is added.
+ const a = insertSlash("/katana make it pop", k);
+ expect(a).toEqual({ text: "/katana / make it pop", caret: 9 });
+ const q = slashQuery(a.text, a.caret)!;
+ expect(q).toEqual({ start: 8, query: "" });
+ const b = pickSlash(a.text, a.caret, q.start, "narration");
+ expect(b).toEqual({ text: "/katana /narration make it pop", caret: 19 });
+ expect(slashSkills(b.text, (n) => k.includes(n))).toEqual({ skills: ["katana", "narration"], text: "make it pop" });
+ // Empty box, plain text, a token without a trailing space, two tokens, a / already waiting.
+ expect(insertSlash("", k)).toEqual({ text: "/", caret: 1 });
+ expect(insertSlash("make it pop", k)).toEqual({ text: "/ make it pop", caret: 1 });
+ expect(insertSlash("/katana", k)).toEqual({ text: "/katana /", caret: 9 });
+ expect(insertSlash("/katana /narration hi", k)).toEqual({ text: "/katana /narration / hi", caret: 20 });
+ expect(insertSlash("/katana /nar hi", k)).toEqual({ text: "/katana /nar hi", caret: 12 });
+ expect(insertSlash("/katana / hi", k)).toEqual({ text: "/katana / hi", caret: 9 });
+ // An unknown /word is text, not a skill: the new / goes before it.
+ expect(insertSlash("/hello there", k)).toEqual({ text: "/ /hello there", caret: 1 });
+ // Picking while typing a partial replaces only that partial.
+ expect(pickSlash("/product-photoshoot /nar a bottle", 24, 20, "narration")).toEqual({ text: "/product-photoshoot /narration a bottle", caret: 31 });
+ });
+
it("finds the /partial at the caret only at the start of the message", () => {
expect(slashQuery("/pro", 4)).toEqual({ start: 0, query: "pro" });
expect(slashQuery("/product-photoshoot /thu", 24)).toEqual({ start: 20, query: "thu" });
diff --git a/tests/e2e/_routes.mjs b/tests/e2e/_routes.mjs
index cad760b2..9f6d03d5 100644
--- a/tests/e2e/_routes.mjs
+++ b/tests/e2e/_routes.mjs
@@ -52,6 +52,7 @@ export function dynamicSamples(root, ids = {}) {
const hubs = hubModePaths(root);
const { patterns } = studioRoutes(root);
const urls = [];
+ /** @type {Record<string, string[]>} */
const byPattern = {};
const generated = [];
for (const p of patterns) {