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): address review — no path in logs, reject non-UTF-8, stable analytics id
Shanu9c4b94a54edb
diff --git a/app/src-tauri/src/directory_picker.rs b/app/src-tauri/src/directory_picker.rsindex eed045fac0..baed8f1316 100644--- a/app/src-tauri/src/directory_picker.rs+++ b/app/src-tauri/src/directory_picker.rs@@ -32,15 +32,21 @@use std::path::Path;/// Render a chosen directory as the string the renderer will store, refusing-/// anything that is not absolute.+/// anything that cannot serve as a path.////// 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.+/// and a window server, but these two rules are the part worth pinning. Both+/// exist for the same reason — a value that reaches the store and cannot+/// resolve is the entire defect this command was written to remove, and an+/// error here is recoverable and visible where a stored bad path is neither.+///+/// - **Not absolute.** Belt-and-braces: the OS choosers all hand back+/// absolute paths, so this is not a branch we expect to take.+/// - **Not UTF-8.** This one is reachable. A Unix directory name is bytes,+/// not text, and `Path::display()` would substitute U+FFFD for anything+/// that is not valid UTF-8 and hand back the corrupted result as a+/// success — recreating the failing-sync behaviour by a different route.+/// `to_str()` refuses instead.fn absolute_path_string(path: &Path) -> Result<String, String> {if !path.is_absolute() {return Err(format!(@@ -48,7 +54,12 @@ fn absolute_path_string(path: &Path) -> Result<String, String> {path.display()));}- Ok(path.display().to_string())+ // The lossy rendering is deliberately not echoed back here: it would be+ // mangled by definition, and a directory path carries the user's login+ // name (see the logging note in `pick_directory_via_dialog`).+ path.to_str()+ .map(str::to_owned)+ .ok_or_else(|| "the directory chooser returned a path that is not valid UTF-8".to_string())}/// Open the OS-native directory chooser and return the absolute path of the@@ -58,8 +69,9 @@ fn absolute_path_string(path: &Path) -> Result<String, String> {/// - `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.+/// - `Err(_)` — the dialog could not run, or it yielded something that cannot+/// serve as a path (see [`absolute_path_string`]). 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@@ -68,12 +80,19 @@ pub async fn pick_directory_via_dialog() -> Result<Option<String>, String> {let handle = rfd::AsyncFileDialog::new().pick_folder().await;let Some(dir) = handle else {- log::info!("[directory_picker] pick_directory_via_dialog cancelled by user");+ log::debug!("[directory_picker] pick_directory_via_dialog cancelled by user");return Ok(None);};+ // The chosen path is deliberately NOT logged. An absolute directory path+ // carries the user's login name and their private folder names, and these+ // logs are written to the daily support log that users are asked to share+ // (AGENTS.md: "Never log secrets or full PII"). The component depth is+ // enough to tell a cancel from a pick and a shallow choice from a deep one+ // without naming anything. Do not "improve" this by adding the path back.+ let depth = dir.path().components().count();let picked = absolute_path_string(dir.path())?;- log::info!("[directory_picker] pick_directory_via_dialog chose {picked}");+ log::debug!("[directory_picker] pick_directory_via_dialog chose a directory (depth={depth})");Ok(Some(picked))}@@ -108,4 +127,27 @@ mod tests {fn refuses_a_relative_path_with_separators() {assert!(absolute_path_string(Path::new("notes/inner")).is_err());}++ /// A Unix directory name is bytes, not text. `Path::display()` would have+ /// substituted U+FFFD here and returned the corrupted string as a+ /// success, which is the #5831 failure mode reached by another route.+ #[cfg(unix)]+ #[test]+ fn refuses_an_absolute_path_that_is_not_utf8() {+ use std::ffi::OsStr;+ use std::os::unix::ffi::OsStrExt;++ let raw = OsStr::from_bytes(b"/Users/you/\xff\xfenotes");+ let path = Path::new(raw);+ assert!(path.is_absolute(), "fixture must clear the absolute check");++ let err = absolute_path_string(path).unwrap_err();+ assert!(err.contains("not valid UTF-8"), "unexpected message: {err}");+ // The mangled rendering must not be echoed back — it is both useless+ // and carries the user's login name.+ assert!(+ !err.contains('\u{FFFD}'),+ "lossy path leaked into the error"+ );+ }}diff --git a/app/src/components/intelligence/FolderField.test.tsx b/app/src/components/intelligence/FolderField.test.tsxindex 453ace2ffa..f186fe94c7 100644--- a/app/src/components/intelligence/FolderField.test.tsx+++ b/app/src/components/intelligence/FolderField.test.tsx@@ -140,4 +140,14 @@ describe('FolderField (folder memory source)', () => {expect(container.querySelector('input[type="file"]')).toBeNull();expect(container.querySelector('[webkitdirectory]')).toBeNull();});++ it('gives Browse a stable analytics id rather than a DOM-order fallback', () => {+ mockPick.mockResolvedValue({ ok: false, reason: 'cancelled' });+ renderFolderFields();++ expect(screen.getByRole('button', { name: /browse/i })).toHaveAttribute(+ 'data-analytics-id',+ 'brain-sources-folder-browse'+ );+ });});diff --git a/app/src/components/intelligence/FolderField.tsx b/app/src/components/intelligence/FolderField.tsxindex e68cf6dd06..87ece21ccd 100644--- a/app/src/components/intelligence/FolderField.tsx+++ b/app/src/components/intelligence/FolderField.tsx@@ -26,6 +26,7 @@ import { useState } from 'react';import { useT } from '../../lib/i18n/I18nContext';import { pickDirectoryNatively } from '../../utils/tauriCommands/directoryPicker';+import Button from '../ui/Button';import TextField from '../ui/TextField';const log = debug('intelligence:folder-field');@@ -70,16 +71,15 @@ export function FolderField({ label, value, onChange }: FolderFieldProps) {}}placeholder={t('memorySources.folderPathPlaceholder')}/>- <button+ <Buttontype="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">+ variant="secondary"+ size="sm"+ className="shrink-0"+ analyticsId="brain-sources-folder-browse"+ onClick={handleBrowse}>{t('memorySources.browse')}- </button>+ </Button></div>{pickError && (<p role="alert" className="mt-1 text-xs leading-5 text-red-600 dark:text-red-300">