Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
feat(ui): native-style folder picker (browse + mkdir + show-hidden)
cyhfc62dce3d834
diff --git a/ui/src/components/ui/directory-browser.tsx b/ui/src/components/ui/directory-browser.tsxindex 59aad2d18..10c75c192 100644--- a/ui/src/components/ui/directory-browser.tsx+++ b/ui/src/components/ui/directory-browser.tsx@@ -1,9 +1,25 @@import React, { useEffect, useState, useCallback, useRef } from 'react';-import { Folder, FolderOpen, ChevronRight, ArrowUp, X, Check, RefreshCw, Eye, EyeOff } from 'lucide-react';+import {+ Check,+ ChevronLeft,+ ChevronRight,+ Download,+ Eye,+ EyeOff,+ FileText,+ Folder,+ FolderOpen,+ FolderPlus,+ Home,+ Monitor,+ RefreshCw,+ X,+} from 'lucide-react';import { useTranslation } from 'react-i18next';-import { useApi } from '../../context/ApiContext';import clsx from 'clsx';+import { useApi } from '../../context/ApiContext';+interface DirectoryBrowserProps {/** Initial path to show when opening */initialPath?: string;@@ -13,6 +29,9 @@ interface DirectoryBrowserProps {onClose: () => void;}+// Mirrors design.pen y5cQ5 — macOS Finder-style folder picker: traffic+// lights + toolbar (history nav + breadcrumb + show-hidden + new-folder)+// + favorites sidebar + folder list + footer (path + cancel + select).export const DirectoryBrowser: React.FC<DirectoryBrowserProps> = ({initialPath,onSelect,@@ -27,25 +46,54 @@ export const DirectoryBrowser: React.FC<DirectoryBrowserProps> = ({const [loading, setLoading] = useState(false);const [error, setError] = useState<string | null>(null);const [showHidden, setShowHidden] = useState(false);+ // Linear history so the < / > arrows behave like a real file browser+ // instead of just walking the directory tree.+ const [history, setHistory] = useState<string[]>([]);+ const [historyIndex, setHistoryIndex] = useState(-1);+ // Inline "create new folder" prompt — shown at the end of the list so+ // it feels like a continuation of the directory rather than a modal.+ const [creating, setCreating] = useState(false);+ const [newFolderName, setNewFolderName] = useState('');+ const [createError, setCreateError] = useState<string | null>(null);+ const newFolderInputRef = useRef<HTMLInputElement | null>(null);- // Guard against setState after unmount / stale responsesconst mountedRef = useRef(true);const reqIdRef = useRef(0);useEffect(() => {- return () => { mountedRef.current = false; };+ return () => {+ mountedRef.current = false;+ };}, []);- // Esc key to close+ // Esc closes the picker, ⌘N opens the new-folder prompt — both familiar+ // shortcuts from Finder.useEffect(() => {const onKey = (e: KeyboardEvent) => {- if (e.key === 'Escape') onClose();+ if (e.key === 'Escape') {+ if (creating) {+ setCreating(false);+ setNewFolderName('');+ setCreateError(null);+ } else {+ onClose();+ }+ } else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'n' && !creating) {+ e.preventDefault();+ setCreating(true);+ }};window.addEventListener('keydown', onKey);return () => window.removeEventListener('keydown', onKey);- }, [onClose]);+ }, [creating, onClose]);- const browse = useCallback(+ useEffect(() => {+ if (creating) {+ newFolderInputRef.current?.focus();+ }+ }, [creating]);++ const fetchPath = useCallback(async (path: string, hidden?: boolean) => {const id = ++reqIdRef.current;setLoading(true);@@ -53,17 +101,21 @@ export const DirectoryBrowser: React.FC<DirectoryBrowserProps> = ({const useHidden = hidden ?? showHidden;try {const result = await api.browseDirectory(path, useHidden);- if (!mountedRef.current || reqIdRef.current !== id) return;+ if (!mountedRef.current || reqIdRef.current !== id) {+ return null;+ }if (result.ok) {setCurrentPath(result.path ?? path);setParent(result.parent ?? null);setDirs(result.dirs ?? []);- } else {- setError(result.error ?? 'Unknown error');+ return result.path ?? path;}+ setError(result.error ?? 'Unknown error');+ return null;} catch (e: any) {- if (!mountedRef.current || reqIdRef.current !== id) return;+ if (!mountedRef.current || reqIdRef.current !== id) return null;setError(e.message ?? String(e));+ return null;} finally {if (mountedRef.current && reqIdRef.current === id) {setLoading(false);@@ -73,134 +125,353 @@ export const DirectoryBrowser: React.FC<DirectoryBrowserProps> = ({[api, showHidden],);+ const navigate = useCallback(+ async (path: string, hidden?: boolean) => {+ // Reset the inline new-folder state whenever the user moves around —+ // a half-typed name shouldn't survive navigating away.+ setCreating(false);+ setNewFolderName('');+ setCreateError(null);+ const resolved = await fetchPath(path, hidden);+ if (resolved) {+ setHistory((prev) => [...prev.slice(0, historyIndex + 1), resolved]);+ setHistoryIndex((prev) => prev + 1);+ }+ },+ [fetchPath, historyIndex],+ );++ const goBack = useCallback(() => {+ if (historyIndex <= 0) return;+ const next = historyIndex - 1;+ setHistoryIndex(next);+ fetchPath(history[next]);+ }, [history, historyIndex, fetchPath]);++ const goForward = useCallback(() => {+ if (historyIndex >= history.length - 1) return;+ const next = historyIndex + 1;+ setHistoryIndex(next);+ fetchPath(history[next]);+ }, [history, historyIndex, fetchPath]);+useEffect(() => {- browse(initialPath || '~');+ navigate(initialPath || '~');+ // eslint-disable-next-line react-hooks/exhaustive-deps}, []);- // Build breadcrumb segments from currentPath- const breadcrumbs = currentPath- ? currentPath.split('/').reduce<{ label: string; path: string }[]>((acc, seg, i) => {- if (i === 0 && seg === '') {- acc.push({ label: '/', path: '/' });- } else if (seg) {- const prev = acc.length ? acc[acc.length - 1].path : '';- const full = prev === '/' ? `/${seg}` : `${prev}/${seg}`;- acc.push({ label: seg, path: full });- }- return acc;- }, [])- : [];+ const toggleHidden = () => {+ const next = !showHidden;+ setShowHidden(next);+ fetchPath(currentPath, next);+ };++ const submitNewFolder = async () => {+ const name = newFolderName.trim();+ if (!name) return;+ setCreateError(null);+ try {+ const target = currentPath ? `${currentPath.replace(/\/$/, '')}/${name}` : name;+ await api.browseMkdir(target);+ setCreating(false);+ setNewFolderName('');+ await fetchPath(currentPath);+ } catch (err: any) {+ const message: string = err?.message ?? String(err);+ if (/exists/i.test(message)) {+ setCreateError(t('directoryBrowser.newFolderExists'));+ } else {+ setCreateError(message);+ }+ }+ };++ // Breadcrumb: collapse the home prefix to ⌂ so deeply-nested paths still fit+ // in the toolbar without scrolling.+ const breadcrumbs = (() => {+ if (!currentPath) return [] as { label: string; path: string; isHome?: boolean }[];+ const home = (typeof window !== 'undefined' && (window as any).__USER_HOME__) || '';+ const startsAtHome = home && currentPath.startsWith(home);+ const segments = (startsAtHome ? currentPath.slice(home.length) : currentPath)+ .split('/')+ .filter(Boolean);+ const out: { label: string; path: string; isHome?: boolean }[] = [];+ if (startsAtHome) {+ out.push({ label: '⌂', path: home, isHome: true });+ } else {+ out.push({ label: '/', path: '/' });+ }+ let acc = startsAtHome ? home : '';+ for (const seg of segments) {+ acc = acc === '/' || acc === '' ? `${acc}${seg}` : `${acc}/${seg}`;+ if (!acc.startsWith('/')) acc = `/${acc}`;+ out.push({ label: seg, path: acc });+ }+ return out;+ })();const canConfirm = !!currentPath && !loading && !error;+ const canBack = historyIndex > 0;+ const canForward = historyIndex < history.length - 1;++ // Static shortcuts mirroring Finder's Favorites column. We just hand+ // these to the existing `browseDirectory` endpoint — the backend+ // expands ``~`` so we don't need to resolve them client-side.+ const favorites: { i18nKey: string; path: string; icon: React.ReactNode }[] = [+ { i18nKey: 'directoryBrowser.favoritesHome', path: '~', icon: <Home className="size-3.5" /> },+ { i18nKey: 'directoryBrowser.favoritesDesktop', path: '~/Desktop', icon: <Monitor className="size-3.5" /> },+ { i18nKey: 'directoryBrowser.favoritesDocuments', path: '~/Documents', icon: <FileText className="size-3.5" /> },+ { i18nKey: 'directoryBrowser.favoritesDownloads', path: '~/Downloads', icon: <Download className="size-3.5" /> },+ ];return (<div- className="fixed inset-0 z-50 flex items-center justify-center bg-black/40"+ className="fixed inset-0 z-50 flex items-center justify-center bg-black/50"role="dialog"aria-modal="true"aria-label={t('directoryBrowser.title')}onClick={onClose}><div- className="bg-panel border border-border rounded-xl shadow-xl w-full max-w-lg max-h-[70vh] flex flex-col"+ className="flex max-h-[80vh] w-full max-w-3xl flex-col overflow-hidden rounded-2xl border border-border-strong bg-surface shadow-[0_24px_64px_-12px_rgba(0,0,0,0.6)]"onClick={(e) => e.stopPropagation()}>- {/* Header */}- <div className="flex items-center justify-between px-4 py-3 border-b border-border">- <h3 className="font-semibold text-text text-sm">{t('directoryBrowser.title')}</h3>+ {/* Traffic-light header */}+ <div className="flex items-center gap-3 border-b border-border bg-surface-2 px-4 py-3"><div className="flex items-center gap-2"><button- onClick={() => {- const next = !showHidden;- setShowHidden(next);- browse(currentPath, next);- }}- className={clsx(- 'p-1 rounded transition-colors',- showHidden ? 'text-accent' : 'text-muted hover:text-text',- )}- title={showHidden ? t('directoryBrowser.hideHidden') : t('directoryBrowser.showHidden')}- >- {showHidden ? <Eye size={15} /> : <EyeOff size={15} />}- </button>- <button onClick={onClose} className="text-muted hover:text-text transition-colors">- <X size={16} />- </button>+ type="button"+ aria-label="Close"+ onClick={onClose}+ className="size-3 rounded-full bg-[#FF5F57] transition hover:brightness-110"+ />+ <span className="size-3 rounded-full bg-[#FFBD2E]" />+ <span className="size-3 rounded-full bg-[#28C840]" />+ </div>+ <div className="flex flex-1 items-center justify-center gap-2 text-[13px] font-semibold text-foreground">+ <FolderOpen className="size-3.5 text-mint" />+ {t('directoryBrowser.title')}+ </div>+ <button+ type="button"+ onClick={onClose}+ aria-label={t('directoryBrowser.cancel')}+ className="text-muted transition hover:text-foreground"+ >+ <X className="size-4" />+ </button>+ </div>++ {/* Toolbar — history arrows + breadcrumb + show-hidden + new-folder */}+ <div className="flex items-center gap-2 border-b border-border px-4 py-2.5">+ <button+ type="button"+ onClick={goBack}+ disabled={!canBack}+ aria-label={t('directoryBrowser.back')}+ className={clsx(+ 'flex size-7 items-center justify-center rounded-md border border-border-strong transition',+ canBack ? 'text-foreground hover:bg-foreground/[0.06]' : 'cursor-not-allowed text-muted opacity-50',+ )}+ >+ <ChevronLeft className="size-3.5" />+ </button>+ <button+ type="button"+ onClick={goForward}+ disabled={!canForward}+ aria-label={t('directoryBrowser.forward')}+ className={clsx(+ 'flex size-7 items-center justify-center rounded-md border border-border-strong transition',+ canForward ? 'text-foreground hover:bg-foreground/[0.06]' : 'cursor-not-allowed text-muted opacity-50',+ )}+ >+ <ChevronRight className="size-3.5" />+ </button>++ <div className="flex min-w-0 flex-1 items-center gap-1 overflow-x-auto rounded-md border border-border-strong bg-surface-2 px-2 py-1 font-mono text-[11px]">+ {breadcrumbs.map((crumb, i) => (+ <React.Fragment key={`${crumb.path}-${i}`}>+ {i > 0 && <ChevronRight className="size-3 shrink-0 text-muted" />}+ <button+ type="button"+ onClick={() => navigate(crumb.path)}+ className={clsx(+ 'shrink-0 rounded px-1 py-0.5 transition hover:bg-foreground/[0.04]',+ i === breadcrumbs.length - 1 ? 'font-semibold text-cyan' : 'text-muted',+ )}+ >+ {crumb.label}+ </button>+ </React.Fragment>+ ))}+ {loading && <RefreshCw className="ml-auto size-3 shrink-0 animate-spin text-muted" />}</div>++ <button+ type="button"+ onClick={toggleHidden}+ className={clsx(+ 'flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-[11px] font-semibold transition',+ showHidden+ ? 'border-cyan/40 bg-cyan/[0.08] text-cyan'+ : 'border-border-strong text-muted hover:text-foreground',+ )}+ >+ {showHidden ? <Eye className="size-3" /> : <EyeOff className="size-3" />}+ {showHidden ? t('directoryBrowser.showHidden') : t('directoryBrowser.hideHidden')}+ </button>++ <button+ type="button"+ onClick={() => {+ setCreating(true);+ setNewFolderName('');+ setCreateError(null);+ }}+ className="flex items-center gap-1.5 rounded-md border border-border-strong px-2.5 py-1.5 text-[11px] font-medium text-foreground transition hover:bg-foreground/[0.04]"+ >+ <FolderPlus className="size-3" />+ {t('directoryBrowser.newFolder')}+ </button></div>- {/* Breadcrumb */}- <div className="px-4 py-2 border-b border-border flex items-center gap-1 text-xs overflow-x-auto min-h-[32px]">- {breadcrumbs.map((crumb, i) => (- <React.Fragment key={crumb.path}>- {i > 0 && <ChevronRight size={10} className="text-muted shrink-0" />}+ {/* Body — favorites sidebar + folder list */}+ <div className="flex min-h-0 flex-1">+ {/* Favorites sidebar */}+ <aside className="hidden w-[180px] shrink-0 flex-col gap-1 border-r border-border bg-surface-2 px-2 py-3 sm:flex">+ <div className="px-2 pb-1 font-mono text-[9px] font-bold uppercase tracking-[0.16em] text-muted">+ {t('directoryBrowser.favorites')}+ </div>+ {favorites.map((fav) => (<button- onClick={() => browse(crumb.path)}- className={clsx(- 'shrink-0 px-1 py-0.5 rounded hover:bg-foreground/5 transition-colors font-mono',- i === breadcrumbs.length - 1 ? 'text-accent font-medium' : 'text-muted',- )}+ key={fav.path}+ type="button"+ onClick={() => navigate(fav.path)}+ className="flex items-center gap-2 rounded-md px-2 py-1.5 text-left text-[12px] text-foreground transition hover:bg-foreground/[0.04]">- {crumb.label}+ <span className="text-muted">{fav.icon}</span>+ <span className="truncate">{t(fav.i18nKey)}</span></button>- </React.Fragment>- ))}- {loading && <RefreshCw size={12} className="animate-spin text-muted ml-auto shrink-0" />}- </div>+ ))}+ </aside>- {/* Directory list */}- <div className="flex-1 overflow-y-auto px-2 py-1 min-h-[200px]">- {error && (- <div className="px-3 py-2 text-sm text-danger">{error}</div>- )}+ {/* Folder list */}+ <div className="flex min-w-0 flex-1 flex-col overflow-y-auto px-2 py-2">+ {error && (+ <div className="mx-2 mb-2 rounded-md border border-destructive/40 bg-destructive/[0.06] px-3 py-2 text-sm text-destructive">+ {error}+ </div>+ )}- {/* Parent directory */}- {parent && (- <button- onClick={() => browse(parent)}- className="flex items-center gap-2 w-full px-3 py-1.5 rounded-lg hover:bg-foreground/5 transition-colors text-sm text-muted"- >- <ArrowUp size={14} />- <span>..</span>- </button>- )}-- {/* Sub-directories */}- {dirs.map((dir) => (- <button- key={dir.path}- onClick={() => browse(dir.path)}- className="flex items-center gap-2 w-full px-3 py-1.5 rounded-lg hover:bg-foreground/5 transition-colors text-sm text-text group"- >- <Folder size={14} className="text-gold group-hover:hidden shrink-0" />- <FolderOpen size={14} className="text-gold hidden group-hover:block shrink-0" />- <span className="truncate text-left">{dir.name}</span>- </button>- ))}-- {!loading && !error && dirs.length === 0 && (- <div className="px-3 py-4 text-sm text-muted text-center italic">- {t('directoryBrowser.empty')}- </div>- )}+ {parent && (+ <button+ onClick={() => navigate(parent)}+ className="flex items-center gap-2.5 rounded-md px-3 py-2 text-[13px] text-muted transition hover:bg-foreground/[0.04]"+ >+ <ChevronLeft className="size-3.5" />+ <span className="font-mono">..</span>+ </button>+ )}++ {dirs.map((dir) => (+ <button+ key={dir.path}+ onClick={() => navigate(dir.path)}+ className="group flex items-center gap-2.5 rounded-md px-3 py-2 text-left text-[13px] text-foreground transition hover:bg-foreground/[0.04]"+ >+ <Folder className="size-4 shrink-0 text-gold group-hover:hidden" />+ <FolderOpen className="hidden size-4 shrink-0 text-gold group-hover:block" />+ <span className="truncate">{dir.name}</span>+ </button>+ ))}++ {!loading && !error && dirs.length === 0 && !creating && (+ <div className="px-3 py-6 text-center text-[12px] italic text-muted">+ {t('directoryBrowser.empty')}+ </div>+ )}++ {/* Inline new-folder prompt — sits at the bottom of the list so+ the user keeps context of which directory they're creating in */}+ {creating ? (+ <div className="mt-2 flex flex-col gap-1.5 rounded-md border border-dashed border-border-strong bg-foreground/[0.03] px-3 py-2.5">+ <div className="flex items-center gap-2">+ <FolderPlus className="size-4 shrink-0 text-mint" />+ <input+ ref={newFolderInputRef}+ value={newFolderName}+ onChange={(e) => setNewFolderName(e.target.value)}+ onKeyDown={(e) => {+ if (e.key === 'Enter') submitNewFolder();+ }}+ placeholder={t('directoryBrowser.newFolderPlaceholder')}+ className="flex-1 bg-transparent text-[13px] text-foreground outline-none placeholder:text-muted"+ />+ <button+ type="button"+ onClick={() => {+ setCreating(false);+ setNewFolderName('');+ setCreateError(null);+ }}+ className="rounded-md px-2 py-0.5 text-[11px] text-muted transition hover:text-foreground"+ >+ {t('directoryBrowser.cancel')}+ </button>+ <button+ type="button"+ onClick={submitNewFolder}+ disabled={!newFolderName.trim()}+ className={clsx(+ 'rounded-md px-2.5 py-0.5 text-[11px] font-semibold transition',+ newFolderName.trim()+ ? 'bg-mint text-[#080812] hover:brightness-110'+ : 'bg-muted-soft text-muted',+ )}+ >+ {t('directoryBrowser.newFolder')}+ </button>+ </div>+ {createError && <div className="pl-6 text-[11px] text-destructive">{createError}</div>}+ </div>+ ) : (+ <button+ type="button"+ onClick={() => setCreating(true)}+ className="mt-2 flex items-center gap-2.5 rounded-md border border-dashed border-border-strong bg-foreground/[0.02] px-3 py-2 text-[12px] italic text-muted transition hover:bg-foreground/[0.04]"+ >+ <FolderPlus className="size-4 shrink-0" />+ {t('directoryBrowser.createHere')}+ </button>+ )}+ </div></div>- {/* Footer — current path + confirm */}- <div className="px-4 py-3 border-t border-border flex items-center gap-2">- <code className="flex-1 text-xs font-mono text-text bg-bg border border-border rounded px-2 py-1.5 truncate">+ {/* Footer — current path + cancel + select */}+ <div className="flex items-center gap-3 border-t border-border bg-surface-2 px-4 py-3">+ <code className="flex-1 truncate rounded-md border border-border-strong bg-surface-3 px-2.5 py-1.5 font-mono text-[11px] text-foreground">{currentPath || '—'}</code><button+ type="button"+ onClick={onClose}+ className="rounded-md border border-border-strong px-4 py-1.5 text-[12px] font-medium text-foreground transition hover:bg-foreground/[0.04]"+ >+ {t('directoryBrowser.cancel')}+ </button>+ <button+ type="button"onClick={() => canConfirm && onSelect(currentPath)}disabled={!canConfirm}className={clsx(- 'flex items-center gap-1.5 px-4 py-1.5 rounded-lg text-sm font-medium transition-colors shrink-0',+ 'flex items-center gap-1.5 rounded-md px-4 py-1.5 text-[12px] font-semibold transition',canConfirm- ? 'bg-accent hover:bg-accent/90 text-accent-foreground'- : 'bg-muted-soft text-muted cursor-not-allowed',+ ? 'bg-mint text-[#080812] shadow-[0_0_14px_-4px_rgba(91,255,160,0.6)] hover:brightness-110'+ : 'cursor-not-allowed bg-muted-soft text-muted',)}>- <Check size={14} />+ <Check className="size-3.5" />{t('directoryBrowser.select')}</button></div>diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex 0d37d20f2..f98819ac8 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -1070,11 +1070,23 @@"zh": "Chinese"},"directoryBrowser": {- "title": "Browse Directory",+ "title": "Select Project Folder","select": "Select",+ "cancel": "Cancel","empty": "No subdirectories",- "showHidden": "Show hidden directories",- "hideHidden": "Hide hidden directories"+ "showHidden": "Show hidden",+ "hideHidden": "Hide hidden",+ "newFolder": "New Folder",+ "newFolderPlaceholder": "Folder name",+ "createHere": "Create new folder here…",+ "favorites": "Favorites",+ "favoritesHome": "Home",+ "favoritesDesktop": "Desktop",+ "favoritesDocuments": "Documents",+ "favoritesDownloads": "Downloads",+ "back": "Back",+ "forward": "Forward",+ "newFolderExists": "A folder with that name already exists."},"wechat": {"userBound": "Your WeChat account is automatically configured as the bot owner.",diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex ae8da47cc..c005b09f1 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -1070,11 +1070,23 @@"zh": "中文"},"directoryBrowser": {- "title": "浏览目录",- "select": "选择",+ "title": "选择项目文件夹",+ "select": "选择此目录",+ "cancel": "取消","empty": "没有子目录",- "showHidden": "显示隐藏目录",- "hideHidden": "隐藏隐藏目录"+ "showHidden": "显示隐藏",+ "hideHidden": "隐藏隐藏",+ "newFolder": "新建文件夹",+ "newFolderPlaceholder": "文件夹名称",+ "createHere": "在这里新建文件夹…",+ "favorites": "收藏",+ "favoritesHome": "主目录",+ "favoritesDesktop": "桌面",+ "favoritesDocuments": "文稿",+ "favoritesDownloads": "下载",+ "back": "后退",+ "forward": "前进",+ "newFolderExists": "已存在同名文件夹。"},"wechat": {"userBound": "您的微信账号已自动配置为机器人所有者。",