Skip to content

Apps - #785

Open
Hadamcik wants to merge 475 commits into
xch-dev:mainfrom
Hadamcik:apps
Open

Apps#785
Hadamcik wants to merge 475 commits into
xch-dev:mainfrom
Hadamcik:apps

Conversation

@Hadamcik

Copy link
Copy Markdown
Contributor

Reviewer map

sage-apps crate

Sage Apps is built around one core rule: backend owns state and authority. The frontend is only a presentation layer and is not trusted to decide permissions, app identity, runtime state, wallet scope, approval results, install/update validity, or storage/origin ownership.

Most sensitive behavior is intentionally funneled through a small exported surface from crates/sage-apps/src/lib.rs, so lib.rs is the best first review file.

crates/sage-apps/src/lib.rs

The crate exports the following authority entry points:

// State
pub use db::AppsDb;
pub use host::AppsHostState;

// Commands
pub use bridge::commands::{apps_invoke_bridge, apps_invoke_system_bridge};
pub use environment::commands::apps_set_environment_theme;
pub use lifecycle::{
    apps_clear_runtime_browsing_data,
    install::commands::apps_list_installed_apps,
    uninstall::apps_uninstall_app,
    update::commands::{apps_apply_app_update, apps_check_app_update},
};
pub use runtime::commands::{
    apps_clear_active_taskbar_runtime, apps_dev_reload_runtime, apps_enter_workspace,
    apps_focus_taskbar_runtime, apps_kill_taskbar_runtime, apps_leave_workspace,
    apps_list_runtimes, apps_start_system_app, apps_start_user_app,
};
pub use sandbox::commands::{
    apps_get_app_launch_gate, apps_get_sandbox_state, apps_rerun_sandbox_tests,
};
pub use settings::{apps_get_auto_update_enabled, apps_set_auto_update_enabled};

// Bridge protocol
pub use security::{handle_system_app_protocol_request, handle_user_app_protocol_request};

// SDK types
pub use bridge::ts_exports::{export_system_bridge_typescript, export_user_bridge_typescript};

// Operations
pub use lifecycle::{process_pending_storage_cleanup, start_background_app_update_checker};
pub use runtime::process_sage_network_change;
pub use sandbox::runner::ensure_initial_sandbox_run;

// Docs
pub use build::docs::generate_docs;

Where to go from lib.rs

lib.rs is the map of the crate boundary. From each export group, follow these review paths.

1. Bridge protocol: how apps interact with Sage

From:

pub use bridge::commands::{apps_invoke_bridge, apps_invoke_system_bridge};
pub use security::{handle_system_app_protocol_request, handle_user_app_protocol_request};

