The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
feat(rea): say which Ghidra REA gets and whether this Mac has its decompiler
purplecdbe2e9a89ae
diff --git a/docs/guide/agent/index.html b/docs/guide/agent/index.htmlindex 6bcb2279..20262f2c 100644--- a/docs/guide/agent/index.html+++ b/docs/guide/agent/index.html@@ -15,7 +15,7 @@<meta property="og:image" content="https://locallyuncensored.com/social-preview.png"><meta name="twitter:card" content="summary_large_image"><script type="application/ld+json">-{"@context":"https://schema.org","@type":"TechArticle","headline":"Agent Mode in Locally Uncensored: Tools, Workspace Folder, Approvals, Stop","description":"How agent mode works in Locally Uncensored: the tools, the workspace folder and the sandbox, permissions and approvals, Stop, background agents and loops.","url":"https://locallyuncensored.com/guide/agent/","dateModified":"2026-09-11","inLanguage":"en","author":{"@type":"Person","name":"PurpleDoubleD","url":"https://github.com/PurpleDoubleD"},"publisher":{"@type":"Organization","name":"Locally Uncensored","url":"https://locallyuncensored.com/"},"mainEntityOfPage":{"@type":"WebPage","@id":"https://locallyuncensored.com/guide/agent/"},"isPartOf":{"@type":"WebPage","name":"Locally Uncensored Handbook: Install, Chat, Agent, Code, Create, Cloud","url":"https://locallyuncensored.com/guide/"},"about":{"@type":"SoftwareApplication","name":"Locally Uncensored","operatingSystem":"Windows, Linux, macOS","applicationCategory":"UtilitiesApplication"}}+{"@context":"https://schema.org","@type":"TechArticle","headline":"Agent Mode in Locally Uncensored: Tools, Workspace Folder, Approvals, Stop","description":"How agent mode works in Locally Uncensored: the tools, the workspace folder and the sandbox, permissions and approvals, Stop, background agents and loops.","url":"https://locallyuncensored.com/guide/agent/","dateModified":"2026-10-28","inLanguage":"en","author":{"@type":"Person","name":"PurpleDoubleD","url":"https://github.com/PurpleDoubleD"},"publisher":{"@type":"Organization","name":"Locally Uncensored","url":"https://locallyuncensored.com/"},"mainEntityOfPage":{"@type":"WebPage","@id":"https://locallyuncensored.com/guide/agent/"},"isPartOf":{"@type":"WebPage","name":"Locally Uncensored Handbook: Install, Chat, Agent, Code, Create, Cloud","url":"https://locallyuncensored.com/guide/"},"about":{"@type":"SoftwareApplication","name":"Locally Uncensored","operatingSystem":"Windows, Linux, macOS","applicationCategory":"UtilitiesApplication"}}</script><link rel="icon" href="/favicon.png"><script type="application/ld+json">@@ -64,6 +64,7 @@<a href="#approvals">Permissions and approvals</a><a href="#stop">Stop, background agents and loops</a><a href="#mcp">MCP servers and workflows</a>+<a href="#rea-ghidra">REA and Ghidra on a Mac</a><a href="#wrong">When it goes wrong</a></nav>@@ -146,8 +147,25 @@<p>MCP is a standard that lets you plug an outside tool server into the agent. Settings, Agent, MCP Servers adds one with a name and a command; the field is labelled "Command (only npx or uvx)", because the app starts servers only through those two launchers. The server's tools then appear next to the built in ones.</p>+<p>A server started with uvx needs uv, Astral's Python tool runner. Install it from the official instructions at <a href="https://docs.astral.sh/uv/getting-started/installation/">docs.astral.sh/uv</a>; on Windows the quickest is <code>winget install --id=astral-sh.uv -e</code>, on a Mac <code>brew install uv</code>. uv puts <code>uvx</code> into <code>~/.local/bin</code> (Windows: <code>%USERPROFILE%\.local\bin\uvx.exe</code>). Quit and reopen LU afterwards so it sees the new PATH; on Windows LU also finds uvx in that folder without it. To try it, add a server with the command <code>uvx</code> and the argument <code>mcp-server-time==2026.8.18</code>: it answers with two tools, get_current_time and convert_time. If uv is missing, the server row says "`uvx` was not found" and links the installation page.</p>+<p>Agent Workflows, under the same settings tab, are saved sequences the agent can run with run_workflow.</p>+<h2 id="rea-ghidra">REA and Ghidra on a Mac</h2>++<p>REA (Plugins, REA) takes apart apps and files for Agent and Code. For native programs it uses Ghidra, which you install yourself; LU installs none of it. REA 6.5.0 is made for Ghidra 12.1.4. Download it only from the official release on <a href="https://github.com/NationalSecurityAgency/ghidra/releases">github.com/NationalSecurityAgency/ghidra</a> and compare the SHA-256 the release lists. Ghidra needs a JDK 21 or newer.</p>++<p>The official download has no decompiler for a Mac. Ghidra ships its native decompiler for Windows and Linux on x86-64 only, and asks everyone on macOS (Apple Silicon and Intel) and Linux ARM to build it once. Without it every decompile ends with "executable_missing" and a path ending in <code>os/mac_arm_64/decompile</code>. With REA switched on, the plugin row now says which Ghidra LU found and whether its decompiler is there. To build it, following Ghidra's own Getting Started:</p>++<ol>+<li>Install the Command Line Tools for Xcode: <code>xcode-select --install</code> (or Xcode from the App Store).</li>+<li>Install Gradle 8.5 or newer, for example <code>brew install gradle</code>, and a JDK 21 or newer, for example <code>brew install openjdk@21</code>.</li>+<li>In Terminal: <code>cd ~/ghidra_12.1.4_PUBLIC/support/gradle</code> (your Ghidra folder), then <code>gradle buildNatives</code>. It takes about a minute. The decompiler lands in <code>Ghidra/Features/Decompiler/build/os/mac_arm_64/</code>, which Ghidra prefers over the shipped folder.</li>+<li>Switch REA off and on. The row should read "decompiler ready".</li>+</ol>++<p>LU finds Ghidra through <code>GHIDRA_INSTALL_DIR</code>, a <code>ghidraRun</code> on the PATH (Homebrew's cask puts one in <code>/opt/homebrew/bin</code>), or a folder named <code>ghidra…</code> in your home folder, <code>~/Applications</code> or <code>/Applications</code>. A Ghidra it finds in such a folder is handed to REA, so a Finder start works without a terminal. Desktop, Documents and Downloads are not searched, because macOS would ask for permission each time; move Ghidra out of there or set <code>GHIDRA_INSTALL_DIR</code>.</p>+<h2 id="wrong">When it goes wrong</h2><p><strong>The "Agent" button is greyed out.</strong> Tooltip "This model is not agent-compatible". Pick a model that the Models tab marks with the tools icon, or switch to Cloud.</p>diff --git a/src-tauri/src/commands/plugin_rea.rs b/src-tauri/src/commands/plugin_rea.rsindex b31ecb99..074df77f 100644--- a/src-tauri/src/commands/plugin_rea.rs+++ b/src-tauri/src/commands/plugin_rea.rs@@ -280,11 +280,172 @@ pub fn keep_tarball(dir: &Path, bytes: &[u8]) -> Result<PathBuf, String> {Ok(target)}+// ── Ghidra, and its decompiler on this machine ─────────────────────────────+//+// REA uses a Ghidra the user installed (LU installs none) and finds it through+// GHIDRA_INSTALL_DIR or a `ghidra`/`ghidraRun` launcher on the PATH. Two+// things went wrong on a Mac (B11, A37 run 27.10.2026):+//+// 1. The official Ghidra download carries its native decompiler only for+// Windows and Linux x86-64. On Apple Silicon (and Intel Macs, Linux ARM)+// Ghidra's own "Getting Started" says to build it once with+// `support/gradle` + `gradle buildNatives`. Without that, REA answers every+// decompile with `executable_missing … os/mac_arm_64/decompile` and the+// user reads it as REA being broken.+// 2. A Mac app started from the Finder has neither GHIDRA_INSTALL_DIR nor a+// terminal's PATH, so a Ghidra unpacked into the home folder was not found+// at all.+//+// LU now looks for the install, says whether its decompiler is there, and+// hands REA the folder it found. It builds nothing and downloads nothing: the+// build is the user's step, in Terminal, with Ghidra's own instructions.++/// The version REA 6.5.0 is validated against (`SUPPORTED_GHIDRA_VERSION`).+pub const GHIDRA_FOR_REA: &str = "12.1.4";++/// Ghidra's folder name for this machine's native tools, as REA and Ghidra+/// name them (`Ghidra/Features/Decompiler/os/<dir>`).+pub fn ghidra_native_dir() -> Option<&'static str> {+ if cfg!(all(target_os = "macos", target_arch = "aarch64")) {+ Some("mac_arm_64")+ } else if cfg!(all(target_os = "macos", target_arch = "x86_64")) {+ Some("mac_x86_64")+ } else if cfg!(all(target_os = "linux", target_arch = "x86_64")) {+ Some("linux_x86_64")+ } else if cfg!(all(target_os = "linux", target_arch = "aarch64")) {+ Some("linux_arm_64")+ } else if cfg!(windows) {+ // Windows on ARM runs the x86-64 build under emulation (Ghidra docs).+ Some("win_x86_64")+ } else {+ None+ }+}++const DECOMPILER_EXE: &str = if cfg!(windows) { "decompile.exe" } else { "decompile" };++/// A folder is a Ghidra install when it has the two files REA checks first.+fn is_ghidra_root(dir: &Path) -> bool {+ let headless = if cfg!(windows) { "analyzeHeadless.bat" } else { "analyzeHeadless" };+ dir.join("Ghidra").join("application.properties").is_file() && dir.join("support").join(headless).is_file()+}++/// `application.version` from `Ghidra/application.properties`.+pub fn ghidra_version(root: &Path) -> Option<String> {+ let raw = std::fs::read_to_string(root.join("Ghidra").join("application.properties")).ok()?;+ raw.lines().find_map(|l| {+ let (k, v) = l.split_once('=')?;+ (k.trim() == "application.version").then(|| v.trim().to_string())+ })+}++/// The decompiler Ghidra will use, built (`build/os`) before shipped (`os`),+/// the order Ghidra and REA prefer.+pub fn ghidra_decompiler(root: &Path, native_dir: &str) -> Option<PathBuf> {+ let base = root.join("Ghidra").join("Features").join("Decompiler");+ [base.join("build").join("os").join(native_dir), base.join("os").join(native_dir)]+ .into_iter()+ .map(|d| d.join(DECOMPILER_EXE))+ .find(|p| p.is_file())+}++/// Folders a Ghidra is unpacked into without a terminal's help. Not Desktop,+/// Documents or Downloads: on a Mac the first touch of each asks the user for+/// permission (see `find_comfyui_path`), and a status poll must not do that.+fn ghidra_search_dirs(home: &Path) -> Vec<PathBuf> {+ let mut dirs = vec![home.to_path_buf(), home.join("Applications"), home.join("tools"), home.join("opt")];+ if cfg!(target_os = "macos") {+ dirs.push(PathBuf::from("/Applications"));+ // Homebrew's cask keeps the unpacked release one level down.+ for cask in ["/opt/homebrew/Caskroom/ghidra", "/usr/local/Caskroom/ghidra"] {+ if let Ok(rd) = std::fs::read_dir(cask) {+ dirs.extend(rd.flatten().map(|e| e.path()));+ }+ }+ } else if cfg!(windows) {+ dirs.push(PathBuf::from("C:\\ghidra"));+ dirs.push(PathBuf::from("C:\\Program Files"));+ } else {+ dirs.push(PathBuf::from("/opt"));+ dirs.push(PathBuf::from("/usr/share"));+ }+ dirs+}++/// Where the Ghidra REA will use is, and how LU found it.+///+/// The order is REA's own: an explicit GHIDRA_INSTALL_DIR wins even when it+/// is wrong (REA does not look further either), then a launcher on the PATH+/// REA gets, then the fixed folders, newest version first.+pub fn find_ghidra(env_dir: Option<&str>, path: Option<&str>, search: &[PathBuf]) -> Option<(PathBuf, &'static str)> {+ if let Some(d) = env_dir.map(str::trim).filter(|d| !d.is_empty()) {+ return Some((PathBuf::from(d), "env"));+ }+ if let Some(path) = path {+ let launchers: &[&str] = if cfg!(windows) { &["ghidraRun.bat", "ghidra.bat"] } else { &["ghidraRun", "ghidra"] };+ for dir in std::env::split_paths(path) {+ for l in launchers {+ if let Ok(real) = std::fs::canonicalize(dir.join(l)) {+ if let Some(root) = real.parent().filter(|r| is_ghidra_root(r)) {+ return Some((root.to_path_buf(), "path"));+ }+ }+ }+ }+ }+ let mut found: Vec<PathBuf> = search+ .iter()+ .filter_map(|d| std::fs::read_dir(d).ok())+ .flat_map(|rd| rd.flatten().map(|e| e.path()))+ .filter(|p| {+ p.file_name().and_then(|n| n.to_str()).is_some_and(|n| n.to_ascii_lowercase().starts_with("ghidra"))+ && is_ghidra_root(p)+ })+ .collect();+ found.sort_by_key(|p| std::cmp::Reverse(ghidra_version(p).map(|v| version_triple(&v))));+ found.into_iter().next().map(|p| (p, "folder"))+}++fn version_triple(v: &str) -> (u32, u32, u32) {+ let mut it = v.split(|c: char| !c.is_ascii_digit()).filter(|s| !s.is_empty()).map(|s| s.parse().unwrap_or(0));+ (it.next().unwrap_or(0), it.next().unwrap_or(0), it.next().unwrap_or(0))+}++/// What the plugin row says about Ghidra. `null` fields where nothing was+/// found; `needsNatives` is the Apple Silicon case B11 is about.+pub fn ghidra_status_in(found: Option<(PathBuf, &'static str)>, native_dir: Option<&str>) -> Value {+ let Some((root, how)) = found else {+ return json!({ "found": false, "nativeDir": native_dir, "wantVersion": GHIDRA_FOR_REA });+ };+ let complete = is_ghidra_root(&root);+ let decompiler = native_dir.and_then(|n| ghidra_decompiler(&root, n));+ json!({+ "found": complete,+ "installDir": root.to_string_lossy(),+ "foundBy": how,+ "version": ghidra_version(&root),+ "wantVersion": GHIDRA_FOR_REA,+ "nativeDir": native_dir,+ "decompiler": decompiler.as_ref().map(|p| p.to_string_lossy().into_owned()),+ "needsNatives": complete && decompiler.is_none(),+ "buildDir": root.join("support").join("gradle").to_string_lossy(),+ })+}++fn ghidra_status(path: Option<&str>) -> Value {+ let env_dir = std::env::var("GHIDRA_INSTALL_DIR").ok();+ let home = crate::os_paths::home();+ ghidra_status_in(find_ghidra(env_dir.as_deref(), path, &ghidra_search_dirs(&home)), ghidra_native_dir())+}+#[tauri::command]pub async fn plugin_rea_status() -> Result<Value, String> {tokio::task::spawn_blocking(|| {let (path, node) = path_and_node(child_path(), &crate::os_paths::home());- status_in(&plugin_dir(&crate::os_paths::data_dir()), path, node)+ let ghidra = ghidra_status(path.as_deref().or(std::env::var("PATH").ok().as_deref()));+ let mut status = status_in(&plugin_dir(&crate::os_paths::data_dir()), path, node);+ status["ghidra"] = ghidra;+ status}).await.map_err(|e| e.to_string())@@ -514,6 +675,93 @@ mod tests {}}+ /// A Ghidra tree as the official zip unpacks it, with or without the+ /// decompiler for `native`.+ fn fake_ghidra(parent: &Path, name: &str, version: &str, native: Option<&str>) -> PathBuf {+ let root = parent.join(name);+ std::fs::create_dir_all(root.join("Ghidra")).unwrap();+ std::fs::create_dir_all(root.join("support")).unwrap();+ std::fs::write(root.join("Ghidra/application.properties"), format!("application.name=Ghidra\napplication.version={version}\n")).unwrap();+ let headless = if cfg!(windows) { "analyzeHeadless.bat" } else { "analyzeHeadless" };+ std::fs::write(root.join("support").join(headless), b"#!/bin/sh\n").unwrap();+ if let Some(n) = native {+ let d = root.join("Ghidra/Features/Decompiler/os").join(n);+ std::fs::create_dir_all(&d).unwrap();+ std::fs::write(d.join(DECOMPILER_EXE), b"x").unwrap();+ }+ root+ }++ /// B11: the official zip on Apple Silicon. It has linux_x86_64 and+ /// win_x86_64 and nothing for mac_arm_64; the row has to say so.+ #[test]+ fn a_ghidra_without_this_machines_decompiler_needs_natives() {+ let home = temp();+ let root = fake_ghidra(&home, "ghidra_12.1.4_PUBLIC", "12.1.4", Some("linux_x86_64"));+ let s = ghidra_status_in(find_ghidra(None, None, std::slice::from_ref(&home)), Some("mac_arm_64"));+ assert_eq!(s["found"], true);+ assert_eq!(s["foundBy"], "folder");+ assert_eq!(s["version"], "12.1.4");+ assert_eq!(s["needsNatives"], true);+ assert!(s["decompiler"].is_null());+ assert_eq!(s["buildDir"], root.join("support").join("gradle").to_string_lossy().as_ref());+ }++ /// After `gradle buildNatives` the decompiler sits under build/os, which+ /// Ghidra prefers over os/.+ #[test]+ fn a_built_decompiler_counts() {+ let home = temp();+ let root = fake_ghidra(&home, "ghidra_12.1.4_PUBLIC", "12.1.4", None);+ let built = root.join("Ghidra/Features/Decompiler/build/os/mac_arm_64");+ std::fs::create_dir_all(&built).unwrap();+ std::fs::write(built.join(DECOMPILER_EXE), b"x").unwrap();+ let s = ghidra_status_in(find_ghidra(None, None, &[home]), Some("mac_arm_64"));+ assert_eq!(s["needsNatives"], false);+ assert!(s["decompiler"].as_str().unwrap().contains("build"));+ }++ #[test]+ fn the_newest_ghidra_in_a_folder_wins_and_an_explicit_dir_wins_over_all() {+ let home = temp();+ fake_ghidra(&home, "ghidra_11.4_PUBLIC", "11.4", None);+ fake_ghidra(&home, "ghidra_12.1.4_PUBLIC", "12.1.4", None);+ fake_ghidra(&home, "not-ghidra", "99.0", None);+ let (root, how) = find_ghidra(None, None, std::slice::from_ref(&home)).unwrap();+ assert!(root.ends_with("ghidra_12.1.4_PUBLIC"));+ assert_eq!(how, "folder");+ let (root, how) = find_ghidra(Some("/somewhere/else"), None, &[home]).unwrap();+ assert_eq!((root, how), (PathBuf::from("/somewhere/else"), "env"));+ }++ #[cfg(unix)]+ #[test]+ fn a_launcher_on_the_path_leads_to_its_install() {+ // Homebrew's cask: /opt/homebrew/bin/ghidraRun is a link into the tree.+ let home = temp();+ let root = fake_ghidra(&home, "ghidra_12.1.4_PUBLIC", "12.1.4", None);+ std::fs::write(root.join("ghidraRun"), b"#!/bin/sh\n").unwrap();+ let bin = home.join("bin");+ std::fs::create_dir_all(&bin).unwrap();+ std::os::unix::fs::symlink(root.join("ghidraRun"), bin.join("ghidraRun")).unwrap();+ let (found, how) = find_ghidra(None, Some(&bin.to_string_lossy()), &[]).unwrap();+ assert_eq!(how, "path");+ assert_eq!(std::fs::canonicalize(found).unwrap(), std::fs::canonicalize(root).unwrap());+ }++ #[test]+ fn no_ghidra_is_a_plain_not_found() {+ let s = ghidra_status_in(find_ghidra(None, None, &[temp()]), Some("mac_arm_64"));+ assert_eq!(s["found"], false);+ assert!(s.get("needsNatives").is_none());+ }++ #[cfg(all(target_os = "macos", target_arch = "aarch64"))]+ #[test]+ fn this_mac_looks_for_mac_arm_64() {+ assert_eq!(ghidra_native_dir(), Some("mac_arm_64"));+ }+#[test]fn the_status_names_the_folder_the_path_and_the_node() {let dir = temp();diff --git a/src/components/chat/ReaPluginRow.tsx b/src/components/chat/ReaPluginRow.tsxindex 658ecb16..cb793548 100644--- a/src/components/chat/ReaPluginRow.tsx+++ b/src/components/chat/ReaPluginRow.tsx@@ -6,7 +6,7 @@import { Microscope } from 'lucide-react'import { useSettingsStore } from '../../stores/settingsStore'import { useReaRuntime } from '../../lib/plugins/rea-runtime'-import { REA_PLUGIN, REA_TOOLS_NOTE } from '../../lib/plugins/rea'+import { REA_PLUGIN, REA_TOOLS_NOTE, reaGhidraLine } from '../../lib/plugins/rea'import { HINWEIS_TEXT } from '../../lib/hinweis'/** The line under the switch for the step a start is at. */@@ -23,8 +23,10 @@ export function reaPhaseLine(phase: string, tools: number, error: string | null)export function ReaPluginRow() {const enabled = useSettingsStore((s) => s.settings.reaPluginEnabled === true)const updateSettings = useSettingsStore((s) => s.updateSettings)- const { phase, tools, error } = useReaRuntime()+ const { phase, tools, error, ghidra } = useReaRuntime()const line = enabled ? reaPhaseLine(phase, tools, error) : null+ // Only once REA runs: before that the row has its own step to tell.+ const ghidraLine = enabled && phase === 'on' ? reaGhidraLine(ghidra) : nullreturn (<div className="px-2.5" data-testid="plugins-rea"><div className="w-full flex items-center justify-between py-1.5 gap-2">@@ -57,6 +59,14 @@ export function ReaPluginRow() {{line}</div>)}+ {ghidraLine && (+ <div+ data-testid="plugins-rea-ghidra"+ className={`pb-1.5 t-micro leading-snug break-words ${ghidra?.needsNatives ? HINWEIS_TEXT.fehler : HINWEIS_TEXT.ruhig}`}+ >+ {ghidraLine}+ </div>+ )}</div>)}diff --git a/src/components/chat/__tests__/rea-says-what-ghidra-lacks.test.tsx b/src/components/chat/__tests__/rea-says-what-ghidra-lacks.test.tsxnew file mode 100644index 00000000..753a6792--- /dev/null+++ b/src/components/chat/__tests__/rea-says-what-ghidra-lacks.test.tsx@@ -0,0 +1,82 @@+/**+ * @vitest-environment jsdom+ *+ * B11: REA on Apple Silicon. The official Ghidra download carries its native+ * decompiler only for Windows and Linux x86-64; on a Mac every decompile ended+ * in `executable_missing … os/mac_arm_64/decompile`, and nothing in LU said+ * why. The row now names the Ghidra it found and, where the decompiler for+ * this machine is missing, the one build step Ghidra's own guide gives. And a+ * Ghidra LU found in a folder reaches REA, which a Finder start would not.+ *+ * Run: npx vitest run src/components/chat/__tests__/rea-says-what-ghidra-lacks.test.tsx+ */+import { describe, it, expect, afterEach, beforeEach } from 'vitest'+import { cleanup, render, screen, act } from '@testing-library/react'+import { ReaPluginRow } from '../ReaPluginRow'+import { useSettingsStore } from '../../../stores/settingsStore'+import { useReaRuntime } from '../../../lib/plugins/rea-runtime'+import { reaGhidraLine, reaServerConfig, type ReaGhidra, type ReaStatus } from '../../../lib/plugins/rea'++const macOhneDecompiler: ReaGhidra = {+ found: true,+ installDir: '/Users/x/ghidra_12.1.4_PUBLIC',+ foundBy: 'folder',+ version: '12.1.4',+ wantVersion: '12.1.4',+ nativeDir: 'mac_arm_64',+ decompiler: null,+ needsNatives: true,+ buildDir: '/Users/x/ghidra_12.1.4_PUBLIC/support/gradle',+}++const ready: ReaStatus = {+ version: '6.5.0', ready: true, tarball: '/d/rea.tgz', workDir: '/d/work', path: '/usr/bin',+ node: 'v24.11.0', nodeOk: true, nodeRange: 'x', ghidra: macOhneDecompiler,+}++beforeEach(() => {+ useSettingsStore.getState().updateSettings({ reaPluginEnabled: true })+ useReaRuntime.setState({ phase: 'off', tools: 0, error: null, ghidra: null })+})+afterEach(() => cleanup())++describe('what the REA row says about Ghidra', () => {+ it('a Ghidra without this Mac\'s decompiler gets the build step, in the row', () => {+ render(<ReaPluginRow />)+ act(() => { useReaRuntime.setState({ phase: 'on', tools: 207, ghidra: macOhneDecompiler }) })+ const line = screen.getByTestId('plugins-rea-ghidra').textContent ?? ''+ expect(line).toContain('no decompiler for this computer (mac_arm_64)')+ expect(line).toContain('cd "/Users/x/ghidra_12.1.4_PUBLIC/support/gradle" && gradle buildNatives')+ expect(line).toContain('xcode-select --install')+ })++ it('a ready one says so, and a wrong version is named', () => {+ const ok = { ...macOhneDecompiler, needsNatives: false, decompiler: '/x/decompile' }+ expect(reaGhidraLine(ok)).toMatch(/decompiler ready\.$/)+ expect(reaGhidraLine({ ...ok, version: '11.4' })).toContain('REA is made for Ghidra 12.1.4')+ })++ it('none found points at the official release, and an old Rust side says nothing', () => {+ expect(reaGhidraLine({ found: false, wantVersion: '12.1.4', nativeDir: 'mac_arm_64' })).toMatch(/Ghidra not found.*official GitHub release/)+ expect(reaGhidraLine(undefined)).toBeNull()+ })++ it('nothing about Ghidra before REA runs', () => {+ render(<ReaPluginRow />)+ act(() => { useReaRuntime.setState({ phase: 'starting', ghidra: macOhneDecompiler }) })+ expect(screen.queryByTestId('plugins-rea-ghidra')).toBeNull()+ })+})++describe('the Ghidra LU found reaches REA', () => {+ it('found in a folder: handed over as GHIDRA_INSTALL_DIR', () => {+ expect(reaServerConfig(ready).env?.GHIDRA_INSTALL_DIR).toBe('/Users/x/ghidra_12.1.4_PUBLIC')+ })++ it('found by the user\'s own variable or PATH: left to REA', () => {+ for (const foundBy of ['env', 'path'] as const) {+ const s = { ...ready, ghidra: { ...macOhneDecompiler, foundBy } }+ expect(reaServerConfig(s).env?.GHIDRA_INSTALL_DIR).toBeUndefined()+ }+ })+})diff --git a/src/lib/plugins/rea-runtime.ts b/src/lib/plugins/rea-runtime.tsindex 4f7ba0ab..6d6827a6 100644--- a/src/lib/plugins/rea-runtime.ts+++ b/src/lib/plugins/rea-runtime.ts@@ -7,7 +7,7 @@ import { create } from 'zustand'import { toolRegistry } from '../../api/mcp/tool-registry'import type { MCPExternalClient } from '../../api/mcp/external-client'import { isTauri } from '../../api/backend'-import { REA_PLUGIN, reaFetch, reaGuard, reaServerConfig, reaStatus } from './rea'+import { REA_PLUGIN, reaFetch, reaGuard, reaServerConfig, reaStatus, type ReaGhidra } from './rea'import { reaArgsFromModel, reaResultForModel, reaToolForModel } from './rea-model'export type ReaPhase = 'off' | 'fetching' | 'starting' | 'on' | 'error'@@ -17,9 +17,11 @@ interface ReaRuntimeState {/** How many tools REA gave the agents. */tools: numbererror: string | null+ /** What the last status said about Ghidra (B11), for the row. */+ ghidra?: ReaGhidra | null}-export const useReaRuntime = create<ReaRuntimeState>(() => ({ phase: 'off', tools: 0, error: null }))+export const useReaRuntime = create<ReaRuntimeState>(() => ({ phase: 'off', tools: 0, error: null, ghidra: null }))let client: MCPExternalClient | null = null@@ -51,6 +53,7 @@ export async function startRea(): Promise<void> {status = await reaStatus()if (mine !== turn) return}+ set({ ghidra: status.ghidra ?? null })const config = reaServerConfig(status)set({ phase: 'starting' })const { MCPExternalClient } = await import('../../api/mcp/external-client')diff --git a/src/lib/plugins/rea.ts b/src/lib/plugins/rea.tsindex ec59ab16..26b6860b 100644--- a/src/lib/plugins/rea.ts+++ b/src/lib/plugins/rea.ts@@ -45,6 +45,55 @@ export const REA_TOOLS_NOTE =+ 'It works best with a model of about 27B and a context window of 64K or more; smaller ones often stop before an answer. '+ 'Use it on software you own or are allowed to examine.'+/**+ * What LU found of Ghidra (commands/plugin_rea.rs, `ghidra_status_in`).+ *+ * REA uses a Ghidra the user installed. On a Mac the official download has no+ * decompiler for the machine (B11): Ghidra ships it for Windows and Linux+ * x86-64 only and asks everyone else to build it once.+ */+export interface ReaGhidra {+ found: boolean+ installDir?: string+ /** env: GHIDRA_INSTALL_DIR, path: a launcher on the PATH, folder: LU's search. */+ foundBy?: 'env' | 'path' | 'folder'+ version?: string | null+ /** The Ghidra version REA is validated against. */+ wantVersion: string+ /** Ghidra's name for this machine's native tools, e.g. mac_arm_64. */+ nativeDir: string | null+ decompiler?: string | null+ /** Found, but no decompiler for this machine: `gradle buildNatives` needed. */+ needsNatives?: boolean+ /** `<install>/support/gradle`, where Ghidra's build runs. */+ buildDir?: string+}++/** The section of the guide that walks through Ghidra on a Mac. */+export const REA_GHIDRA_GUIDE = 'https://locallyuncensored.com/guide/agent/#rea-ghidra'++/**+ * The sentence about Ghidra under the REA row, or null when there is nothing+ * to say (Ghidra ready, or the status came from an older Rust side).+ */+export function reaGhidraLine(g: ReaGhidra | null | undefined): string | null {+ if (!g) return null+ if (!g.found) {+ return g.installDir+ ? `GHIDRA_INSTALL_DIR points at ${g.installDir}, which is not a Ghidra install. Native programs need Ghidra ${g.wantVersion}.`+ : `Ghidra not found. For native programs install Ghidra ${g.wantVersion} from its official GitHub release (guide: ${REA_GHIDRA_GUIDE}).`+ }+ const which = `Ghidra ${g.version ?? '(unknown version)'} at ${g.installDir}`+ const versionNote = g.version && g.version !== g.wantVersion ? ` REA is made for Ghidra ${g.wantVersion}.` : ''+ if (g.needsNatives) {+ return `${which} has no decompiler for this computer (${g.nativeDir}). `+ + 'The official download ships it only for Windows and Linux; build it once in Terminal: '+ + `xcode-select --install, then cd "${g.buildDir}" && gradle buildNatives (needs Gradle 8.5+ and a JDK 21). `+ + `Then switch REA off and on. Guide: ${REA_GHIDRA_GUIDE}${versionNote}`+ }+ return `${which}, decompiler ready.${versionNote}`+}+/** The answer of `plugin_rea_status` / `plugin_rea_fetch`. */export interface ReaStatus {version: string@@ -57,6 +106,8 @@ export interface ReaStatus {node: string | nullnodeOk: booleannodeRange: string+ /** Since 3.0.9; missing from an older Rust side. */+ ghidra?: ReaGhidra | null}export function reaStatus(): Promise<ReaStatus> {@@ -119,6 +170,11 @@ export function reaServerConfig(status: ReaStatus): MCPServerConfig {REA_LOG_LEVEL: 'warn',}if (status.path) env.PATH = status.path+ // A Ghidra LU found in a folder is one REA would not find on its own: a+ // Finder start has no GHIDRA_INSTALL_DIR and no terminal PATH (B11).+ if (status.ghidra?.found && status.ghidra.installDir && status.ghidra.foundBy === 'folder') {+ env.GHIDRA_INSTALL_DIR = status.ghidra.installDir+ }return {id: REA_PLUGIN.serverId,name: REA_PLUGIN.name,