Files
sovereign_browser_rust/plans/full-implementation-analysis.md

9.4 KiB

Comprehensive Implementation Gap Analysis: Sovereign Browser (Rust vs. C)

This document provides a detailed breakdown of all components, subsystems, internal pages, and features comparing the original C implementation (/home/user/lt/sovereign_browser) to the current Rust implementation (/home/user/lt/sovereign_browser_rust).


1. Executive Summary & Parity Matrix

Subsystem / Feature C Implementation Status Rust Implementation Status Parity % Priority
Core GTK & Multi-Tab Window Complete (tabs, toolbars, shortcuts, theme, context menus) Complete (tabs, per-tab toolbars, theme, webview & tab context menus) 95% Low
NIP-07 JS Extension Injection (window.nostr) Complete (Sync XHR, Security Manager, NIP-04/44, named constructor) Complete (Sync XHR, Security Manager, NIP-04/44, named constructor) 100% Done
MCP Automation Server Complete (Streamable HTTP, Tools on port 17777) Complete (Streamable HTTP, cross-thread GTK scheduling) 100% Done
Login Dialog & CLI Auth Complete (5 tabs, No Login, CLI auto-login for local/seed/pubkey) Complete (5 tabs, No Login, CLI auto-login for local/seed/pubkey) 95% Low
Settings (sovereign://settings) Complete (Embedded HTML/JS, Live toggles, relays, shortcuts, save) Complete (Dynamic HTML, XHR endpoint handling, SQLite persistence) 90% Low
Embedded Internal Pages (sovereign://) Complete (Profile, Bookmarks, FIPS, Processes, Agents) Partial (Basic static HTML/JS stubs, missing rich JS apps) 30% High
Agent Loop & Provider Management Complete (OpenAI/Anthropic/Ollama, tool calling, chat store) Partial (Async loop structure exists, missing UI hooks & prompt wiring) 50% High
Agent Chat Sidebar Complete (Collapsible left sidebar webview running sovereign://agents/chat) Incomplete (Shortcut mapped, sidebar container not fully attached to tabs) 20% Medium
URL Autocomplete / Search Dropdown Complete (GtkEntryCompletion for bookmarks & history) Incomplete (URL entry exists, completion model not wired) 20% Medium
Per-Tab Performance Probe (sovereign://processes) Complete (perf-probe.js injection, CPU/FPS/DOM stats, probe-report endpoint) Incomplete (Skeleton probe struct, probe injection & report collection missing) 15% Medium
NIP-78 Settings & Bookmark Sync Complete (Kind 30078 / 30003 NIP-44 encrypted sync to bootstrap relays) Partial (Library functions exist, automatic background publish not wired) 40% Medium
Tor & FIPS Service Controllers Complete (Tor control protocol, FIPS Unix IPC / daemon management) Stubs (Module placeholders returning mock/default status) 15% Low
Offline Site Downloader Complete (Headless webview rendering & asset bundling) Stubs (Log message placeholder) 10% Low

2. Detailed Gap Breakdown by Subsystem

2.1 Internal Pages & Embedded Assets (src/embedded_web_content.rs, src/nostr_bridge.rs)

In the original C version, the www/ directory contains complete single-page web applications for browser management:

  1. sovereign://profile (www/profile.html, profile.js, profile.css):
    • C: Queries cached Kind 0 (metadata) and Kind 3 (contacts) events from SQLite, displays avatar, banner, bio, NIP-05 verification, QR code generation (sovereign://qr), and contact list.
    • Rust: Only returns a minimal static HTML template; handle_profile_data_json endpoint is stubbed.
  2. sovereign://bookmarks (www/bookmarks.html, bookmarks.js, bookmarks.css):
    • C: Nested folder tree view with drag-and-drop hierarchy, tag filters, live editing, and REST endpoints (/bookmarks/list, /add, /delete, /createdir, /deletedir, /move, /rename, /renamedir).
    • Rust: Embedded HTML is a simple flat list; directory tree endpoints need full implementation in nostr_bridge.rs.
  3. sovereign://agents & sovereign://agents/chat (www/agents/):
    • C: Complete chat client supporting markdown rendering (marked.min.js), HTML sanitization (purify.min.js), conversation branching, model selection, skill management (/agents/skills/*), and live polling of agent messages.
    • Rust: Static placeholder forms without full web client assets and conversation endpoints.
  4. sovereign://processes (www/processes.html, processes.js):
    • C: Two-layer diagnostics dashboard: Layer 1 lists OS processes/WebProcesses (PID, CPU, Memory); Layer 2 lists per-tab performance metrics collected via perf-probe.js.
    • Rust: HTML skeleton with no real process tracking or probe integration.
  5. sovereign://fips (www/fips.html, fips.js):
    • C: Mesh management UI showing status cards, active peers, spanning tree graph, node directory (Kind 37195), and manual connection controls.
    • Rust: Static placeholder form.

2.2 Tab Management & UI Features (src/tab_manager.rs)

  1. Agent Chat Sidebar (tab_manager_toggle_sidebar):
    • C: Creates a persistent GtkPaned container with a collapsible 280px left sidebar hosting a dedicated WebKitWebView loaded with sovereign://agents/chat.
    • Rust: tab_manager_toggle_sidebar() function stub exists, but webview/sidebar layout is not packed into the tab container.
  2. URL Entry Completion (GtkEntryCompletion):
    • C: As the user types in the URL bar, an async completion popup searches SQLite history and bookmarks, showing favicon/title/URL.
    • Rust: GtkEntry handles Enter and Esc, but has no attached GtkEntryCompletion model.
  3. Popup & New Window Handling (on_create_webview / target="_blank"):
    • C: Intercepts WebKit create signal on webviews to enforce tab policy (converting popup windows into new tabs or respected multi-window popups based on settings).
    • Rust: Navigation policy decision is handled for URLs, but the WebKit create signal is not hooked.
  4. Favicon Display:
    • C: Captures favicon-database updates and renders 16x16 pixbufs in tab labels.
    • Rust: Omitted due to Cairo surface conversion differences; uses a generic globe icon.

2.3 Agent System & Tool Catalog (src/agent_*.rs)

  1. Interactive Tool Execution:
    • browser_click and browser_type: Currently stubs in agent_tools.rs. C injects DOM query selector JS to synthesize click and keyboard input events.
    • browser_screenshot: C captures the WebKit webview surface to PNG bytes; Rust returns a stub message.
  2. Skill Management (src/agent_skills.rs):
    • C publishes and queries NIP-51/NIP-78 Kind 31123 skill definitions to Nostr relays. Rust has internal structs but lacks relay publishing integration.
  3. Conversation Persistence (src/agent_conversations.rs):
    • C encrypts chat sessions using NIP-44 and persists them to Nostr relays (Kind 30078) and local SQLite. Rust has SQLite tables but lacks relay publishing.

2.4 Performance Probe Subsystem (src/perf_probe.rs)

  1. js/perf-probe.js Script Injection:
    • C: Injected via UserContentManager into non-internal pages; measures CPU busy percentage (Long Tasks API), FPS (requestAnimationFrame loop), DOM node count, Heap used, in-flight fetch requests, and sends periodic reports to sovereign://processes/probe-report.
    • Rust: Not yet injected; /processes/probe-report endpoint is unhandled.

2.5 Network Services & System daemons (src/net_services.rs, src/tor_control.rs, src/fips_control.rs)

  1. Tor Control:
    • C: Connects to Tor ControlPort (default 9051), authenticates, checks circuit status, and requests new identity (SIGNAL NEWNYM).
    • Rust: Simulated in memory.
  2. FIPS Mesh Control:
    • C: Connects via Unix domain socket to the local FIPS daemon, queries peer tables, resolves .fips and npub overlay addresses.
    • Rust: Stubs returning default status.

flowchart TD
    A[Phase 1: Rich Embedded Pages & Assets] --> B[Phase 2: UI Enhancements & Sidebar]
    B --> C[Phase 3: Agent Tool Execution & Automation]
    C --> D[Phase 4: Diagnostics & Settings/Bookmark Sync]
    D --> E[Phase 5: Network Services Tor/FIPS]

Phase 1: Rich Internal Pages (sovereign://)

  • Migrate embedded web assets from www/ into embedded_web_content.rs or asset files.
  • Implement full REST JSON route dispatchers in nostr_bridge.rs for Bookmarks (/bookmarks/*), Profile (/profile/data), and Agents (/agents/*).

Phase 2: Tab Manager & UI Features

  • Wire collapsible Agent Chat sidebar into tab_manager.rs.
  • Connect GtkEntryCompletion for URL autocomplete from SQLite history and bookmarks.
  • Handle WebKit create signal for target="_blank" popups.

Phase 3: Agent Automation & Tool Execution

  • Implement DOM automation tools (browser_click, browser_type) via run_javascript.
  • Implement browser_screenshot via WebKitGTK snapshot API.

Phase 4: Performance Probe & Sync

  • Wire perf-probe.js injection into all page views and connect sovereign://processes/probe-report.
  • Wire automatic background sync for Kind 30078 settings and Kind 30003 bookmarks.

Phase 5: Network Daemon Controls

  • Implement Tor ControlPort protocol client in tor_control.rs.
  • Implement FIPS daemon Unix socket IPC in fips_control.rs.