Python
Choose a folder on a machine: type a path, check it, use it
Rohit C Prasadc1959f027fbe
diff --git a/surfaces/gui/src/App.tsx b/surfaces/gui/src/App.tsxindex a162477c..11053430 100644--- a/surfaces/gui/src/App.tsx+++ b/surfaces/gui/src/App.tsx@@ -2334,16 +2334,16 @@ export function App() {<SessionSetupRowpersonas={personas}agent={agent}- showFolder={!machine && !cloudMode}+ showFolder={!cloudMode}folderName={workspace && !tempWorkspace ? baseName(workspace) : null}machines={machines}machine={machine}cloud={cloudMode}onPickMachine={(id) => {setMachine(id);- // A remote draft never carries a LOCAL folder — the box provisions- // its own scratch (remote folder browsing is a follow-up).- if (id) {+ // A folder picked here belongs to one place: switching machines (or back to+ // this computer) drops it. The folder chip then takes a path on the new one.+ if (id !== machine) {setWorkspace(null);setBranch(null);setShowGate(false);diff --git a/surfaces/gui/src/components/MachineFolderDialog.test.tsx b/surfaces/gui/src/components/MachineFolderDialog.test.tsxnew file mode 100644index 00000000..6f5f44c0--- /dev/null+++ b/surfaces/gui/src/components/MachineFolderDialog.test.tsx@@ -0,0 +1,59 @@+// A folder on a machine: type a path, Check asks the machine, Use only after a pass.+import { afterEach, describe, expect, it, vi } from "vitest";+import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";+import { MachineFolderDialog } from "./MachineFolderDialog";+import type { Machine } from "../api";++const MACHINE = { id: "m1", name: "linux-exe" } as unknown as Machine;++function stubFetch(answers: Record<string, unknown>) {+ const calls: string[] = [];+ vi.stubGlobal(+ "fetch",+ vi.fn(async (url: string, init?: RequestInit) => {+ calls.push(url);+ if (url.includes("/workspaces/recent") || url.includes("recent")) {+ return { ok: true, json: async () => ({ workspaces: [{ path: "/home/ubuntu/code/billing", name: "billing", exists: true }] }) } as Response;+ }+ const body = JSON.parse(String(init?.body || "{}"));+ const a = answers[body.path] ?? { ok: false, error: `No folder at ${body.path} on linux-exe.` };+ return { ok: true, json: async () => a } as Response;+ }),+ );+ return calls;+}++afterEach(() => {+ cleanup();+ vi.unstubAllGlobals();+});++describe("MachineFolderDialog", () => {+ it("checks a typed path on the machine and enables Use only after a pass", async () => {+ stubFetch({ "/home/ubuntu/code/invoices": { ok: true, path: "/home/ubuntu/code/invoices", git_branch: "main" } });+ const onPick = vi.fn();+ render(<MachineFolderDialog coworkerName="Coworker" machine={MACHINE} onPick={onPick} onCancel={() => {}} />);+ const use = screen.getByTestId("machine-folder-use") as HTMLButtonElement;+ expect(use.disabled).toBe(true);+ fireEvent.change(screen.getByTestId("machine-folder-input"), { target: { value: "/home/ubuntu/code/invoice" } });+ fireEvent.click(screen.getByTestId("machine-folder-check"));+ await waitFor(() => expect(screen.getByTestId("machine-folder-status").textContent).toContain("No folder at /home/ubuntu/code/invoice"));+ expect(use.disabled).toBe(true);+ fireEvent.change(screen.getByTestId("machine-folder-input"), { target: { value: "/home/ubuntu/code/invoices" } });+ expect(screen.getByTestId("machine-folder-status").textContent).toBe(""); // a new path needs a new check+ fireEvent.submit(screen.getByTestId("machine-folder-input").closest("form")!);+ await waitFor(() => expect(screen.getByTestId("machine-folder-status").textContent).toContain("git branch main"));+ expect(use.disabled).toBe(false);+ fireEvent.click(use);+ expect(onPick).toHaveBeenCalledWith("/home/ubuntu/code/invoices", "main");+ });++ it("a recent folder on the machine is checked and used in one click", async () => {+ stubFetch({ "/home/ubuntu/code/billing": { ok: true, path: "/home/ubuntu/code/billing", git_branch: null } });+ const onPick = vi.fn();+ render(<MachineFolderDialog coworkerName="Coworker" machine={MACHINE} onPick={onPick} onCancel={() => {}} />);+ const recent = await screen.findByTestId("machine-folder-recent");+ fireEvent.click(recent);+ await waitFor(() => expect(onPick).toHaveBeenCalledWith("/home/ubuntu/code/billing", null));+ });+});diff --git a/surfaces/gui/src/components/MachineFolderDialog.tsx b/surfaces/gui/src/components/MachineFolderDialog.tsxnew file mode 100644index 00000000..419a3239--- /dev/null+++ b/surfaces/gui/src/components/MachineFolderDialog.tsx@@ -0,0 +1,153 @@+// A folder on a machine, for the setup row's "Choose folder" when the session runs on one+// (UX ruling 2026-09-29, mock ux-improvements/mocks/coworker-picker-groups.html): the Mac's+// file picker cannot see the machine, so the user types a path, Check asks the machine+// whether it is a folder (and its git branch), and "Use this folder" is enabled only after a+// check passes. Recent folders on that machine are one click. No browsing.+import { useEffect, useState } from "react";+import { useTranslation } from "react-i18next";+import { getRecentWorkspaces, openWorkspace, type Machine, type RecentWorkspace } from "../api";+import { Icon } from "./Icon";++interface Props {+ coworkerName: string;+ machine: Machine;+ onPick: (path: string, branch?: string | null) => void;+ onCancel: () => void;+}++type Check =+ | { state: "idle" }+ | { state: "checking" }+ | { state: "ok"; path: string; branch: string | null }+ | { state: "bad"; path: string; error: string };++function baseName(p: string): string {+ const parts = p.replace(/[\\/]+$/, "").split(/[\\/]/);+ return parts[parts.length - 1] || p;+}++export function MachineFolderDialog({ coworkerName, machine, onPick, onCancel }: Props) {+ const { t } = useTranslation();+ const [recents, setRecents] = useState<RecentWorkspace[]>([]);+ const [typed, setTyped] = useState("");+ const [check, setCheck] = useState<Check>({ state: "idle" });++ useEffect(() => {+ getRecentWorkspaces(machine.id).then(setRecents).catch(() => {});+ }, [machine.id]);++ useEffect(() => {+ const onKey = (e: KeyboardEvent) => {+ if (e.key === "Escape") onCancel();+ };+ window.addEventListener("keydown", onKey);+ return () => window.removeEventListener("keydown", onKey);+ }, [onCancel]);++ // The machine answers: openWorkspace with its id validates the path there.+ const runCheck = async (path: string): Promise<Check> => {+ setCheck({ state: "checking" });+ const res = await openWorkspace(path, false, machine.id);+ const next: Check = res.ok+ ? { state: "ok", path: res.path, branch: res.git_branch ?? null }+ : { state: "bad", path, error: res.error || t("onmachine.folder.not_found", { path, machine: machine.name }) };+ setCheck(next);+ return next;+ };++ const useChecked = () => {+ if (check.state === "ok") onPick(check.path, check.branch);+ };++ // A recent folder is checked and used in one step.+ const pickRecent = async (path: string) => {+ const next = await runCheck(path);+ if (next.state === "ok") onPick(next.path, next.branch);+ };++ const fieldTone =+ check.state === "ok" ? " border-ok" : check.state === "bad" ? " border-danger" : " border-line focus:border-accent";++ return (+ <div className="gate-overlay" onClick={onCancel}>+ <div+ className="w-[410px] bg-panel border border-line rounded-xl2 shadow-2xl p-[18px]"+ data-testid="machine-folder-dialog"+ onClick={(e) => e.stopPropagation()}+ >+ <h3 className="text-body font-semibold text-ink mb-1">+ {t("onmachine.folder.draft_title", { name: coworkerName, machine: machine.name })}+ </h3>+ <p className="text-ui text-muted mb-3">{t("onmachine.folder.draft_sub", { machine: machine.name })}</p>+ {recents+ .filter((w) => w.exists)+ .slice(0, 4)+ .map((w) => (+ <button+ key={w.path}+ className="w-full flex items-center gap-2.5 px-2.5 py-2 mb-1.5 rounded-lg border border-line hover:border-lineStrong hover:bg-paper text-left"+ onClick={() => void pickRecent(w.path)}+ title={w.path}+ data-testid="machine-folder-recent"+ >+ <Icon name="folder" size={13} className="shrink-0 text-muted" />+ <span className="text-ui text-ink truncate">{baseName(w.path)}</span>+ <span className="ml-auto text-meta text-faint truncate max-w-[45%]">{w.path}</span>+ </button>+ ))}+ <form+ className="flex gap-2 mt-1"+ onSubmit={(e) => {+ e.preventDefault();+ if (typed.trim()) void runCheck(typed.trim());+ }}+ >+ <input+ className={"flex-1 min-w-0 px-2.5 py-2 rounded-lg border bg-paper font-mono text-meta text-ink outline-none" + fieldTone}+ placeholder={t("onmachine.folder.path_placeholder", { machine: machine.name })}+ value={typed}+ onChange={(e) => {+ setTyped(e.target.value);+ if (check.state !== "idle") setCheck({ state: "idle" }); // a new path needs a new check+ }}+ data-testid="machine-folder-input"+ autoFocus+ />+ <button+ type="submit"+ className="text-ui px-3 py-2 rounded-lg border border-lineStrong text-ink hover:bg-paper disabled:opacity-40"+ disabled={!typed.trim() || check.state === "checking"}+ data-testid="machine-folder-check"+ >+ {check.state === "checking" ? t("onmachine.folder.checking") : t("onmachine.folder.check")}+ </button>+ </form>+ <p+ className={"text-meta mt-2 min-h-[18px] " + (check.state === "ok" ? "text-ok" : check.state === "bad" ? "text-danger" : "text-muted")}+ data-testid="machine-folder-status"+ >+ {check.state === "ok"+ ? check.branch+ ? t("onmachine.folder.found_branch", { machine: machine.name, branch: check.branch })+ : t("onmachine.folder.found", { machine: machine.name })+ : check.state === "bad"+ ? check.error+ : ""}+ </p>+ <div className="flex gap-2 mt-3 justify-end">+ <button className="text-ui px-3 py-2 rounded-lg border border-lineStrong text-ink hover:bg-paper" onClick={onCancel}>+ {t("folder_gate.cancel")}+ </button>+ <button+ className="text-ui px-3 py-2 rounded-lg bg-accent text-white hover:opacity-90 disabled:opacity-40"+ disabled={check.state !== "ok"}+ onClick={useChecked}+ data-testid="machine-folder-use"+ >+ {t("onmachine.folder.use")}+ </button>+ </div>+ </div>+ </div>+ );+}diff --git a/surfaces/gui/src/components/SessionSetupRow.tsx b/surfaces/gui/src/components/SessionSetupRow.tsxindex a082709b..c0842ac8 100644--- a/surfaces/gui/src/components/SessionSetupRow.tsx+++ b/surfaces/gui/src/components/SessionSetupRow.tsx@@ -11,6 +11,7 @@ import { chooseFolder } from "../tauri";import { fullPersonaName } from "../personaScope";import { baseName } from "../paths";import { Icon } from "./Icon";+import { MachineFolderDialog } from "./MachineFolderDialog";// UX-029: the session-setup row — per-SESSION choices (coworker + folder) in their own// quiet chip row above the composer, a different species from the per-MESSAGE controls@@ -61,6 +62,8 @@ export function personaGroups(personas: Persona[]): { group: string; items: Persexport function SessionSetupRow(props: Props) {const { t } = useTranslation();const [openMenu, setOpenMenu] = useState<"coworker" | "folder" | "machine" | null>(null);+ // On a machine, the Mac's file picker cannot see the folders: a dialog takes a typed path.+ const [machineDialog, setMachineDialog] = useState(false);const [recents, setRecents] = useState<RecentWorkspace[] | null>(null);const [error, setError] = useState("");const personas = (props.personas || []).filter((p) => p.enabled);@@ -70,6 +73,12 @@ export function SessionSetupRow(props: Props) {const toggle = (menu: "coworker" | "folder" | "machine") => {setError("");+ if (menu === "folder" && currentMachine) {+ // The folder lives on the machine: no menu, the path dialog.+ setOpenMenu(null);+ setMachineDialog(true);+ return;+ }if (menu === "folder" && openMenu !== "folder") {getRecentWorkspaces().then(setRecents).catch(() => setRecents([]));}@@ -97,6 +106,17 @@ export function SessionSetupRow(props: Props) {return (<div className="max-w-3xl mx-auto mb-1.5 px-1 flex items-center gap-1.5" data-testid="setup-row">{openMenu && <div className="fixed inset-0 z-20" onClick={() => setOpenMenu(null)} />}+ {machineDialog && currentMachine && (+ <MachineFolderDialog+ coworkerName={fullPersonaName(current?.name, props.agent)}+ machine={currentMachine}+ onPick={(path, branch) => {+ setMachineDialog(false);+ props.onPickFolder(path, branch);+ }}+ onCancel={() => setMachineDialog(false)}+ />+ )}{/* Coworker chip — name only, no icon (owner call). */}<div className="relative">diff --git a/surfaces/gui/src/locales/en.json b/surfaces/gui/src/locales/en.jsonindex a5dbcbd6..97f5fa62 100644--- a/surfaces/gui/src/locales/en.json+++ b/surfaces/gui/src/locales/en.json@@ -2174,7 +2174,16 @@"send_sub": "Code work happens inside a folder on ⌂ {{machine}} — enter a path there, or start somewhere temporary.","path_placeholder": "/home/you/project (path on {{machine}})","use_temp": "Use temporary folder on {{machine}}",- "temp_note": "A temporary folder is created on ⌂ {{machine}} only when you send, with git ready. Your message sends as soon as you choose."+ "temp_note": "A temporary folder is created on ⌂ {{machine}} only when you send, with git ready. Your message sends as soon as you choose.",+ "draft_title": "Where should {{name}} work on ⌂ {{machine}}?",+ "draft_sub": "Type a folder path on {{machine}}. Recent folders are listed.",+ "check": "Check",+ "checking": "Checking…",+ "found": "✓ Folder found on {{machine}}",+ "found_branch": "✓ Folder found on {{machine}} · git branch {{branch}}",+ "not_found": "No folder at {{path}} on {{machine}}.",+ "use": "Use this folder",+ "type_path": "Type a path on {{machine}}…"},"access": {"another_machine": "another machine",diff --git a/surfaces/gui/src/locales/zh.json b/surfaces/gui/src/locales/zh.jsonindex 66784828..668c437d 100644--- a/surfaces/gui/src/locales/zh.json+++ b/surfaces/gui/src/locales/zh.json@@ -2134,7 +2134,16 @@"send_sub": "代码工作在 ⌂ {{machine}} 上的文件夹里进行 —— 输入那台机器上的路径,或从临时位置开始。","path_placeholder": "/home/you/project ({{machine}} 上的路径)","use_temp": "在 {{machine}} 上使用临时文件夹",- "temp_note": "临时文件夹只在你发送时于 ⌂ {{machine}} 上创建,git 已就绪。你一选定,消息即发送。"+ "temp_note": "临时文件夹只在你发送时于 ⌂ {{machine}} 上创建,git 已就绪。你一选定,消息即发送。",+ "draft_title": "{{name}} 应在 ⌂ {{machine}} 的哪个文件夹中工作?",+ "draft_sub": "输入 {{machine}} 上的文件夹路径。下方列出最近使用的文件夹。",+ "check": "检查",+ "checking": "检查中…",+ "found": "✓ 已在 {{machine}} 上找到该文件夹",+ "found_branch": "✓ 已在 {{machine}} 上找到该文件夹 · git 分支 {{branch}}",+ "not_found": "{{machine}} 上没有 {{path}} 这个文件夹。",+ "use": "使用此文件夹",+ "type_path": "输入 {{machine}} 上的路径…"},"access": {"another_machine": "另一台机器",