Review:

  • crates/sage-apps/src/bridge/commands.rs
  • crates/sage-apps/src/bridge/registry.rs
  • crates/sage-apps/src/bridge/methods/shared.rs
  • crates/sage-apps/src/bridge/methods/user/**
  • crates/sage-apps/src/bridge/methods/system/**
  • crates/sage-apps/src/security/**

Important things to verify:

  • all app calls funnel through a small number of backend entry points
  • user bridge and system bridge are isolated
  • bridge methods explicitly declare required capabilities
  • backend re-checks authority at execution time
  • approval UI is not treated as authority
  • runtime capability requests only allow requestable_by_app
  • wallet methods enforce wallet scope

2. App isolation model: what apps are allowed to be

Review:

  • crates/sage-apps/src/types/app/common.rs
  • crates/sage-apps/src/types/app/wallet_scope.rs
  • crates/sage-apps/src/types/invariants/permission.rs
  • crates/sage-apps/src/types/permissions/**
  • crates/sage-apps/src/capabilities/definitions.rs
  • crates/sage-apps/src/capabilities/types.rs
  • crates/sage-apps/src/db/**

Important things to verify:

  • permissions are normalized in backend types
  • secret access cannot coexist with external/network access
  • secret access cannot coexist with tainted persistent webview storage
  • wallet scope is backend-owned durable state
  • capability flags are enforced consistently:
    • user_grantable
    • requestable_by_app
    • shared_with_app

3. Install/update/permission mutation: what changes app authority

Review:

  • crates/sage-apps/src/lifecycle/package.rs
  • crates/sage-apps/src/lifecycle/install/**
  • crates/sage-apps/src/lifecycle/update/**
  • crates/sage-apps/src/lifecycle/mutation/**
  • crates/sage-apps/src/bridge/methods/system/app_install/**
  • crates/sage-apps/src/bridge/methods/system/app_update/**
  • crates/sage-apps/src/bridge/methods/system/app_permissions/**

Important things to verify:

  • manifest permissions are normalized before persistence
  • install/update review is backend-owned
  • permission changes are diffed correctly
  • wallet scope changes are backend-owned
  • permission/scope changes trigger required runtime reload/reopen behavior
  • ZIP extraction is bounded and cannot escape extraction root

4. Runtime lifecycle: how durable app state becomes webviews

From:

pub use runtime::commands::{
    apps_clear_active_taskbar_runtime, apps_dev_reload_runtime, apps_enter_workspace,
    apps_focus_taskbar_runtime, apps_kill_taskbar_runtime, apps_leave_workspace,
    apps_list_runtimes, apps_start_system_app, apps_start_user_app,
};
pub use runtime::process_sage_network_change;

Review:

  • crates/sage-apps/src/runtime/state/**
  • crates/sage-apps/src/runtime/start.rs
  • crates/sage-apps/src/runtime/stop.rs
  • crates/sage-apps/src/runtime/resolve.rs
  • crates/sage-apps/src/runtime/webview.rs
  • crates/sage-apps/src/runtime/commands.rs

Important things to verify:

  • backend runtime state is authority
  • user apps cannot escalate into system presentations
  • runtime reload/reopen paths are centralized
  • stale runtime state cannot silently survive permission/storage changes
  • runtime visibility/focus is backend-controlled

5. Storage/origin rotation and cleanup

From:

pub use lifecycle::{
    apps_clear_runtime_browsing_data,
};
pub use lifecycle::{process_pending_storage_cleanup, start_background_app_update_checker};

Review:

  • crates/sage-apps/src/types/storage/**
  • crates/sage-apps/src/db/storage.rs
  • crates/sage-apps/src/lifecycle/clear_data/**
  • crates/sage-apps/src/lifecycle/storage_cleanup/**
  • crates/sage-apps/src/lifecycle/update/permissions.rs

Important things to verify:

  • storage and origin are explicit durable state
  • clearing/rotating storage invalidates affected runtimes
  • runtimes cannot continue using invalidated storage/origins
  • origin taint persists correctly
  • abandoned cleanup is secondary to runtime invalidation

6. Sandbox validation

From:

pub use sandbox::commands::{
    apps_get_app_launch_gate, apps_get_sandbox_state, apps_rerun_sandbox_tests,
};
pub use sandbox::runner::ensure_initial_sandbox_run;

Review:

  • crates/sage-apps/src/sandbox/**
  • builtin-apps/src/sandbox-test/**

Important things to verify:

  • sandbox tests validate expected isolation behavior
  • tests cover storage isolation
  • tests cover network restrictions
  • tests cover bridge restrictions
  • launch gating behaves correctly

7. Secondary/supporting exports

From:

pub use settings::{apps_get_auto_update_enabled, apps_set_auto_update_enabled};
pub use bridge::ts_exports::{export_system_bridge_typescript, export_user_bridge_typescript};
pub use build::docs::generate_docs;

Review later:

  • crates/sage-apps/src/settings.rs
  • crates/sage-apps/src/bridge/ts_exports.rs
  • crates/sage-apps/src/build/docs.rs
  • SDK/package/generated output

Hadamcik added 30 commits April 26, 2026 23:51
…tion

- Replaced `normalize_and_validate_granted_capabilities` with `normalize_and_validate_user_granted_capabilities` for naming clarity.
- Updated `resolve_effective_granted_capabilities` to `resolve_and_validate_effective_granted_capabilities` for improved modularity and consistency.
- Consolidated `capabilities` logic by integrating validation within normalization workflows.
- Added comprehensive test coverage in `validation.rs` and `tests.rs` for updated capability workflows.
- Simplified imports and visibility settings across modules to improve code organization.
- Eliminated `clear_storage_taint` parameter from permission handling functions.
- Removed associated logic from `update_app_permissions` and internal workflows.
- Deleted obsolete unit test `update_app_permissions_internal_can_clear_storage_taint_without_capabilities`.
- Simplified imports by removing `clear_storage_may_contain_secrets` usage.
…normalization

- Merged required and optional whitelist logic into a single `allowed` set in `validation.rs` for cleaner validation.
- Simplified `normalize_network_entries` by using functional constructs and removing manual sorting in `normalization.rs`.
- Deleted tests and helper functions that have overlapping coverage or were no longer relevant to streamlined validation workflows (`bridge`, `capabilities`, and `lifecycle` modules).
- Consolidated core testing logic into related modules for better organization and clarity.
- Updated imports and visibility settings across affected files.
- Deleted multiple normalization and validation functions in `capabilities` and `network` modules.
- Refactored to rely on simplified permission handling workflows.
- Updated associated imports, tests, and permissions logic for streamlined workflow integration.
- Added detailed structs for Sage App representation (`SageApp`, `UserSageApp`, `SystemSageApp`, etc.) to enhance capability and permission management.
- Included manifest parsers and validators (`SageAppPackageManifest`, `SageRequestedPermissions`, etc.) for strict compliance with app specifications.
- Modularized app-related types (`app.rs`, `permissions.rs`, `manifest.rs`, `network.rs`, `storage.rs`) for improved maintainability.
- Enhanced validation workflows for network and capabilities permissions.
- Defined reusable logic for app lifecycle management and manifest integrity checks.
- Implemented custom deserialization logic for `SageNetworkWhitelistEntry` to support both string and object formats.
- Replaced basic manifest deserialization with `serde_path_to_error` for detailed error reporting.
- Updated `Cargo.toml` to include `serde_path_to_error` dependency.
- Adjusted related structs and logic across `permissions.rs` and `network.rs` for improved consistency and flexibility.
- Deleted deprecated `types_legacy.rs` file and its content.
- Removed obsolete unit tests that referenced legacy type definitions or workflows.
… handling

- Moved `builtin_apps_root` into the `utils` module for consistency and reusability.
- Updated references across `system_apps`, `sandbox`, and `build` modules.
- Simplified file path resolution and validation for system apps manifest and directories.
- Improved error messages related to builtin system app handling.
- Adjusted `sage-manifest.json` to correctly reference the public icon path.
- Extracted common app update retrieval logic into `fetch_pending_update`.
- Simplified `check_app_update`, `update_app_pending_state`, and `apply_app_update` for better maintainability.
- Added `from_pending_update` constructor to `SageAppUrlPreview` for consistency.
…n` components

- Extracted icon rendering logic into reusable `AppIconContent` and `AppIcon` components.
- Replaced inline logic for app icons across multiple files (`AppTaskBar`, `InstallDialog`, `AppTile`, etc.) to improve consistency.
- Adjusted `InstallSource` type export for shared use.
- Simplified icon URL resolution and fallback logic for better maintainability.
…ogic

- Moved capability-related validation and construction logic from `permissions.rs` to `invariants.rs`.
- Introduced reusable functions: `validate_permissions_policy`, `validate_requested_capabilities_are_requestable`, and `build_user_grantable_capability_set`.
- Simplified `SageRequestedPermissions` and related methods for better reusability and maintainability.
- Removed redundant `build_capabilities` and inlined checks into reusable helpers.
…st and capability construction

- Introduced `split_required_optional_set` in `invariants.rs` to centralize logic for handling `required` and `optional` sets.
- Updated `SageNetworkWhitelist` and `SageRequestedPermissions` constructors to use the new helper function.
- Simplified filtering logic for consistency and maintainability.
- Split `invariants.rs` into `app.rs`, `manifest.rs`, and `permission.rs` for better modularity.
- Moved app-related, manifest-related, and permission-related logic into respective modules.
- Updated imports across the project to reflect the new structure.
- Introduced `resolve_app_capability_flags` to simplify and reuse capability flag resolution logic.
- Replaced `capabilities_vec` with `has_capability` for direct capability checks.
- Removed redundant methods across `user.rs`, `permissions.rs`, and related files.
- Streamlined permission and capability handling for improved clarity and maintainability.
- Removed `into_sage_app` and `new_builtin` methods as they were unused.
- Streamlined `PersistentStorage` capability check by introducing `has_persistent_storage` intermediate variable.
- Cleaned up unused imports and reduced redundant code to improve clarity.
- Introduced `app_path` method in `SageAppCommon` and exposed it in related structs.
- Replaced redundant `app_dir` conversions with `app_path` across multiple files (`commands.rs`, `permissions.rs`, etc.).
- Cleaned up imports and removed unused `PathBuf` declarations.
…try`/`icon` retrieval

- Removed `manifest_entry_file` and `manifest_icon_file` in favor of using `manifest.entry()` and `manifest.icon()` directly.
- Updated `entry()` to provide a default value of `"index.html"` for consistency.
- Cleaned up related tests and updated assertions accordingly.
… manifest validation logic

- Added `SageAppUrl` and `SageAppManifestUrl` types for improved URL handling and validation.
- Consolidated manifest-related validation into `invariants::manifest.rs` to centralize logic.
- Removed redundant functions and tests, migrating necessary logic to updated modules.
- Simplified the `fetch_url_manifest` and manifest derivation process using new URL types.
…ation

- Moved limit constants (`MAX_APP_FILE_COUNT`, `MAX_APP_TOTAL_SIZE_BYTES`, `MAX_APP_PATH_LENGTH`) into `manifest.rs` for centralization.
- Replaced `validate_package_structure` with `SageAppPackageManifest::validate_package_files`.
- Cleaned up imports, removing unused dependencies and redundant function logic.
- Updated all package validation calls to use the refactored `validate_package_files` method for consistency.
…rganization

- Moved all manifest-related tests from `lifecycle/manifest.rs` to `types/manifest.rs` to centralize test logic.
- Cleaned up redundant code and ensured test consistency during relocation.
…lize URL validation logic

- Introduced `SageAppUrl` and `SageAppManifestUrl` types for robust app and manifest URL management.
- Consolidated URL validation and normalization logic into `invariants/url.rs`.
- Replaced string-based `app_url` and `manifest_url` with `SageAppUrl` across the codebase.
- Updated related methods, tests, and imports for consistency and maintainability.
Rigidity and others added 15 commits May 31, 2026 17:48
- Introduced `set_builtin_apps_root` to allow dynamic configuration of the `builtin-apps` root directory.
- Updated Tauri app initialization to set `builtin-apps` root from bundled resources directory if available.
- Modified `tauri.conf.json` to include `builtin-apps` in bundled resources.
… locales

- Synced translation changes in `en-US`, `es-MX`, `zh-CN`, and `de-DE` locales.
- Added new entries for "Apps" and adjusted context references for updated components.
- Addressed line number updates and structural changes in `src/components/Nav.tsx` and other related components.
…ld process

- Introduced a new `generate_docs` binary in `sage-apps` for generating Sage app documentation.
- Updated `build.rs` to remove in-process docs generation in favor of the new binary.
- Modified `package.json` to include `generate:app-docs` script and integrate docs generation into the `build:builtin-apps` process.
- Added Tauri Android and iOS configuration files with a `beforeBuildCommand` to build the frontend.
Hadamcik and others added 13 commits July 5, 2026 01:14
Bridge responses and per-app runtime events were delivered with
`Emitter::emit`, which in Tauri broadcasts to every webview that has a
JS listener for the event name rather than only the intended one. Since
`wallet.getSecretKey` (and other approval-gated) results are delivered
over the `sage-bridge:response` rail, a second user app running
concurrently could subscribe to that event and capture another app's
secret key material and bridge results.

Deliver `sage-bridge:response` and the user/system runtime event rails
with `emit_to(<app webview label>, ...)` so each payload reaches only the
originating app's webview. The broadcast to the trusted main Sage webview
(`apps:runtime-event`) is unchanged and documented.
…ndexedDB seeding, and validate storage probe data. Integrate host isolation seeding into tests.
…prove error handling, and optimize staging process.
…before applying updates; add tests and update related function signatures.
… state rechecks, and reload mechanisms; standardize table formatting in generated documentation.
…dering logic, add tests, and improve markdown formatting.
…tain operation locks until initialization completes; include tests for guard behavior.
…L resolution logic; include loopback and private network restrictions with tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants