Skip to content
Python

Composer attach menu: message/session split, project memory & board bindings (UX-044)

Rohit C Prasad7b7c8f712611
diff --git a/surfaces/gui/e2e/fixtures.ts b/surfaces/gui/e2e/fixtures.ts
index 2331d900..8cf5155f 100644
--- a/surfaces/gui/e2e/fixtures.ts
+++ b/surfaces/gui/e2e/fixtures.ts
@@ -542,6 +542,15 @@ export async function mockApi(page: import("@playwright/test").Page) {
// Installed personas — mutable so enable/surface/delete round-trip through the UI.
const personas: any[] = PERSONAS.personas.map((p) => ({ ...p }));
// Sessions — mutable so archive (PATCH), rename (PATCH), and delete round-trip.
+ // UX-044: mutable binding state for the project-menu mocks.
+ const projectBindings: Record<string, string> = {};
+ const projectNames: Record<string, { name: string; key: string }[]> = {
+ memory: [
+ { name: "openworker", key: "/k/openworker" },
+ { name: "personal-ops", key: "/k/ops" },
+ ],
+ board: [{ name: "aicreator-ops", key: "/k/aico" }],
+ };
const sessions: any[] = [
{ ...PINNED_SESSION },
...EXTRA_SESSIONS.map((s) => ({ ...s })),
@@ -1055,6 +1064,32 @@ export async function mockApi(page: import("@playwright/test").Page) {
}
return json(connections);
}
+ // UX-044 project bindings: stateful per-run so specs can bind/unbind/name.
+ if (/\/v1\/sessions\/[^/]+\/project-menu$/.test(p)) {
+ const kind = new URL(req.url()).searchParams.get("kind") || "memory";
+ return json({
+ kind,
+ bound: projectBindings[kind] ?? null,
+ derived: {
+ kind: "folder",
+ label: "~/fleet/ro4d/demo-universe/notes",
+ full: "/Users/u/fleet/ro4d/demo-universe/notes",
+ key: "/Users/u/fleet/ro4d/demo-universe/notes",
+ },
+ named: projectNames[kind] || [],
+ });
+ }
+ if (/\/v1\/sessions\/[^/]+\/bindings$/.test(p) && m === "PUT") {
+ const b = req.postDataJSON() || {};
+ if (b.name) projectBindings[b.kind] = b.name;
+ else delete projectBindings[b.kind];
+ return json({ ok: true, bindings: projectBindings });
+ }
+ if (/\/v1\/sessions\/[^/]+\/project-name$/.test(p) && m === "POST") {
+ const b = req.postDataJSON() || {};
+ (projectNames[b.kind] ||= []).unshift({ name: b.name, key: "/Users/u/fleet/ro4d/demo-universe/notes" });
+ return json({ ok: true, kind: b.kind, name: b.name });
+ }
if (/\/v1\/sessions\/[^/]+\/roots$/.test(p)) {
if (m === "POST") {
const b = req.postDataJSON();
diff --git a/surfaces/gui/e2e/project-bindings.spec.ts b/surfaces/gui/e2e/project-bindings.spec.ts
new file mode 100644
index 00000000..bce0f8ff
--- /dev/null
+++ b/surfaces/gui/e2e/project-bindings.spec.ts
@@ -0,0 +1,67 @@
+import { test, expect } from "./fixtures";
+
+// UX-044: the composer "+" menu's session section — project-memory/board bindings.
+// Guards: the two labeled sections, the radio submenu (derived label rules, MRU,
+// bound tag), swap-binding round trip, board's "none" row, and naming the current
+// project. Bindings are PROJECT memory only — global memory never appears here.
+
+async function openAttach(page: import("@playwright/test").Page) {
+ await page.goto("/");
+ await page.getByText("Draft the launch note").first().click();
+ await page.getByRole("button", { name: "Attach" }).click();
+}
+
+test("attach menu: two sections, memory submenu with derived + named rows", async ({ page }) => {
+ await openAttach(page);
+
+ await expect(page.getByText("This message")).toBeVisible();
+ await expect(page.getByText("This session")).toBeVisible();
+ await expect(page.getByRole("button", { name: "Photo or image" })).toBeVisible();
+
+ await page.getByRole("button", { name: "Project memory" }).click();
+ const menu = page.getByTestId("project-menu-memory");
+ // Derived row: folder form, trimmed to the last 3 segments, tagged.
+ await expect(menu.getByText("…/ro4d/demo-universe/notes")).toBeVisible();
+ await expect(menu.getByText("this folder")).toBeVisible();
+ // Named rows (MRU), no filter under 6, the two actions.
+ await expect(menu.getByText("openworker")).toBeVisible();
+ await expect(menu.getByText("personal-ops")).toBeVisible();
+ await expect(menu.getByPlaceholder("Filter…")).toHaveCount(0);
+ await expect(menu.getByText("Name current memory…")).toBeVisible();
+ await expect(menu.getByText("View & edit…")).toBeVisible();
+});
+
+test("binding swap round-trips and closes the menu", async ({ page }) => {
+ await openAttach(page);
+ await page.getByRole("button", { name: "Project memory" }).click();
+ await page.getByTestId("project-menu-memory").getByText("openworker").click();
+ // Menu closed on success.
+ await expect(page.getByTestId("project-menu-memory")).toHaveCount(0);
+
+ // Reopen: the binding shows as bound.
+ await page.getByRole("button", { name: "Attach" }).click();
+ await page.getByRole("button", { name: "Project memory" }).click();
+ const menu = page.getByTestId("project-menu-memory");
+ await expect(menu.getByText("bound")).toBeVisible();
+});
+
+test("board submenu has a none row and its own names", async ({ page }) => {
+ await openAttach(page);
+ await page.getByRole("button", { name: "Board", exact: true }).click();
+ const menu = page.getByTestId("project-menu-board");
+ await expect(menu.getByText("none")).toBeVisible();
+ await expect(menu.getByText("aicreator-ops")).toBeVisible();
+ // Board naming exists; memory's View & edit does not.
+ await expect(menu.getByText("Name current board…")).toBeVisible();
+ await expect(menu.getByText("View & edit…")).toHaveCount(0);
+});
+
+test("naming the current project adds it to the named list", async ({ page }) => {
+ await openAttach(page);
+ await page.getByRole("button", { name: "Project memory" }).click();
+ await page.getByTestId("project-menu-memory").getByText("Name current memory…").click();
+ const input = page.getByPlaceholder("Name this memory…");
+ await input.fill("my-notes");
+ await input.press("Enter");
+ await expect(page.getByTestId("project-menu-memory").getByText("my-notes")).toBeVisible();
+});
diff --git a/surfaces/gui/src/App.tsx b/surfaces/gui/src/App.tsx
index 62a35380..2954c044 100644
--- a/surfaces/gui/src/App.tsx
+++ b/surfaces/gui/src/App.tsx
@@ -2044,6 +2044,7 @@ export function App() {
connected={connected}
modelReady={modelReady}
onConnectModel={openModelSetup}
+ onOpenMemory={() => openSettings("memory")}
onConfigureVoiceInput={() => openSettings("voice")}
onSend={send}
onInterrupt={interrupt}
diff --git a/surfaces/gui/src/api.ts b/surfaces/gui/src/api.ts
index 42628c77..9eb65748 100644
--- a/surfaces/gui/src/api.ts
+++ b/surfaces/gui/src/api.ts
@@ -2460,3 +2460,43 @@ export class Session {
this.ws.close();
}
}
+
+// -- project bindings (pass 20 / UX-044) ---------------------------------------
+
+export interface ProjectMenu {
+ kind: "memory" | "board";
+ bound: string | null;
+ derived: { kind: "git" | "folder"; label: string; full: string; key: string } | null;
+ named: { name: string; key: string }[];
+}
+
+export async function getProjectMenu(sessionId: string, kind: "memory" | "board"): Promise<ProjectMenu> {
+ const r = await fetch(`${httpBase()}/v1/sessions/${sessionId}/project-menu?kind=${kind}`);
+ return r.json();
+}
+
+export async function setProjectBinding(
+ sessionId: string,
+ kind: "memory" | "board",
+ name: string | null,
+): Promise<{ ok: boolean; error?: string }> {
+ const r = await fetch(`${httpBase()}/v1/sessions/${sessionId}/bindings`, {
+ method: "PUT",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ kind, name }),
+ });
+ return r.json();
+}
+
+export async function nameCurrentProject(
+ sessionId: string,
+ kind: "memory" | "board",
+ name: string,
+): Promise<{ ok: boolean; error?: string }> {
+ const r = await fetch(`${httpBase()}/v1/sessions/${sessionId}/project-name`, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ kind, name }),
+ });
+ return r.json();
+}
diff --git a/surfaces/gui/src/components/Composer.tsx b/surfaces/gui/src/components/Composer.tsx
index 109ac03d..8a837cd4 100644
--- a/surfaces/gui/src/components/Composer.tsx
+++ b/surfaces/gui/src/components/Composer.tsx
@@ -1,6 +1,7 @@
import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react";
import type { Attachment, SessionUsage } from "../types";
import { isPdfFile, readFile } from "../attach";
+import { ProjectBindMenu } from "./ProjectBindMenu";
import { getSettings, inspectPdf, sessionSkills, type SessionSkillRow } from "../api";
import { formatTokens, totalTokens } from "../usage";
import { Dropdown, type Option } from "./Dropdown";
@@ -111,6 +112,8 @@ interface Props {
// The pending-approval card rendered above the input (plan / work-items / team / tool /
// folder requests). Attended sessions only — Unattended parks the prompt in the Inbox.
approvalSlot?: ReactNode;
+ // UX-044: "View & edit…" in the Project memory submenu routes to the memory panel.
+ onOpenMemory?: () => void;
// Push text + attachments into the composer (e.g. a start-panel task card). The `nonce` makes
// repeated identical prefills re-apply; the user can still edit before sending.
prefill?: { text: string; attachments?: Attachment[]; nonce: number };
@@ -173,6 +176,23 @@ export function Composer(props: Props) {
};
const [dragging, setDragging] = useState(false);
const [attachMenuOpen, setAttachMenuOpen] = useState(false);
+ // UX-044: which "This session" submenu is open (bindings live server-side).
+ const [bindMenu, setBindMenu] = useState<"memory" | "board" | null>(null);
+ // Bindings need a session and a workspace surface (Chat has neither).
+ const sessionRows = Boolean(props.sessionId && props.workspace !== undefined);
+ const bindRow = (icon: "book" | "table", label: string, kind: "memory" | "board") => (
+ <button
+ className={
+ "w-full flex items-center gap-2.5 px-3 py-1.5 text-[13px] text-left hover:bg-paper" +
+ (bindMenu === kind ? " bg-paper" : "")
+ }
+ onClick={() => setBindMenu(bindMenu === kind ? null : kind)}
+ >
+ <Icon name={icon} size={15} className="shrink-0 text-muted" />
+ <span className="flex-1">{label}</span>
+ <Icon name="chevronRight" size={12} className="shrink-0 text-faint" />
+ </button>
+ );
const [dictation, setDictation] = useState<DictationStatus | null>(null);
const [dictationBusy, setDictationBusy] = useState<string | null>(null);
const [dictationError, setDictationError] = useState<string | null>(null);
@@ -583,8 +603,19 @@ export function Composer(props: Props) {
</button>
{attachMenuOpen && (
<>
- <div className="fixed inset-0 z-30" onClick={() => setAttachMenuOpen(false)} />
- <div className="absolute z-40 bottom-full mb-1 left-0 min-w-[180px] rounded-xl border border-line bg-panel shadow-2xl py-1.5">
+ <div
+ className="fixed inset-0 z-30"
+ onClick={() => {
+ setAttachMenuOpen(false);
+ setBindMenu(null);
+ }}
+ />
+ <div className="absolute z-40 bottom-full mb-1 left-0 min-w-[200px] rounded-xl border border-line bg-panel shadow-2xl py-1.5">
+ {sessionRows && (
+ <div className="px-3 pt-1 pb-0.5 text-[10.5px] font-semibold tracking-wide uppercase text-faint">
+ This message
+ </div>
+ )}
{attachItem("image", "Photo or image", () => pickFiles("image/*"))}
{attachItem("file", "PDF", () => pickFiles("application/pdf,.pdf"))}
{attachItem(
@@ -592,7 +623,28 @@ export function Composer(props: Props) {
"Other files",
() => pickFiles("text/*,.md,.csv,.json,.yaml,.yml,.log,.py,.ts,.tsx,.js,.rs,.go,.toml"),
)}
+ {sessionRows && (
+ <>
+ <div className="my-1 border-t border-line" />
+ <div className="px-3 pt-0.5 pb-0.5 text-[10.5px] font-semibold tracking-wide uppercase text-faint">
+ This session
+ </div>
+ {bindRow("book", "Project memory", "memory")}
+ {bindRow("table", "Board", "board")}
+ </>
+ )}
</div>
+ {bindMenu && props.sessionId && (
+ <ProjectBindMenu
+ sessionId={props.sessionId}
+ kind={bindMenu}
+ onClose={() => {
+ setBindMenu(null);
+ setAttachMenuOpen(false);
+ }}
+ onOpenMemory={props.onOpenMemory}
+ />
+ )}
</>
)}
</div>
diff --git a/surfaces/gui/src/components/ProjectBindMenu.test.tsx b/surfaces/gui/src/components/ProjectBindMenu.test.tsx
new file mode 100644
index 00000000..ed43a85a
--- /dev/null
+++ b/surfaces/gui/src/components/ProjectBindMenu.test.tsx
@@ -0,0 +1,63 @@
+// UX-044: label trimming + submenu rendering rules.
+import { describe, expect, it, vi, beforeEach } from "vitest";
+import { render, screen, waitFor } from "@testing-library/react";
+import { ProjectBindMenu, trimPath } from "./ProjectBindMenu";
+
+const menuPayload = {
+ kind: "memory",
+ bound: null,
+ derived: { kind: "folder", label: "~/a/b/c/d/notes", full: "/u/a/b/c/d/notes", key: "/u/a/b/c/d/notes" },
+ named: [
+ { name: "openworker", key: "/k1" },
+ { name: "personal-ops", key: "/k2" },
+ ],
+};
+
+beforeEach(() => {
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async () => ({ json: async () => menuPayload }) as Response),
+ );
+});
+
+describe("trimPath", () => {
+ it("keeps short paths whole", () => {
+ expect(trimPath("~/projects/api")).toBe("~/projects/api");
+ });
+ it("trims long paths to the last 3 segments", () => {
+ expect(trimPath("~/fleet/ro4d/demo-universe/notes")).toBe("…/ro4d/demo-universe/notes");
+ });
+});
+
+describe("ProjectBindMenu", () => {
+ it("renders derived (trimmed) + named rows, no filter under 6", async () => {
+ render(
+ <ProjectBindMenu sessionId="s1" kind="memory" onClose={() => {}} />,
+ );
+ await waitFor(() => expect(screen.getByText("openworker")).toBeTruthy());
+ expect(screen.getByText("…/c/d/notes")).toBeTruthy();
+ expect(screen.getByText("this folder")).toBeTruthy();
+ expect(screen.queryByPlaceholderText("Filter…")).toBeNull();
+ expect(screen.getByText(/Name current memory/)).toBeTruthy();
+ });
+
+ it("shows the filter at 6+ named and filters in place", async () => {
+ const big = {
+ ...menuPayload,
+ named: Array.from({ length: 7 }, (_, i) => ({ name: `mem-${i}`, key: `/k${i}` })),
+ };
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async () => ({ json: async () => big }) as Response),
+ );
+ render(<ProjectBindMenu sessionId="s1" kind="memory" onClose={() => {}} />);
+ await waitFor(() => expect(screen.getByPlaceholderText("Filter…")).toBeTruthy());
+ // MRU cap: only 5 named rows visible unfiltered
+ expect(screen.queryByText("mem-5")).toBeNull();
+ });
+
+ it("board gets a none row; memory does not", async () => {
+ render(<ProjectBindMenu sessionId="s1" kind="board" onClose={() => {}} />);
+ await waitFor(() => expect(screen.getByText("none")).toBeTruthy());
+ });
+});
diff --git a/surfaces/gui/src/components/ProjectBindMenu.tsx b/surfaces/gui/src/components/ProjectBindMenu.tsx
new file mode 100644
index 00000000..dca72265
--- /dev/null
+++ b/surfaces/gui/src/components/ProjectBindMenu.tsx
@@ -0,0 +1,187 @@
+// UX-044: the "This session" submenus of the composer "+" menu — bind a named
+// project memory or board, name the current one, or (memory) open the editor.
+// Radio semantics: picking a row IS the swap. The derived row is pinned first,
+// labeled per the UX-044 rules (git = repo name with a branch glyph; folder =
+// ~-collapsed path trimmed to its last 3 segments). Named rows are MRU-ordered,
+// 5 visible; at 6+ a filter appears and the list is the results (no second
+// surface). Project memory only — global memory never appears here.
+
+import { useEffect, useRef, useState } from "react";
+import { getProjectMenu, nameCurrentProject, setProjectBinding } from "../api";
+import type { ProjectMenu } from "../api";
+import { Icon } from "./Icon";
+
+const MRU_VISIBLE = 5;
+const FILTER_AT = 6;
+
+// "~/fleet/ro4d/demo-universe/notes" → "…/ro4d/demo-universe/notes"
+export function trimPath(label: string): string {
+ const parts = label.split("/").filter(Boolean);
+ if (parts.length <= 3) return label;
+ return "…/" + parts.slice(-3).join("/");
+}
+
+export function ProjectBindMenu(props: {
+ sessionId: string;
+ kind: "memory" | "board";
+ onClose: () => void;
+ onOpenMemory?: () => void;
+}) {
+ const { sessionId, kind } = props;
+ const [menu, setMenu] = useState<ProjectMenu | null>(null);
+ const [filter, setFilter] = useState("");
+ const [naming, setNaming] = useState(false);
+ const [nameDraft, setNameDraft] = useState("");
+ const [error, setError] = useState<string | null>(null);
+ const nameInput = useRef<HTMLInputElement>(null);
+
+ const reload = () => {
+ getProjectMenu(sessionId, kind).then(setMenu).catch(() => setMenu(null));
+ };
+ useEffect(reload, [sessionId, kind]);
+ useEffect(() => {
+ if (naming) nameInput.current?.focus();
+ }, [naming]);
+
+ const bind = async (name: string | null) => {
+ const res = await setProjectBinding(sessionId, kind, name);
+ if (!res.ok) {
+ setError(res.error || "could not bind");
+ return;
+ }
+ props.onClose();
+ };
+
+ const nameCurrent = async () => {
+ const name = nameDraft.trim();
+ if (!name) return;
+ const res = await nameCurrentProject(sessionId, kind, name);
+ if (!res.ok) {
+ setError(res.error || "could not name");
+ return;
+ }
+ setNaming(false);
+ setNameDraft("");
+ reload();
+ };
+
+ const named = menu?.named ?? [];
+ const q = filter.trim().toLowerCase();
+ const shown = q
+ ? named.filter((n) => n.name.toLowerCase().includes(q))
+ : named.slice(0, MRU_VISIBLE);
+ const title = kind === "memory" ? "Project memory" : "Board";
+
+ const radioRow = (
+ active: boolean,
+ label: React.ReactNode,
+ onClick: () => void,
+ key: string,
+ tag?: string,
+ ) => (
+ <button
+ key={key}
+ className="w-full flex items-center gap-2.5 px-3 py-1.5 text-[13px] text-left hover:bg-paper"
+ onClick={onClick}
+ >
+ <span
+ className={
+ "inline-block w-3.5 h-3.5 rounded-full border shrink-0 " +
+ (active ? "border-accent border-[4.5px]" : "border-faint")
+ }
+ />
+ <span className="min-w-0 flex-1 truncate">{label}</span>
+ {tag && <span className="text-[10.5px] text-faint shrink-0">{tag}</span>}
+ </button>
+ );
+
+ return (
+ <div
+ className="absolute z-50 bottom-full mb-1 left-[190px] w-[248px] rounded-xl border border-line bg-panel shadow-2xl py-1.5"
+ data-testid={`project-menu-${kind}`}
+ >
+ <div className="px-3 pt-1 pb-1.5 text-[10.5px] font-semibold tracking-wide uppercase text-faint">
+ {title}
+ </div>
+ {named.length >= FILTER_AT && (
+ <div className="mx-2.5 mb-1.5 flex items-center gap-1.5 rounded-lg border border-line px-2 py-1">
+ <Icon name="search" size={12} className="text-faint shrink-0" />
+ <input
+ className="w-full bg-transparent text-[12.5px] outline-none"
+ placeholder="Filter…"
+ value={filter}
+ onChange={(e) => setFilter(e.target.value)}
+ />
+ </div>
+ )}
+ {kind === "board" &&
+ !q &&
+ radioRow(!menu?.bound && !menu?.derived, "none", () => bind(null), "none")}
+ {menu?.derived &&
+ !q &&
+ radioRow(
+ !menu.bound,
+ menu.derived.kind === "git" ? (
+ <span className="inline-flex items-center gap-1.5">
+ <Icon name="branch" size={12} className="text-faint shrink-0" />
+ <span className="font-mono text-[12px]">{menu.derived.label}</span>
+ </span>
+ ) : (
+ <span className="font-mono text-[12px] text-muted" title={menu.derived.full}>
+ {trimPath(menu.derived.label)}
+ </span>
+ ),
+ () => bind(null),
+ "derived",
+ menu.derived.kind === "git" ? "this repo" : "this folder",
+ )}
+ {shown.map((n) =>
+ radioRow(
+ menu?.bound === n.name,
+ n.name,
+ () => bind(n.name),
+ n.name,
+ menu?.bound === n.name ? "bound" : undefined,
+ ),
+ )}
+ {q && shown.length === 0 && (
+ <div className="px-3 py-1.5 text-[12px] text-faint">no matches</div>
+ )}
+ <div className="my-1 border-t border-line" />
+ {naming ? (
+ <div className="mx-2.5 my-1 flex items-center gap-1.5">
+ <input
+ ref={nameInput}
+ className="w-full rounded-lg border border-line bg-transparent px-2 py-1 text-[12.5px] outline-none"
+ placeholder={`Name this ${kind}…`}
+ value={nameDraft}
+ onChange={(e) => setNameDraft(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") nameCurrent();
+ if (e.key === "Escape") setNaming(false);
+ }}
+ />
+ </div>
+ ) : (
+ <button
+ className="w-full flex items-center gap-2.5 px-3 py-1.5 text-[12.5px] text-left text-muted hover:bg-paper"
+ onClick={() => setNaming(true)}
+ >
+ <Icon name="pencil" size={13} className="shrink-0" /> Name current {kind}…
+ </button>
+ )}
+ {kind === "memory" && props.onOpenMemory && (
+ <button
+ className="w-full flex items-center gap-2.5 px-3 py-1.5 text-[12.5px] text-left text-muted hover:bg-paper"
+ onClick={() => {
+ props.onClose();
+ props.onOpenMemory?.();
+ }}
+ >
+ <Icon name="sliders" size={13} className="shrink-0" /> View &amp; edit…
+ </button>
+ )}
+ {error && <div className="px-3 py-1 text-[11.5px] text-red-500">{error}</div>}
+ </div>
+ );
+}