The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(memory-sources): pick folders with the native chooser, never store a bare name\n\nBrowse on the folder memory source was an `<input type="file" webkitdirectory>`.\nThat element cannot report where the directory it returned lives: the handler\nread `File.path`, which is an Electron extension that none of Wry's renderers\n(WKWebView, WebView2, WebKitGTK) implement, and fell through to\n`webkitRelativePath.split('/')[0]` — the directory's bare name, location\ndiscarded.\n\nThe stored source then looked configured and could never sync. The reader\nanchors a relative path on the workspace, so it failed once per cycle,\nforever, with `folder does not exist: docs`. Nothing downstream could repair\nit, because `docs` is not a relative path to the chosen directory.\n\nBrowse now calls a native chooser in the shell, which returns an absolute path\non every platform because the OS owns the selection. When no absolute path can\nbe obtained the field reports it and stays as it was: a visible error is\nrecoverable, a silently stored name is not.\n\nHand-typed paths are untouched, relative ones included — those resolve against\nthe workspace at read time, which this field deliberately does not\nsecond-guess.\n\nCloses #5831\n
Shanu6924d2f3fce9
diff --git a/app/src-tauri/Cargo.lock b/app/src-tauri/Cargo.lockindex 9c801370fa..76f3f90e57 100644--- a/app/src-tauri/Cargo.lock+++ b/app/src-tauri/Cargo.lock@@ -25,6 +25,7 @@ dependencies = ["parking_lot","rand 0.9.5","reqwest 0.12.28",+ "rfd","rusqlite","rustls","sentry",@@ -187,6 +188,27 @@ dependencies = ["password-hash",]+[[package]]+name = "ashpd"+version = "0.11.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d2f3f79755c74fd155000314eb349864caa787c6592eace6c6882dad873d9c39"+dependencies = [+ "enumflags2",+ "futures-channel",+ "futures-util",+ "rand 0.9.5",+ "raw-window-handle",+ "serde",+ "serde_repr",+ "tokio",+ "url",+ "wayland-backend",+ "wayland-client",+ "wayland-protocols",+ "zbus",+]+[[package]]name = "async-broadcast"version = "0.7.2"@@ -1544,6 +1566,15 @@ dependencies = ["syn 3.0.4",]+[[package]]+name = "dlib"+version = "0.5.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ab8ecd87370524b461f8557c119c405552c396ed91fc0a8eec68679eab26f94a"+dependencies = [+ "libloading 0.7.4",+]+[[package]]name = "dlopen2"version = "0.8.2"@@ -1597,6 +1628,12 @@ version = "0.15.7"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"+[[package]]+name = "downcast-rs"+version = "1.2.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"+[[package]]name = "dpi"version = "0.1.2"@@ -4680,7 +4717,7 @@ checksum = "740ebea15c5d1428f910cd1a5f52cebf8d25006245ed8ade92702f4943d91e07"dependencies = ["base64 0.22.1","indexmap 2.14.1",- "quick-xml",+ "quick-xml 0.38.4","serde","time",]@@ -4899,6 +4936,15 @@ dependencies = ["memchr",]+[[package]]+name = "quick-xml"+version = "0.41.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e660451e55124f798a69a5af3f49ccfbefbd41910eefd25caf2393e1f3473ec1"+dependencies = [+ "memchr",+]+[[package]]name = "quinn"version = "0.11.11"@@ -5255,6 +5301,31 @@ dependencies = ["web-sys",]+[[package]]+name = "rfd"+version = "0.15.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ef2bee61e6cffa4635c72d7d81a84294e28f0930db0ddcb0f66d10244674ebed"+dependencies = [+ "ashpd",+ "block2 0.6.2",+ "dispatch2",+ "glib-sys",+ "gobject-sys",+ "gtk-sys",+ "js-sys",+ "log",+ "objc2 0.6.4",+ "objc2-app-kit 0.3.2",+ "objc2-core-foundation",+ "objc2-foundation 0.3.2",+ "raw-window-handle",+ "wasm-bindgen",+ "wasm-bindgen-futures",+ "web-sys",+ "windows-sys 0.59.0",+]+[[package]]name = "ring"version = "0.17.14"@@ -5516,6 +5587,12 @@ dependencies = ["syn 3.0.4",]+[[package]]+name = "scoped-tls"+version = "1.0.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"+[[package]]name = "scopeguard"version = "1.2.0"@@ -7381,6 +7458,7 @@ dependencies = ["signal-hook-registry","socket2","tokio-macros",+ "tracing","windows-sys 0.61.2",]@@ -8161,6 +8239,66 @@ dependencies = ["web-sys",]+[[package]]+name = "wayland-backend"+version = "0.3.17"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "38a91b4eaddff87b1cd1074985e3713da4af2c49742d1b356b2c01670a67a078"+dependencies = [+ "cc",+ "downcast-rs",+ "rustix",+ "scoped-tls",+ "smallvec",+ "wayland-sys",+]++[[package]]+name = "wayland-client"+version = "0.31.15"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e3c36a0f861ad76d0901f2800b46321410d9f73f2ea88aac0650d86c32688073"+dependencies = [+ "bitflags 2.13.1",+ "rustix",+ "wayland-backend",+ "wayland-scanner",+]++[[package]]+name = "wayland-protocols"+version = "0.32.13"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "23d0c813de3daa2ed6520af85a3bd49b0e722a3078506899aa9686fea58dc4b6"+dependencies = [+ "bitflags 2.13.1",+ "wayland-backend",+ "wayland-client",+ "wayland-scanner",+]++[[package]]+name = "wayland-scanner"+version = "0.31.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "338e30461b3a2b67d70eb30a6d89f8e0c93a833e07d2ae89085cd070c4a00ac0"+dependencies = [+ "proc-macro2",+ "quick-xml 0.41.0",+ "quote",+]++[[package]]+name = "wayland-sys"+version = "0.31.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d8eab23fefc9e41f8e841df4a9c707e8a8c4ed26e944ef69297184de2785e3be"+dependencies = [+ "dlib",+ "log",+ "pkg-config",+]+[[package]]name = "web-sys"version = "0.3.104"@@ -9156,6 +9294,7 @@ dependencies = ["rustix","serde","serde_repr",+ "tokio","tracing","uds_windows","uuid",@@ -9372,6 +9511,7 @@ dependencies = ["endi","enumflags2","serde",+ "url","winnow 1.0.4","zcheapstr","zvariant_derive",diff --git a/app/src-tauri/Cargo.toml b/app/src-tauri/Cargo.tomlindex 96ac256f75..632385c0fc 100644--- a/app/src-tauri/Cargo.toml+++ b/app/src-tauri/Cargo.toml@@ -80,6 +80,47 @@ hex = "0.4"rustls = { version = "0.23", default-features = false, features = ["ring"] }log = "0.4"+# Native directory chooser for the folder memory-source (#5831). A directory+# picked in the renderer carries no filesystem path — `File.path` is an+# Electron extension that neither Wry's WKWebView/WebView2/WebKitGTK nor+# plain Chromium implements — so the only way to learn where a chosen folder+# lives is to ask the OS from the host process.+#+# `default-features = false` is what makes this a different proposition from+# the `rfd` that `artifact_commands` shed in #5541. That removal counted 13+# packages: `ashpd`, `zbus`, and the `async-io`/`polling` executor stack.+# Every one of those arrives through `rfd`'s **default** `xdg-portal` feature+# (`xdg-portal = ["ashpd", "urlencoding", "pollster"]`), which is not enabled+# here. `gtk3` binds the GTK that Wry already links on Linux instead —+# `gtk-sys` is in that graph via `tray-icon` -> `tauri` whether or not this+# entry exists — and on macOS/Windows `rfd` compiles against `objc2-app-kit`+# / `windows-sys`, both already present. The marginal cost is `rfd` itself.+#+# `Cargo.lock` will nonetheless gain `ashpd` and a wayland cluster, and that+# is expected: the lockfile records the **maximal** resolution graph,+# including optional and target-gated edges nothing enables. Read the real+# graph, not the lock —+#+# cargo tree --target x86_64-unknown-linux-gnu -e normal -i ashpd+# # -> warning: nothing to print.+#+# Prefer this over `tauri-plugin-dialog`: that plugin depends on the same+# `rfd` AND drags `tauri-plugin-fs` in behind it, for one command that needs+# no filesystem permission surface at all.+#+# The feature list is `tauri-plugin-dialog`'s own, verbatim — that plugin is+# the reference integration of `rfd` into a Tauri app, and each of the three+# matters here. `gtk3` is the right Linux backend precisely *because* the host+# is GTK-based (rfd steers non-GTK apps to the portal instead), `tokio` drives+# the async dialog on the runtime a `#[tauri::command]` already runs on, and+# `common-controls-v6` mirrors the feature `tauri` itself enables above, so+# the Windows dialog matches the rest of the app's chrome.+rfd = { version = "0.15", default-features = false, features = [+ "gtk3",+ "tokio",+ "common-controls-v6",+] }+# Sentry for the Tauri shell (desktop host) process — separate Sentry project# from the React frontend and the Rust core sidecar. DSN is baked at compile# time via `option_env!("OPENHUMAN_TAURI_SENTRY_DSN")` in `lib.rs::run()` anddiff --git a/app/src-tauri/capabilities/default.json b/app/src-tauri/capabilities/default.jsonindex c3c89b7ef3..e540b87f4e 100644--- a/app/src-tauri/capabilities/default.json+++ b/app/src-tauri/capabilities/default.json@@ -33,6 +33,7 @@"allow-workspace-files","allow-artifact-download","allow-artifact-save",+ "allow-directory-picker","allow-app-update","allow-loopback-oauth"]diff --git a/app/src-tauri/permissions/allow-directory-picker.toml b/app/src-tauri/permissions/allow-directory-picker.tomlnew file mode 100644index 0000000000..c4d10285e5--- /dev/null+++ b/app/src-tauri/permissions/allow-directory-picker.toml@@ -0,0 +1,11 @@+[[permission]]+identifier = "allow-directory-picker"+description = "Allow opening the OS-native directory chooser so the folder memory-source can store the absolute path the user picked (#5831)"++[permission.commands]++allow = [+ "pick_directory_via_dialog",+]++deny = []diff --git a/app/src-tauri/src/directory_picker.rs b/app/src-tauri/src/directory_picker.rsnew file mode 100644index 0000000000..eed045fac0--- /dev/null+++ b/app/src-tauri/src/directory_picker.rs@@ -0,0 +1,111 @@+//! Native directory chooser for memory-source configuration (#5831).+//!+//! The folder memory-source used to be picked with an+//! `<input type="file" webkitdirectory>` in the renderer. That element hands+//! back `File` objects, and a `File` carries no filesystem location: the+//! `File.path` attribute the old handler read is an Electron extension that+//! no web engine implements. Wry's WKWebView, WebView2 and WebKitGTK do not,+//! and neither does plain Chromium, so the handler always fell through to+//! `webkitRelativePath.split('/')[0]` — the chosen directory's **name**, with+//! its location discarded — and stored that.+//!+//! The resulting source looked configured and could never sync. Because the+//! reader anchors a relative path on the workspace, it failed once per sync+//! cycle, forever, with `folder does not exist: docs (resolved to+//! <workspace>/docs)`. Nothing downstream could repair it: `docs` is not a+//! relative path to the chosen directory, it is a name whose location was+//! thrown away.+//!+//! A host-side dialog closes that gap by construction. It returns an absolute+//! path on every platform, in every renderer, because the OS — not the web+//! engine — owns the selection.+//!+//! ## Trust boundary+//!+//! Deliberately none. Unlike [`crate::artifact_commands`], which re-validates+//! that a renderer-supplied path sits inside the artifacts tree because there+//! the renderer *supplies* the path, this command takes no input at all and+//! returns only what the user chose in an OS-owned dialog. The renderer+//! cannot steer it at a directory, and choosing a folder to index is the+//! user's decision to make anywhere on their own disk.++use std::path::Path;++/// Render a chosen directory as the string the renderer will store, refusing+/// anything that is not absolute.+///+/// Split from the command so it is testable: the dialog itself needs a user+/// and a window server, but this rule is the part worth pinning. The OS+/// choosers all hand back absolute paths, so the rejection is belt-and-braces+/// rather than a branch we expect to take. It exists because a relative value+/// reaching the store is the entire defect this command was written to remove+/// — an error here is recoverable and visible, whereas a stored relative path+/// is neither.+fn absolute_path_string(path: &Path) -> Result<String, String> {+ if !path.is_absolute() {+ return Err(format!(+ "the directory chooser returned a non-absolute path: {}",+ path.display()+ ));+ }+ Ok(path.display().to_string())+}++/// Open the OS-native directory chooser and return the absolute path of the+/// directory the user selected.+///+/// Returns:+/// - `Ok(Some(path))` — the absolute path chosen.+/// - `Ok(None)` — the user dismissed the dialog. Not an error; the caller+/// leaves the field exactly as it was.+/// - `Err(_)` — the dialog could not run, or it somehow yielded a relative+/// path. The caller surfaces this rather than storing anything.+#[tauri::command]+pub async fn pick_directory_via_dialog() -> Result<Option<String>, String> {+ // macOS: NSOpenPanel. Windows: IFileOpenDialog. Linux: the GTK chooser+ // that WebKitGTK already links (see the `gtk3` feature in Cargo.toml).+ // The await resolves when the user picks or cancels.+ let handle = rfd::AsyncFileDialog::new().pick_folder().await;++ let Some(dir) = handle else {+ log::info!("[directory_picker] pick_directory_via_dialog cancelled by user");+ return Ok(None);+ };++ let picked = absolute_path_string(dir.path())?;+ log::info!("[directory_picker] pick_directory_via_dialog chose {picked}");+ Ok(Some(picked))+}++#[cfg(test)]+mod tests {+ use super::absolute_path_string;+ use std::path::Path;++ #[cfg(not(target_os = "windows"))]+ const ABSOLUTE: &str = "/Users/you/notes";+ #[cfg(target_os = "windows")]+ const ABSOLUTE: &str = r"C:\Users\you\notes";++ #[test]+ fn passes_an_absolute_path_through_unchanged() {+ assert_eq!(+ absolute_path_string(Path::new(ABSOLUTE)),+ Ok(ABSOLUTE.to_string())+ );+ }++ #[test]+ fn refuses_a_bare_directory_name() {+ // `docs` is exactly what the old `webkitRelativePath.split('/')[0]`+ // fallback stored, and what made the source unsyncable (#5831).+ let err = absolute_path_string(Path::new("docs")).unwrap_err();+ assert!(err.contains("non-absolute"), "unexpected message: {err}");+ assert!(err.contains("docs"), "message should name the value: {err}");+ }++ #[test]+ fn refuses_a_relative_path_with_separators() {+ assert!(absolute_path_string(Path::new("notes/inner")).is_err());+ }+}diff --git a/app/src-tauri/src/lib.rs b/app/src-tauri/src/lib.rsindex 0b5eef295c..2565c57719 100644--- a/app/src-tauri/src/lib.rs+++ b/app/src-tauri/src/lib.rs@@ -48,6 +48,7 @@ mod deep_link_ipc_windows;// developer host covers them.mod deep_link_registration_check;mod dictation_hotkeys;+mod directory_picker;mod file_logging;// Routing the frontend to a core that is not the one in this process. Leaf// gated: with `gateways` off the commands are simply absent, which is what the@@ -3394,6 +3395,11 @@ pub fn run() {// too (CodeRabbit on #4127). The Save-As dialog that used to sit in// front of this went with the shell's `rfd` dependency.artifact_commands::download_artifact_to_downloads,+ // Native directory chooser for the folder memory-source (#5831).+ // Unlike the Save-As dialog above it, this one has no renderer-side+ // substitute: a `webkitdirectory` input cannot report where the+ // directory it returned actually lives.+ directory_picker::pick_directory_via_dialog,check_core_update,apply_core_update,check_app_update,diff --git a/app/src/components/intelligence/AddMemorySourceFields.tsx b/app/src/components/intelligence/AddMemorySourceFields.tsxindex eea9a5e48c..de7f77fda0 100644--- a/app/src/components/intelligence/AddMemorySourceFields.tsx+++ b/app/src/components/intelligence/AddMemorySourceFields.tsx@@ -19,6 +19,7 @@ import type { ComposioConnection } from '../../lib/composio/types';import { useT } from '../../lib/i18n/I18nContext';import type { SourceKind } from '../../services/memorySourcesService';import TextField from '../ui/TextField';+import { FolderField } from './FolderField';const log = debug('intelligence:add-memory-source-dialog');@@ -52,62 +53,6 @@ interface FieldProps {type?: string;}-interface FolderFieldProps {- label: string;- value: string;- onChange: (v: string) => void;-}--function FolderField({ label, value, onChange }: FolderFieldProps) {- const { t } = useT();- return (- <label className="block">- <span className="text-xs font-medium text-content-secondary">{label}</span>- <div className="mt-1 flex gap-2">- <TextField- type="text"- value={value}- onChange={e => onChange(e.target.value)}- placeholder={t('memorySources.folderPathPlaceholder')}- />- <label- className="shrink-0 cursor-pointer rounded-md border border-line-strong bg-surface px-3 py-2- text-xs font-medium text-content-secondary transition-colors- hover:border-primary-400 hover:text-primary-600- dark:bg-surface-muted dark:text-content-secondary- dark:hover:border-primary-500 dark:hover:text-primary-400">- {t('memorySources.browse')}- <input- type="file"- // @ts-expect-error — non-standard but supported in CEF/Chromium- webkitdirectory=""- multiple- className="hidden"- onChange={e => {- const files = e.target.files;- if (!files || files.length === 0) return;- // Chromium exposes the chosen directory path on the first file's `path`- // attribute when the renderer has filesystem-aware integration (CEF).- // Fall back to webkitRelativePath split if `path` isn't available.- const first = files[0] as File & { path?: string };- if (first.path) {- // first.path is the absolute path to the file. Derive the directory- // by trimming the relative portion (everything after the chosen root).- const rel = first.webkitRelativePath || first.name;- const abs = first.path;- const idx = abs.lastIndexOf(rel);- onChange(idx > 0 ? abs.slice(0, idx).replace(/\/$/, '') : abs);- } else if (first.webkitRelativePath) {- onChange(first.webkitRelativePath.split('/')[0]);- }- }}- />- </label>- </div>- </label>- );-}-export function Field({ label, value, onChange, placeholder, type = 'text' }: FieldProps) {return (<label className="block">diff --git a/app/src/components/intelligence/FolderField.test.tsx b/app/src/components/intelligence/FolderField.test.tsxnew file mode 100644index 0000000000..453ace2ffa--- /dev/null+++ b/app/src/components/intelligence/FolderField.test.tsx@@ -0,0 +1,143 @@+/**+ * Tests for the folder memory-source path field (#5831).+ *+ * The defect these guard against: Browse used to be an+ * `<input type="file" webkitdirectory>`, whose handler stored+ * `webkitRelativePath.split('/')[0]` when the non-standard `File.path` was+ * absent. That is the chosen directory's bare *name*, and no renderer Wry+ * ships (WKWebView, WebView2, WebKitGTK) provides `File.path`, so it was the+ * value stored every time. The source then looked configured and failed once+ * per sync cycle, forever, with `folder does not exist: docs`.+ *+ * The invariant asserted here is therefore not "Browse works" but the+ * stronger "Browse never writes a value that cannot resolve".+ */+import { fireEvent, screen, waitFor } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { renderWithProviders } from '../../test/test-utils';+import { pickDirectoryNatively } from '../../utils/tauriCommands/directoryPicker';+import { KindFields } from './AddMemorySourceFields';++vi.mock('../../utils/tauriCommands/directoryPicker', () => ({ pickDirectoryNatively: vi.fn() }));++const mockPick = vi.mocked(pickDirectoryNatively);++function renderFolderFields(path = '') {+ const setPath = vi.fn();+ renderWithProviders(+ <KindFields+ kind="folder"+ path={path}+ setPath={setPath}+ glob=""+ setGlob={vi.fn()}+ url=""+ setUrl={vi.fn()}+ branch=""+ setBranch={vi.fn()}+ query=""+ setQuery={vi.fn()}+ selector=""+ setSelector={vi.fn()}+ connections={[]}+ loadingConnections={false}+ supportedToolkits={null}+ connectionId=""+ setConnection={vi.fn()}+ />+ );+ return { setPath };+}++const UNAVAILABLE_COPY = 'Could not determine where that folder is. Type its full path instead.';++describe('FolderField (folder memory source)', () => {+ beforeEach(() => {+ mockPick.mockReset();+ });++ it('stores the absolute path the native chooser returned', async () => {+ mockPick.mockResolvedValue({ ok: true, path: '/Users/you/notes' });+ const { setPath } = renderFolderFields();++ fireEvent.click(screen.getByRole('button', { name: /browse/i }));++ await waitFor(() => expect(setPath).toHaveBeenCalledWith('/Users/you/notes'));+ expect(screen.queryByRole('alert')).toBeNull();+ });++ it('stores nothing and explains itself when no path can be obtained', async () => {+ mockPick.mockResolvedValue({ ok: false, reason: 'unavailable' });+ const { setPath } = renderFolderFields();++ fireEvent.click(screen.getByRole('button', { name: /browse/i }));++ expect(await screen.findByRole('alert')).toHaveTextContent(UNAVAILABLE_COPY);+ expect(setPath).not.toHaveBeenCalled();+ });++ it('stores nothing when the host chooser tried and failed', async () => {+ mockPick.mockResolvedValue({ ok: false, reason: 'failed', message: 'no portal' });+ const { setPath } = renderFolderFields();++ fireEvent.click(screen.getByRole('button', { name: /browse/i }));++ expect(await screen.findByRole('alert')).toHaveTextContent(UNAVAILABLE_COPY);+ expect(setPath).not.toHaveBeenCalled();+ });++ it('leaves the field untouched and silent when the user cancels', async () => {+ mockPick.mockResolvedValue({ ok: false, reason: 'cancelled' });+ const { setPath } = renderFolderFields();++ fireEvent.click(screen.getByRole('button', { name: /browse/i }));++ await waitFor(() => expect(mockPick).toHaveBeenCalled());+ expect(setPath).not.toHaveBeenCalled();+ expect(screen.queryByRole('alert')).toBeNull();+ });++ it('clears a previous error once the user types a path by hand', async () => {+ mockPick.mockResolvedValue({ ok: false, reason: 'unavailable' });+ const { setPath } = renderFolderFields();++ fireEvent.click(screen.getByRole('button', { name: /browse/i }));+ expect(await screen.findByRole('alert')).toBeInTheDocument();++ fireEvent.change(screen.getByPlaceholderText('/Users/you/notes'), {+ target: { value: '/Users/you/docs' },+ });++ expect(screen.queryByRole('alert')).toBeNull();+ expect(setPath).toHaveBeenCalledWith('/Users/you/docs');+ });++ it('no longer renders a directory input that cannot report a path', () => {+ const { container } = renderWithProviders(+ <KindFields+ kind="folder"+ path=""+ setPath={vi.fn()}+ glob=""+ setGlob={vi.fn()}+ url=""+ setUrl={vi.fn()}+ branch=""+ setBranch={vi.fn()}+ query=""+ setQuery={vi.fn()}+ selector=""+ setSelector={vi.fn()}+ connections={[]}+ loadingConnections={false}+ supportedToolkits={null}+ connectionId=""+ setConnection={vi.fn()}+ />+ );++ expect(container.querySelector('input[type="file"]')).toBeNull();+ expect(container.querySelector('[webkitdirectory]')).toBeNull();+ });+});diff --git a/app/src/components/intelligence/FolderField.tsx b/app/src/components/intelligence/FolderField.tsxnew file mode 100644index 0000000000..e68cf6dd06--- /dev/null+++ b/app/src/components/intelligence/FolderField.tsx@@ -0,0 +1,93 @@+/**+ * Path field for the `folder` memory-source kind, with a Browse button backed+ * by the OS-native directory chooser.+ *+ * Split out of `AddMemorySourceFields` for the same reason that file was split+ * out of the dialog: it is the only field with behaviour of its own, and the+ * reasoning below is most of what there is to say about it.+ *+ * Browse used to be an `<input type="file" webkitdirectory>`. That element+ * cannot report where the directory it returned actually lives - `File.path`+ * is an Electron extension no web engine implements, Wry's WKWebView,+ * WebView2 and WebKitGTK included - so its handler fell through to+ * `webkitRelativePath.split('/')[0]` and stored the directory's bare *name*.+ * The source then looked configured and failed every sync cycle, forever,+ * with `folder does not exist: docs` (#5831).+ *+ * The rule that replaces it: **never store a value that cannot resolve.**+ * When no absolute path can be obtained the field says so and stays as it+ * was, because a visible error is recoverable and a silently stored name is+ * not. Typing a path by hand is untouched, including a relative one - the+ * reader anchors those on the workspace at read time (tinymemory#113), which+ * is deliberately not something this field second-guesses.+ */+import debug from 'debug';+import { useState } from 'react';++import { useT } from '../../lib/i18n/I18nContext';+import { pickDirectoryNatively } from '../../utils/tauriCommands/directoryPicker';+import TextField from '../ui/TextField';++const log = debug('intelligence:folder-field');++export interface FolderFieldProps {+ label: string;+ value: string;+ onChange: (v: string) => void;+}++export function FolderField({ label, value, onChange }: FolderFieldProps) {+ const { t } = useT();+ const [pickError, setPickError] = useState<string | null>(null);++ const handleBrowse = async () => {+ const result = await pickDirectoryNatively();+ if (result.ok) {+ setPickError(null);+ onChange(result.path);+ return;+ }+ if (result.reason === 'cancelled') {+ // Dismissing the dialog is not a failure. Leave the field untouched and+ // clear any error from an earlier attempt.+ setPickError(null);+ return;+ }+ log('folder picker produced no absolute path (%s); refusing to store a name', result.reason);+ setPickError(t('memorySources.folderPathUnavailable'));+ };++ return (+ <label className="block">+ <span className="text-xs font-medium text-content-secondary">{label}</span>+ <div className="mt-1 flex gap-2">+ <TextField+ type="text"+ value={value}+ onChange={e => {+ setPickError(null);+ onChange(e.target.value);+ }}+ placeholder={t('memorySources.folderPathPlaceholder')}+ />+ <button+ type="button"+ onClick={handleBrowse}+ className="shrink-0 cursor-pointer rounded-md border border-line-strong bg-surface px-3 py-2+ text-xs font-medium text-content-secondary transition-colors+ hover:border-primary-400 hover:text-primary-600+ dark:bg-surface-muted dark:text-content-secondary+ dark:hover:border-primary-500 dark:hover:text-primary-400">+ {t('memorySources.browse')}+ </button>+ </div>+ {pickError && (+ <p role="alert" className="mt-1 text-xs leading-5 text-red-600 dark:text-red-300">+ {pickError}+ </p>+ )}+ </label>+ );+}++export default FolderField;diff --git a/app/src/lib/i18n/ar.ts b/app/src/lib/i18n/ar.tsindex 4fd15db18a..7ea57cd1ed 100644--- a/app/src/lib/i18n/ar.ts+++ b/app/src/lib/i18n/ar.ts@@ -2552,6 +2552,8 @@ const messages: TranslationMap = {'memorySources.comingSoon': 'قريباً','memorySources.composioListFailed': 'فشل في تحميل الأتصالات Xqx0x.','memorySources.browse': '(بروز)...',+ 'memorySources.folderPathUnavailable':+ 'تعذر تحديد موقع هذا المجلد. اكتب مساره الكامل بدلاً من ذلك.','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '**','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/bn.ts b/app/src/lib/i18n/bn.tsindex 5acd757da6..7f543f6d25 100644--- a/app/src/lib/i18n/bn.ts+++ b/app/src/lib/i18n/bn.ts@@ -2614,6 +2614,8 @@ const messages: TranslationMap = {'memorySources.comingSoon': 'শীঘ্রই আসছে','memorySources.composioListFailed': 'Xqxqx সংযোগ লোড করতে ব্যর্থ।','memorySources.browse': 'ব্রাউজ করুন...',+ 'memorySources.folderPathUnavailable':+ 'সেই ফোল্ডারটি কোথায় আছে তা নির্ধারণ করা যায়নি। এর পরিবর্তে এর সম্পূর্ণ পাথ টাইপ করুন।','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '*ড্যাম','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/de.ts b/app/src/lib/i18n/de.tsindex 9438086a0f..79fc44eaa3 100644--- a/app/src/lib/i18n/de.ts+++ b/app/src/lib/i18n/de.ts@@ -2689,6 +2689,8 @@ const messages: TranslationMap = {'memorySources.comingSoon': 'Demnächst','memorySources.composioListFailed': 'Fehler beim Laden der Composio-Verbindungen.','memorySources.browse': 'Durchsuchen…',+ 'memorySources.folderPathUnavailable':+ 'Der Speicherort dieses Ordners konnte nicht ermittelt werden. Geben Sie stattdessen den vollständigen Pfad ein.','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': 'Md. ','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/en.ts b/app/src/lib/i18n/en.tsindex d1c401de1e..a7085881ef 100644--- a/app/src/lib/i18n/en.ts+++ b/app/src/lib/i18n/en.ts@@ -2981,6 +2981,8 @@ const en: TranslationMap = {'memorySources.comingSoon': 'Coming soon','memorySources.composioListFailed': 'Failed to load Composio connections.','memorySources.browse': 'Browse…',+ 'memorySources.folderPathUnavailable':+ 'Could not determine where that folder is. Type its full path instead.','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '**/*.md','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/es.ts b/app/src/lib/i18n/es.tsindex 3e49414e13..ddab97025f 100644--- a/app/src/lib/i18n/es.ts+++ b/app/src/lib/i18n/es.ts@@ -2666,6 +2666,8 @@ const messages: TranslationMap = {'memorySources.comingSoon': 'Próximamente','memorySources.composioListFailed': 'Error al cargar las conexiones Composio.','memorySources.browse': 'Examinar…',+ 'memorySources.folderPathUnavailable':+ 'No se pudo determinar dónde está esa carpeta. Escribe su ruta completa en su lugar.','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '**/*.md','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/fr.ts b/app/src/lib/i18n/fr.tsindex 3a9ff89c9f..c1f5afc126 100644--- a/app/src/lib/i18n/fr.ts+++ b/app/src/lib/i18n/fr.ts@@ -2688,6 +2688,8 @@ const messages: TranslationMap = {'memorySources.comingSoon': 'Bientôt disponible','memorySources.composioListFailed': 'Échec du chargement des connexions Composio.','memorySources.browse': 'Parcourir…',+ 'memorySources.folderPathUnavailable':+ 'Impossible de déterminer où se trouve ce dossier. Saisissez plutôt son chemin complet.','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '**/*.md','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/hi.ts b/app/src/lib/i18n/hi.tsindex 3db5cf87b9..e359da3270 100644--- a/app/src/lib/i18n/hi.ts+++ b/app/src/lib/i18n/hi.ts@@ -2614,6 +2614,8 @@ const messages: TranslationMap = {'memorySources.comingSoon': 'जल्द आ रहा है','memorySources.composioListFailed': 'Composio कनेक्शन लोड करने में विफल रहा।','memorySources.browse': 'ब्राउज़ करें',+ 'memorySources.folderPathUnavailable':+ 'यह पता नहीं लगाया जा सका कि वह फ़ोल्डर कहाँ है। इसके बजाय उसका पूरा पथ टाइप करें।','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '**','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/id.ts b/app/src/lib/i18n/id.tsindex 4a76827d54..1ee21f220e 100644--- a/app/src/lib/i18n/id.ts+++ b/app/src/lib/i18n/id.ts@@ -2626,6 +2626,8 @@ const messages: TranslationMap = {'memorySources.comingSoon': 'Segera hadir','memorySources.composioListFailed': 'Gagal memuat koneksi Composio.','memorySources.browse': 'Jelajahi...',+ 'memorySources.folderPathUnavailable':+ 'Tidak dapat menentukan lokasi folder tersebut. Ketik jalur lengkapnya sebagai gantinya.','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '* * /*.md','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/it.ts b/app/src/lib/i18n/it.tsindex 1ccba3d6ed..2d00f123bb 100644--- a/app/src/lib/i18n/it.ts+++ b/app/src/lib/i18n/it.ts@@ -2664,6 +2664,8 @@ const messages: TranslationMap = {'memorySources.comingSoon': 'Prossimamente','memorySources.composioListFailed': 'Impossibile caricare le connessioni Composio.','memorySources.browse': 'Sfoglia…',+ 'memorySources.folderPathUnavailable':+ 'Impossibile determinare dove si trova quella cartella. Digita invece il suo percorso completo.','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '**/*.md','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/ko.ts b/app/src/lib/i18n/ko.tsindex a021a8eaf3..11d204369e 100644--- a/app/src/lib/i18n/ko.ts+++ b/app/src/lib/i18n/ko.ts@@ -2581,6 +2581,8 @@ const messages: TranslationMap = {'memorySources.comingSoon': '출시 예정','memorySources.composioListFailed': 'Composio 연결을 불러오지 못했습니다.','memorySources.browse': '찾아보기…',+ 'memorySources.folderPathUnavailable':+ '해당 폴더의 위치를 확인할 수 없습니다. 대신 전체 경로를 입력하세요.','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '**/*.md','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/pl.ts b/app/src/lib/i18n/pl.tsindex 4b9a2af6f7..a37d0d6def 100644--- a/app/src/lib/i18n/pl.ts+++ b/app/src/lib/i18n/pl.ts@@ -2645,6 +2645,8 @@ const messages: TranslationMap = {'memorySources.comingSoon': 'Wkrótce','memorySources.composioListFailed': 'Nie udało się wczytać połączeń Composio.','memorySources.browse': 'Przeglądaj…',+ 'memorySources.folderPathUnavailable':+ 'Nie udało się ustalić, gdzie znajduje się ten folder. Zamiast tego wpisz jego pełną ścieżkę.','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '**/*.md','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/pt.ts b/app/src/lib/i18n/pt.tsindex f24f22078a..a743dc50a3 100644--- a/app/src/lib/i18n/pt.ts+++ b/app/src/lib/i18n/pt.ts@@ -2662,6 +2662,8 @@ const messages: TranslationMap = {'memorySources.comingSoon': 'Em breve','memorySources.composioListFailed': 'Falha ao carregar as conexões Composio.','memorySources.browse': 'Navegar…',+ 'memorySources.folderPathUnavailable':+ 'Não foi possível determinar onde essa pasta está. Digite o caminho completo dela.','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '**/*.md','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/ru.ts b/app/src/lib/i18n/ru.tsindex 120a2a40ff..c0a305111d 100644--- a/app/src/lib/i18n/ru.ts+++ b/app/src/lib/i18n/ru.ts@@ -2633,6 +2633,8 @@ const messages: TranslationMap = {'memorySources.comingSoon': 'Скоро','memorySources.composioListFailed': 'Не удалось загрузить соединения Composio.','memorySources.browse': 'Просматривать…',+ 'memorySources.folderPathUnavailable':+ 'Не удалось определить, где находится эта папка. Введите полный путь к ней.','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '**/*.md','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/lib/i18n/zh-CN.ts b/app/src/lib/i18n/zh-CN.tsindex f0112e3a53..4d79ef7874 100644--- a/app/src/lib/i18n/zh-CN.ts+++ b/app/src/lib/i18n/zh-CN.ts@@ -2465,6 +2465,7 @@ const messages: TranslationMap = {'memorySources.comingSoon': '即将推出','memorySources.composioListFailed': '加载 Composio 连接失败。','memorySources.browse': '浏览…',+ 'memorySources.folderPathUnavailable': '无法确定该文件夹的位置。请改为输入其完整路径。','memorySources.folderPathPlaceholder': '/Users/you/notes','memorySources.globPatternPlaceholder': '**/*.md','memorySources.repoUrlPlaceholder': 'https://github.com/org/repo',diff --git a/app/src/utils/tauriCommands/directoryPicker.test.ts b/app/src/utils/tauriCommands/directoryPicker.test.tsnew file mode 100644index 0000000000..68a620431c--- /dev/null+++ b/app/src/utils/tauriCommands/directoryPicker.test.ts@@ -0,0 +1,70 @@+/**+ * Tests for the native directory chooser wrapper (#5831).+ *+ * The point of every case here is the same: a caller must be able to tell+ * "the user chose nothing" from "no path could be obtained", because only+ * the second one is allowed to surface an error, and neither is allowed to+ * produce a path the caller then stores.+ */+import { beforeEach, describe, expect, test, vi } from 'vitest';++import { isTauri, safeInvoke } from './common';+import { pickDirectoryNatively } from './directoryPicker';++vi.mock('./common', () => ({ isTauri: vi.fn(), safeInvoke: vi.fn() }));++describe('tauriCommands/directoryPicker', () => {+ beforeEach(() => {+ vi.mocked(safeInvoke).mockReset();+ vi.mocked(isTauri).mockReset();+ vi.mocked(isTauri).mockReturnValue(true);+ });++ test('reports unavailable without invoking when there is no host to ask', async () => {+ vi.mocked(isTauri).mockReturnValue(false);++ await expect(pickDirectoryNatively()).resolves.toEqual({ ok: false, reason: 'unavailable' });++ expect(safeInvoke).not.toHaveBeenCalled();+ });++ test('returns the absolute path the host chooser produced', async () => {+ vi.mocked(safeInvoke).mockResolvedValue('/Users/you/notes');++ await expect(pickDirectoryNatively()).resolves.toEqual({ ok: true, path: '/Users/you/notes' });++ expect(safeInvoke).toHaveBeenCalledWith('pick_directory_via_dialog');+ });++ test('treats a null result as a user cancellation, not a failure', async () => {+ vi.mocked(safeInvoke).mockResolvedValue(null);++ await expect(pickDirectoryNatively()).resolves.toEqual({ ok: false, reason: 'cancelled' });+ });++ test('treats an empty string as a cancellation rather than an empty path', async () => {+ vi.mocked(safeInvoke).mockResolvedValue('');++ await expect(pickDirectoryNatively()).resolves.toEqual({ ok: false, reason: 'cancelled' });+ });++ test('converts an invoke rejection into a failed result instead of throwing', async () => {+ vi.mocked(safeInvoke).mockRejectedValue(new Error('no chooser on this host'));++ await expect(pickDirectoryNatively()).resolves.toEqual({+ ok: false,+ reason: 'failed',+ message: 'no chooser on this host',+ });+ });++ test('carries a non-Error rejection through as a string message', async () => {+ vi.mocked(safeInvoke).mockRejectedValue('portal timed out');++ await expect(pickDirectoryNatively()).resolves.toEqual({+ ok: false,+ reason: 'failed',+ message: 'portal timed out',+ });+ });+});diff --git a/app/src/utils/tauriCommands/directoryPicker.ts b/app/src/utils/tauriCommands/directoryPicker.tsnew file mode 100644index 0000000000..78f3f3e14c--- /dev/null+++ b/app/src/utils/tauriCommands/directoryPicker.ts@@ -0,0 +1,52 @@+/**+ * Native directory chooser (#5831).+ *+ * The renderer cannot learn where a directory lives on its own. An+ * `<input type="file" webkitdirectory>` yields `File` objects, and a `File`+ * carries no filesystem location — `File.path` is an Electron extension that+ * Wry's WKWebView/WebView2/WebKitGTK do not implement. So the path has to+ * come from the host process, which is what+ * `directory_picker::pick_directory_via_dialog` provides.+ */+import { isTauri, safeInvoke } from './common';++export type DirectoryPickResult =+ /** The user chose a directory; `path` is absolute. */+ | { ok: true; path: string }+ /**+ * No path was obtained. Callers must NOT substitute a guess: storing a+ * value that cannot resolve is the defect #5831 describes, where a source+ * looked configured and failed once per sync cycle forever.+ *+ * - `cancelled` — the user dismissed the dialog. Leave the field alone.+ * - `unavailable` — no host to ask (a plain browser context, or the IPC+ * bridge is not wired yet).+ * - `failed` — the host tried and could not produce an absolute path.+ */+ | { ok: false; reason: 'cancelled' | 'unavailable' | 'failed'; message?: string };++/**+ * Open the OS-native directory chooser.+ *+ * Never throws: every failure mode is returned as a discriminated result so+ * the caller can decide what the user sees. `unavailable` and `failed` are+ * kept distinct because only the latter means the host actually tried.+ */+export async function pickDirectoryNatively(): Promise<DirectoryPickResult> {+ if (!isTauri()) {+ return { ok: false, reason: 'unavailable' };+ }+ try {+ const picked = await safeInvoke<string | null>('pick_directory_via_dialog');+ if (picked === null || picked === undefined || picked.length === 0) {+ return { ok: false, reason: 'cancelled' };+ }+ return { ok: true, path: picked };+ } catch (err) {+ return {+ ok: false,+ reason: 'failed',+ message: err instanceof Error ? err.message : String(err),+ };+ }+}diff --git a/app/src/utils/tauriCommands/index.ts b/app/src/utils/tauriCommands/index.tsindex cdb93a68f2..6c72819e6d 100644--- a/app/src/utils/tauriCommands/index.ts+++ b/app/src/utils/tauriCommands/index.ts@@ -17,3 +17,4 @@ export * from './service';export * from './voice';export * from './aboutApp';export * from './workspacePaths';+export * from './directoryPicker';