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
tech(RA-1): das Berechtigungs-Panel zeigt, was der Server wirklich tut
Davidc9935453d240
diff --git a/src-tauri/src/commands/remote.rs b/src-tauri/src/commands/remote.rsindex a4e49965..2473d797 100644--- a/src-tauri/src/commands/remote.rs+++ b/src-tauri/src/commands/remote.rs@@ -58,12 +58,30 @@ pub struct RemotePermissions {pub shell: bool,}+/// RA-1: EVERYTHING off by default.+///+/// The desktop permission panel renders its toggles from the frontend store,+/// which starts all-false. The server used to start filesystem/downloads/+/// process_control at `true`, so a user who deliberately left every switch+/// off still handed a paired phone workspace read/write, screenshots,+/// process_list, model pull/delete and ComfyUI start/stop. The displayed+/// control was decoration.+///+/// Two halves fix that and both are needed: this conservative default (the+/// server can no longer be more permissive than the panel claims) and the+/// read-back — `start_remote_server` / `remote_server_status` now report the+/// effective permissions so the panel can never drift from the server again+/// (a paired phone may raise the three non-RCE scopes from the mobile+/// permissions panel; the desktop now sees that).+///+/// `shell` stays off for the separate, stronger reason documented on the+/// field: it is RCE-equivalent and desktop-controlled only.impl Default for RemotePermissions {fn default() -> Self {Self {- filesystem: true,- downloads: true,- process_control: true,+ filesystem: false,+ downloads: false,+ process_control: false,shell: false,}}@@ -5098,6 +5116,12 @@ pub async fn start_remote_server(*dsp = system_prompt.unwrap_or_default();}+ // RA-1: the Arc moves into the axum state below, so keep a second handle to+ // read the effective permissions back into the start response. The desktop+ // store maps them in the same `set()` that flips `enabled: true`, so there+ // is no window in which the panel shows something the server isn't doing.+ let permissions_readback = permissions_arc.clone();+let server_state = RemoteState {jwt_secret: jwt_secret_arc,passcode: passcode_arc,@@ -5188,6 +5212,8 @@ pub async fn start_remote_server(.map(|ip| ip.to_string()).unwrap_or_else(|_| "127.0.0.1".to_string());+ let permissions = permissions_readback.lock().await.clone();+info!(port = port, "remote server started");Ok(serde_json::json!({"port": port,@@ -5195,6 +5221,10 @@ pub async fn start_remote_server("passcodeExpiresAt": now + PASSCODE_TTL_SECS,"lanUrl": format!("http://{}:{}", lan_ip, port),"mobileUrl": format!("http://{}:{}/mobile", lan_ip, port),+ // RA-1: effective permissions, so the UI is never out of sync with the+ // server it just started. `restart_remote_server` delegates here, so it+ // reports them too.+ "permissions": permissions,}))}@@ -5263,7 +5293,7 @@ pub async fn stop_remote_server(pub async fn remote_server_status(state: tauri::State<'_, crate::state::AppState>,) -> Result<serde_json::Value, String> {- let (running, port, passcode_arc, tunnel_url_arc, tunnel_pid) = {+ let (running, port, passcode_arc, tunnel_url_arc, tunnel_pid, permissions_arc) = {let remote = state.remote.lock().map_err(|e| e.to_string())?;(remote.handle.is_some(),@@ -5271,6 +5301,7 @@ pub async fn remote_server_status(remote.passcode.clone(),remote.tunnel_url.clone(),remote.tunnel_pid,+ remote.permissions.clone(),)};@@ -5286,6 +5317,12 @@ pub async fn remote_server_status((pc.code.clone(), pc.expires_at)};+ // RA-1: report the EFFECTIVE server permissions so the desktop panel reads+ // the server's truth instead of showing a hardcoded all-false guess. This is+ // also how a change made from the mobile permissions panel gets back to the+ // desktop UI.+ let permissions = permissions_arc.lock().await.clone();+let tunnel_url = tunnel_url_arc.lock().await;let lan_ip = local_ip_address::local_ip().map(|ip| ip.to_string())@@ -5300,6 +5337,7 @@ pub async fn remote_server_status("mobileUrl": if running { format!("http://{}:{}/mobile", lan_ip, port) } else { String::new() },"tunnelActive": tunnel_pid.is_some(),"tunnelUrl": tunnel_url.clone().unwrap_or_default(),+ "permissions": permissions,}))}@@ -6019,6 +6057,37 @@ mod remote_path_tests {assert!(!p.shell, "remote `shell` permission must default to false");}+ #[test]+ fn all_remote_permissions_are_off_by_default() {+ // RA-1: the desktop panel renders every toggle OFF on a fresh start.+ // The server default has to agree, otherwise a user who deliberately+ // granted nothing still handed a paired phone workspace read/write,+ // model pull/delete and ComfyUI start/stop.+ let p = super::RemotePermissions::default();+ assert!(!p.filesystem, "filesystem must default to false");+ assert!(!p.downloads, "downloads must default to false");+ assert!(!p.process_control, "process_control must default to false");+ assert!(!p.shell, "shell must default to false");+ }++ #[test]+ fn remote_permissions_serialize_with_snake_case_keys() {+ // RA-1 read-back contract: `start_remote_server` / `remote_server_status`+ // embed this struct as `permissions`, and the frontend store maps+ // exactly these key names into RemoteState.permissions.+ let json = serde_json::to_value(super::RemotePermissions {+ filesystem: true,+ downloads: false,+ process_control: true,+ shell: false,+ })+ .unwrap();+ assert_eq!(json["filesystem"], serde_json::json!(true));+ assert_eq!(json["downloads"], serde_json::json!(false));+ assert_eq!(json["process_control"], serde_json::json!(true));+ assert_eq!(json["shell"], serde_json::json!(false));+ }+#[test]fn remote_permissions_deserialize_without_shell_defaults_false() {// Older mobile/client payloads omit `shell`; serde default must be false.diff --git a/src/api/__tests__/mobile-codex-parity.test.ts b/src/api/__tests__/mobile-codex-parity.test.tsindex 5517b5c5..ac90f955 100644--- a/src/api/__tests__/mobile-codex-parity.test.ts+++ b/src/api/__tests__/mobile-codex-parity.test.ts@@ -123,13 +123,35 @@ describe('Mobile fallback final answer', () => {})describe('Mobile permissions', () => {- it('all permissions default to ON', () => {- // RemotePermissions::default() should have all true- expect(REMOTE_RS).toMatch(/impl\s+Default\s+for\s+RemotePermissions/)- // Check for `true` defaults (field names: filesystem, downloads, process_control)- expect(REMOTE_RS).toMatch(/filesystem:\s*true/)- expect(REMOTE_RS).toMatch(/downloads:\s*true/)- expect(REMOTE_RS).toMatch(/process_control:\s*true/)+ // RA-1: this used to assert "all permissions default to ON" — and it passed+ // for the wrong reason, because it matched `filesystem: true` ANYWHERE in the+ // 6k-line file (the merge tests contain that literal). The default it was+ // guarding was itself the bug: the desktop panel renders every toggle off on+ // a fresh start, so a server that starts filesystem/downloads/process_control+ // at `true` hands a paired phone workspace read/write, model pull/delete and+ // ComfyUI start/stop that the user never granted. Now scoped to the actual+ // `impl Default` block, and asserting the conservative default.+ const defaultBlock = REMOTE_RS.match(+ /impl\s+Default\s+for\s+RemotePermissions\s*\{[\s\S]*?\n\}/,+ )?.[0]++ it('has an impl Default for RemotePermissions', () => {+ expect(defaultBlock).toBeTruthy()+ })++ it('defaults every permission to OFF, matching what the desktop panel shows', () => {+ expect(defaultBlock).toMatch(/filesystem:\s*false/)+ expect(defaultBlock).toMatch(/downloads:\s*false/)+ expect(defaultBlock).toMatch(/process_control:\s*false/)+ expect(defaultBlock).toMatch(/shell:\s*false/)+ expect(defaultBlock).not.toMatch(/:\s*true/)+ })++ it('reports the effective permissions back to the desktop', () => {+ // Without a read-back the panel is decoration: it can only ever show its+ // own local guess. Both the start response and the status command carry+ // them, and the store maps them in.+ expect(REMOTE_RS).toContain('"permissions": permissions')})})diff --git a/src/stores/__tests__/remoteStore.test.ts b/src/stores/__tests__/remoteStore.test.tsindex 7e5562d0..dcf551f4 100644--- a/src/stores/__tests__/remoteStore.test.ts+++ b/src/stores/__tests__/remoteStore.test.ts@@ -7,7 +7,7 @@ vi.mock('../../api/backend', () => ({isTauri: () => mockIsTauri(),}))-import { useRemoteStore, REMOTE_DEV_MODE_ERROR, remoteBackendArgs } from '../remoteStore'+import { useRemoteStore, REMOTE_DEV_MODE_ERROR, remoteBackendArgs, normalizeRemotePermissions } from '../remoteStore'describe('remoteBackendArgs (#87 non-Ollama remote routing)', () => {const providers = {@@ -65,7 +65,7 @@ describe('remoteStore', () => {mobileUrl: '',qrPngBase64: '',connectedDevices: [],- permissions: { filesystem: false, downloads: false, process_control: false },+ permissions: { filesystem: false, downloads: false, process_control: false, shell: false },tunnelActive: false,tunnelUrl: '',tunnelLoading: false,@@ -426,18 +426,24 @@ describe('remoteStore', () => {downloads: true,process_control: false,})+ // RA-1: the store now normalises to a fully-explicit payload — `shell`+ // is optional on the TS type, and an undefined scope must never reach+ // the backend as "whatever serde defaults to".expect(useRemoteStore.getState().permissions).toEqual({filesystem: true,downloads: true,process_control: false,+ shell: false,})})- it('calls backend with correct args', async () => {+ it('calls backend with correct args, every scope explicit', async () => {const perms = { filesystem: true, downloads: false, process_control: false }mockBackendCall.mockResolvedValueOnce(undefined)await useRemoteStore.getState().setPermissions(perms)- expect(mockBackendCall).toHaveBeenCalledWith('set_remote_permissions', { permissions: perms })+ expect(mockBackendCall).toHaveBeenCalledWith('set_remote_permissions', {+ permissions: { ...perms, shell: false },+ })})it('sets error on failure', async () => {@@ -449,5 +455,199 @@ describe('remoteStore', () => {})expect(useRemoteStore.getState().error).toContain('Perm error')})++ it('leaves the shown permissions untouched when the push fails', async () => {+ // RA-1: a failed toggle must not repaint the panel as if it applied —+ // the panel has to keep showing the server's last known truth.+ useRemoteStore.setState({+ permissions: { filesystem: false, downloads: false, process_control: false, shell: false },+ })+ mockBackendCall.mockRejectedValueOnce(new Error('Perm error'))+ await useRemoteStore.getState().setPermissions({+ filesystem: true,+ downloads: true,+ process_control: true,+ shell: true,+ })+ expect(useRemoteStore.getState().permissions).toEqual({+ filesystem: false,+ downloads: false,+ process_control: false,+ shell: false,+ })+ })+ })++ // ── RA-1: permission read-back ─────────────────────────────+ //+ // The panel used to render a purely local guess: the store hardcoded every+ // scope to false, refreshStatus never mapped the server's copy, and the Rust+ // `impl Default for RemotePermissions` started filesystem/downloads/+ // process_control at TRUE. A user who granted nothing still handed a paired+ // phone workspace read/write, model pull/delete and ComfyUI start/stop.+ // Every path that learns the server's mind must now map it into the store.++ describe('permission read-back (RA-1)', () => {+ const statusBase = {+ running: true,+ port: 11435,+ passcode: 'P',+ passcodeExpiresAt: 1,+ lanUrl: 'http://lan',+ mobileUrl: 'http://lan/m',+ tunnelActive: false,+ tunnelUrl: '',+ }++ it('maps the permissions reported by remote_server_status', async () => {+ mockBackendCall.mockResolvedValueOnce({+ ...statusBase,+ permissions: { filesystem: true, downloads: false, process_control: true, shell: false },+ })+ await useRemoteStore.getState().refreshStatus()+ expect(useRemoteStore.getState().permissions).toEqual({+ filesystem: true,+ downloads: false,+ process_control: true,+ shell: false,+ })+ })++ it('surfaces a scope a paired phone raised through the mobile panel', async () => {+ // The mobile permissions panel POSTs /remote-api/permissions, which the+ // desktop never sees on its own. Status polling is the path that catches+ // it, so the desktop toggle stops lying about what the phone can do.+ useRemoteStore.setState({+ permissions: { filesystem: false, downloads: false, process_control: false, shell: false },+ })+ mockBackendCall.mockResolvedValueOnce({+ ...statusBase,+ permissions: { filesystem: true, downloads: false, process_control: false, shell: false },+ })+ await useRemoteStore.getState().refreshStatus()+ expect(useRemoteStore.getState().permissions.filesystem).toBe(true)+ })++ it('treats a missing scope as denied, never as granted', async () => {+ useRemoteStore.setState({+ permissions: { filesystem: true, downloads: true, process_control: true, shell: true },+ })+ mockBackendCall.mockResolvedValueOnce({+ ...statusBase,+ permissions: { filesystem: true }, // older/partial payload+ })+ await useRemoteStore.getState().refreshStatus()+ expect(useRemoteStore.getState().permissions).toEqual({+ filesystem: true,+ downloads: false,+ process_control: false,+ shell: false,+ })+ })++ it('keeps the current value when the backend reports no permissions', async () => {+ // A backend predating the read-back tells us nothing. Coercing to+ // all-false there would just move the lie to the other side.+ useRemoteStore.setState({+ permissions: { filesystem: true, downloads: false, process_control: false, shell: false },+ })+ mockBackendCall.mockResolvedValueOnce({ ...statusBase })+ await useRemoteStore.getState().refreshStatus()+ expect(useRemoteStore.getState().permissions).toEqual({+ filesystem: true,+ downloads: false,+ process_control: false,+ shell: false,+ })+ })++ it('adopts the server permissions in the same update that enables the server', async () => {+ // No window may exist in which `enabled` is already true while the panel+ // still shows the pre-start guess.+ useRemoteStore.setState({+ permissions: { filesystem: false, downloads: false, process_control: false, shell: false },+ })+ const seen: Array<{ enabled: boolean; filesystem: boolean }> = []+ const unsub = useRemoteStore.subscribe((st) =>+ seen.push({ enabled: st.enabled, filesystem: st.permissions.filesystem }),+ )+ mockBackendCall+ .mockResolvedValueOnce({+ port: 11435,+ passcode: 'ABC',+ passcodeExpiresAt: 9999,+ lanUrl: 'http://lan',+ mobileUrl: 'http://lan/m',+ permissions: { filesystem: true, downloads: true, process_control: false, shell: false },+ })+ .mockResolvedValueOnce({ qr_png_base64: '', url: '', passcode: '' })++ await useRemoteStore.getState().startServer()+ unsub()++ expect(useRemoteStore.getState().permissions).toEqual({+ filesystem: true,+ downloads: true,+ process_control: false,+ shell: false,+ })+ // Not one emitted state had the server running under permissions the+ // panel wasn't showing.+ expect(seen.filter((s) => s.enabled && !s.filesystem)).toEqual([])+ })++ it('maps the permissions returned by a restart', async () => {+ useRemoteStore.setState({+ permissions: { filesystem: true, downloads: true, process_control: true, shell: true },+ })+ mockBackendCall+ .mockResolvedValueOnce({+ port: 11435,+ passcode: 'ABC',+ passcodeExpiresAt: 9999,+ lanUrl: 'http://lan',+ mobileUrl: 'http://lan/m',+ permissions: { filesystem: false, downloads: false, process_control: false, shell: false },+ })+ .mockResolvedValueOnce({ qr_png_base64: '', url: '', passcode: '' })++ await useRemoteStore.getState().restart()+ expect(useRemoteStore.getState().permissions).toEqual({+ filesystem: false,+ downloads: false,+ process_control: false,+ shell: false,+ })+ })++ it('starts with every scope off, matching the Rust default', async () => {+ // The store's initial value and `impl Default for RemotePermissions` have+ // to agree, or the very first render is already a lie.+ expect(useRemoteStore.getInitialState().permissions).toEqual({+ filesystem: false,+ downloads: false,+ process_control: false,+ shell: false,+ })+ })+ })+})++describe('normalizeRemotePermissions (RA-1)', () => {+ it('coerces every scope to an explicit boolean', () => {+ expect(normalizeRemotePermissions({ filesystem: true, downloads: false, process_control: true, shell: true }))+ .toEqual({ filesystem: true, downloads: false, process_control: true, shell: true })+ })++ it('reads anything that is not exactly `true` as denied', () => {+ expect(normalizeRemotePermissions({ filesystem: 'true', downloads: 1, process_control: null }))+ .toEqual({ filesystem: false, downloads: false, process_control: false, shell: false })+ })++ it('returns null for a payload that carries no permissions object', () => {+ expect(normalizeRemotePermissions(undefined)).toBeNull()+ expect(normalizeRemotePermissions(null)).toBeNull()+ expect(normalizeRemotePermissions('filesystem')).toBeNull()+ expect(normalizeRemotePermissions([])).toBeNull()})})diff --git a/src/stores/remoteStore.ts b/src/stores/remoteStore.tsindex 4b7fef07..f498f529 100644--- a/src/stores/remoteStore.ts+++ b/src/stores/remoteStore.ts@@ -94,7 +94,7 @@ interface ConnectedDevice {last_seen: number}-interface RemotePermissions {+export interface RemotePermissions {filesystem: booleandownloads: booleanprocess_control: boolean@@ -104,6 +104,40 @@ interface RemotePermissions {shell?: boolean}+/**+ * RA-1: the permission panel used to be decoration. The store initialised+ * `permissions` all-false locally, `refreshStatus` never mapped the server's+ * copy, and there is no persist middleware — so the UI showed a guess, while+ * `impl Default for RemotePermissions` on the Rust side started+ * filesystem/downloads/process_control at TRUE. A user who deliberately+ * granted nothing still handed a paired phone workspace read/write,+ * screenshots, process_list, model pull/delete and ComfyUI start/stop.+ *+ * The fix has two halves. Rust now defaults every scope to false, and every+ * response that can tell us the server's mind (`start_remote_server`,+ * `restart_remote_server`, `remote_server_status`) carries the effective+ * `permissions`. This helper is the single mapping point.+ *+ * Returns `null` when the payload carries no usable permissions object — an+ * older backend that predates the read-back. In that case callers must LEAVE+ * the current store value alone rather than invent one; coercing to all-false+ * would just move the lie to the other side.+ *+ * Pure + exported for unit tests.+ */+export function normalizeRemotePermissions(raw: unknown): RemotePermissions | null {+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null+ const r = raw as Record<string, unknown>+ // Anything not explicitly `true` reads as denied: a missing or malformed+ // field must never render as a granted capability.+ return {+ filesystem: r.filesystem === true,+ downloads: r.downloads === true,+ process_control: r.process_control === true,+ shell: r.shell === true,+ }+}+interface RemoteState {enabled: booleanport: number@@ -200,7 +234,12 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({passcodeExpiresAt: numberlanUrl: stringmobileUrl: string+ permissions?: RemotePermissions}>('start_remote_server', args)+ // RA-1: read the server's effective permissions back in the SAME set()+ // that flips `enabled: true`. There must be no window in which the panel+ // renders one thing and the running server enforces another.+ const startPerms = normalizeRemotePermissions(result.permissions)set({enabled: true,port: result.port,@@ -208,6 +247,7 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({passcodeExpiresAt: result.passcodeExpiresAt,lanUrl: result.lanUrl,mobileUrl: result.mobileUrl,+ ...(startPerms ? { permissions: startPerms } : {}),loading: false,qrVisible: true, // Bug #16: show QR right after a fresh dispatch})@@ -257,8 +297,9 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({mobileUrl: stringtunnelActive: booleantunnelUrl: string+ permissions?: RemotePermissions}>('remote_server_status')- set({+ const next: Partial<RemoteState> = {enabled: status.running,port: status.port,passcode: status.passcode,@@ -267,7 +308,14 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({mobileUrl: status.mobileUrl,tunnelActive: status.tunnelActive,tunnelUrl: status.tunnelUrl,- })+ }+ // RA-1: the server owns the permissions, the panel only renders them.+ // This is also the path that surfaces a change a paired phone made+ // through the mobile permissions panel. An older backend that doesn't+ // report them leaves the current value untouched.+ const perms = normalizeRemotePermissions(status.permissions)+ if (perms) next.permissions = perms+ set(next as RemoteState)} catch {// Non-critical}@@ -319,9 +367,21 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({},setPermissions: async (perms: RemotePermissions) => {+ // RA-1: never send a partial payload. `shell` is optional on the TS type,+ // and an undefined field would land on the Rust side as serde's default —+ // the store must state every scope explicitly so what we push is exactly+ // what the panel shows. On failure the store is left untouched, so the UI+ // keeps showing the server's last known truth instead of an unapplied+ // toggle.+ const payload = normalizeRemotePermissions(perms) ?? {+ filesystem: false,+ downloads: false,+ process_control: false,+ shell: false,+ }try {- await backendCall('set_remote_permissions', { permissions: perms })- set({ permissions: perms })+ await backendCall('set_remote_permissions', { permissions: payload })+ set({ permissions: payload })} catch (err) {set({ error: String(err) })}@@ -422,7 +482,11 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({passcodeExpiresAt: numberlanUrl: stringmobileUrl: string+ permissions?: RemotePermissions}>('restart_remote_server', args)+ // RA-1: same read-back as startServer — restart_remote_server delegates+ // to start_remote_server on the Rust side and reports them identically.+ const restartPerms = normalizeRemotePermissions(result.permissions)set({enabled: true,port: result.port,@@ -430,6 +494,7 @@ export const useRemoteStore = create<RemoteState>()((set, get) => ({passcodeExpiresAt: result.passcodeExpiresAt,lanUrl: result.lanUrl,mobileUrl: result.mobileUrl,+ ...(restartPerms ? { permissions: restartPerms } : {}),loading: false,qrVisible: true, // Bug #16: fresh restart → fresh passcode → show QR})