YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(enterprise): resolve license key from enterprise.json — no env var needed
Louis Beaumont5a64d154b828
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts b/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.tsindex 2a275ad6c..ad08dc2ea 100644--- a/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts+++ b/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts@@ -232,6 +232,21 @@ export function useEnterprisePolicy() {}} catch {}+ // Fallback: read directly from ~/.screenpipe/auth.json when the+ // in-memory store hasn't been hydrated yet (dev launches before+ // sign-in completes, or store resets). auth.json is the durable+ // on-disk copy maintained by the pi-agent configuration flow.+ if (!cloudToken) {+ try {+ const fallback = await commands.getCloudToken();+ if (typeof fallback === "string" && fallback.length > 0) {+ cloudToken = fallback;+ }+ } catch (e) {+ console.warn("[enterprise] get_cloud_token failed:", e);+ }+ }+const headers: Record<string, string> = {"X-License-Key": licenseKey,"X-Device-Id": deviceId,@@ -312,14 +327,18 @@ export function useEnterprisePolicy() {// policy-fetch time).if (cloudToken) {try {- await commands.saveEnterpriseTeamConfig({- isAdmin: Boolean(data.isAdmin),- licenseActive: true,- teamApiToken: null,- });+ const adminFlag = Boolean(data.isAdmin);+ console.log(+ `[enterprise] persisting team config: is_admin=${adminFlag} (raw response.isAdmin=${data.isAdmin})`+ );+ await commands.saveEnterpriseTeamConfig(adminFlag, true, null);} catch (e) {console.warn("[enterprise] failed to persist team config:", e);}+ } else {+ console.warn(+ "[enterprise] no cloud token available — skipping team-config persist (sign in to screenpipe cloud to enable team queries)"+ );}return { ok: true, policy: result };} catch (e) {diff --git a/apps/screenpipe-app-tauri/lib/utils/tauri.ts b/apps/screenpipe-app-tauri/lib/utils/tauri.tsindex bef6b8ba7..ce5502fe8 100644--- a/apps/screenpipe-app-tauri/lib/utils/tauri.ts+++ b/apps/screenpipe-app-tauri/lib/utils/tauri.ts@@ -304,20 +304,43 @@ async saveEnterpriseLicenseKey(licenseKey: string) : Promise<Result<null, string}},/**- * Persist enterprise admin status + team API token (each independently- * optional) into `~/.screenpipe/enterprise.json`. Mirrors the Rust- * `save_enterprise_team_config` command. Specta will regenerate this- * binding on the next Tauri build — the hand-written stub here keeps- * TypeScript happy in the meantime.+ * Persist the user's enterprise admin status + team API token so the+ * pi-agent's `screenpipe-team` skill knows whether to install itself.+ *+ * Called by the frontend right after a policy fetch confirms admin+ * role. Storing this alongside the license key in `enterprise.json`+ * keeps everything pi-agent needs in one file the skill can read+ * without a Tauri round-trip.+ *+ * All fields are optional so callers can update one at a time —+ * e.g. revoke admin without wiping the cached team token, or refresh+ * just the token after a rotation. To FORCE a field to null, pass+ * an empty string for strings or `false` for `is_admin`/`license_active`.*/-async saveEnterpriseTeamConfig(args: { isAdmin?: boolean | null; licenseActive?: boolean | null; teamApiToken?: string | null }) : Promise<Result<null, string>> {+async saveEnterpriseTeamConfig(isAdmin: boolean | null, licenseActive: boolean | null, teamApiToken: string | null) : Promise<Result<null, string>> {try {- return { status: "ok", data: await TAURI_INVOKE("save_enterprise_team_config", args) };+ return { status: "ok", data: await TAURI_INVOKE("save_enterprise_team_config", { isAdmin, licenseActive, teamApiToken }) };} catch (e) {if(e instanceof Error) throw e;else return { status: "error", error: e as any };}},+/**+ * Read the user's screenpipe cloud session JWT from `~/.screenpipe/+ * auth.json`. Returns None when the file is missing, malformed, or the+ * token field is empty.+ *+ * The settings store (`store.bin → user.token`) is the canonical+ * runtime cache for this token but is only populated after a fresh+ * in-app sign-in. `auth.json` is the durable on-disk copy written by+ * the pi-agent configuration flow — it survives store resets and dev-+ * mode launches where the in-memory user object hasn't been hydrated+ * yet. Used by the enterprise-policy hook to send the Bearer header+ * even when the in-app user object is still null.+ */+async getCloudToken() : Promise<string | null> {+ return await TAURI_INVOKE("get_cloud_token");+},/*** Called by the frontend after fetching the enterprise policy.*/@@ -404,7 +427,7 @@ async hideMainWindow() : Promise<void> {},/*** E2E helper: emit a deterministic chat stream from the Rust side.- *+ ** This keeps chat performance tests close to production's Pi stdout path:* one backend command starts the stream, then the app emits `agent_event`* envelopes into the WebView. Tests avoid the extra WebView→Rust→WebView@@ -1570,13 +1593,13 @@ audioTranscriptionEngine: string;*/transcriptionMode: string;/**- * Stream live notes only while a meeting is active. This is separate- * from 24/7 background transcription: the recorder still writes durable- * chunks, while this powers the low-latency meeting note UI.+ * Stream live notes only for manually-started live meetings. This is+ * separate from 24/7 background transcription: the recorder still writes+ * durable chunks, while this powers the low-latency meeting note UI.*/meetingLiveTranscriptionEnabled: boolean;/**- * Provider for meeting-only live notes. Defaults to the selected audio+ * Provider for manually-started live notes. Defaults to the selected audio* transcription engine so local/custom engines work without Cloud.*/meetingLiveTranscriptionProvider: string;@@ -1607,7 +1630,7 @@ experimentalCoreaudioSystemAudio?: boolean;* Experimental: request Windows WASAPI microphone Acoustic Echo Cancellation.* Ignored on non-Windows platforms and fail-open when unsupported by device/driver.*/-windowsInputAecEnabled?: boolean;+windowsInputAecEnabled?: boolean;/*** Duration of each audio chunk in seconds before transcription.* Stored as i32 to match existing store.bin schema (cast to u64 by engine).@@ -1672,6 +1695,26 @@ disableSnapshotCompaction?: boolean;* in_meeting override flag stays false.*/disableMeetingDetector?: boolean;+/**+ * Override `EventDrivenCaptureConfig::idle_capture_interval_ms` (milliseconds).+ * None = follow active PowerProfile.+ */+idleCaptureIntervalMs?: bigint | null;+/**+ * Override `EventDrivenCaptureConfig::visual_check_interval_ms` (milliseconds).+ * None = follow active PowerProfile.+ */+visualCheckIntervalMs?: bigint | null;+/**+ * Override `EventDrivenCaptureConfig::visual_change_threshold` (0.0–1.0).+ * None = follow active PowerProfile.+ */+visualChangeThreshold?: number | null;+/**+ * Override `EventDrivenCaptureConfig::min_capture_interval_ms` (milliseconds).+ * None = follow active PowerProfile.+ */+minCaptureIntervalMs?: bigint | null;/*** Window titles to exclude from capture.*/diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rsindex 0b8c6b9d4..fba1acef1 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs@@ -662,6 +662,30 @@ pub fn save_enterprise_license_key(license_key: String) -> Result<(), String> {Ok(())}+/// Read the user's screenpipe cloud session JWT from `~/.screenpipe/+/// auth.json`. Returns None when the file is missing, malformed, or the+/// token field is empty.+///+/// The settings store (`store.bin → user.token`) is the canonical+/// runtime cache for this token but is only populated after a fresh+/// in-app sign-in. `auth.json` is the durable on-disk copy written by+/// the pi-agent configuration flow — it survives store resets and dev-+/// mode launches where the in-memory user object hasn't been hydrated+/// yet. Used by the enterprise-policy hook to send the Bearer header+/// even when the in-app user object is still null.+#[tauri::command]+#[specta::specta]+pub fn get_cloud_token() -> Option<String> {+ let path = screenpipe_core::paths::default_screenpipe_data_dir().join("auth.json");+ let raw = std::fs::read_to_string(&path).ok()?;+ let parsed: serde_json::Value = serde_json::from_str(&raw).ok()?;+ parsed+ .get("token")+ .and_then(|t| t.as_str())+ .filter(|s| !s.is_empty())+ .map(String::from)+}+/// Persist the user's enterprise admin status + team API token so the/// pi-agent's `screenpipe-team` skill knows whether to install itself.///diff --git a/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs b/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rsindex 5cc7f4a64..a5127d3f6 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/enterprise_sync.rs@@ -381,14 +381,25 @@ mod imp {.and_then(|h| h.into_string().ok()).unwrap_or_else(|| "unknown".to_string());- let cfg = match EnterpriseSyncConfig::from_env(+ // Resolve license key from the canonical file location the+ // in-app license prompt writes to (~/.screenpipe/enterprise.json,+ // or the MDM Resources/ copy). Without this the env-var-only+ // discovery in `from_env` silently no-ops on every standard+ // install — the telemetry pipeline would never start, even with+ // the dashboard fully configured.+ let license_fallback = crate::commands::get_enterprise_license_key();++ let cfg = match EnterpriseSyncConfig::from_env_with_fallback(app_data_dir,device_id.clone(),device_label.clone(),+ license_fallback,) {Some(c) => c,None => {- info!("enterprise sync: SCREENPIPE_ENTERPRISE_LICENSE_KEY not set, skipping");+ info!(+ "enterprise sync: no license key in env or ~/.screenpipe/enterprise.json — skipping"+ );return None;}};diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex b2cbd89ef..ba665673f 100755--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -739,6 +739,7 @@ async fn main() {commands::get_enterprise_license_key,commands::save_enterprise_license_key,commands::save_enterprise_team_config,+ commands::get_cloud_token,enterprise_policy::set_enterprise_policy,commands::get_disk_usage,commands::list_cache_files,@@ -1014,6 +1015,7 @@ async fn main() {enterprise_policy::set_enterprise_policy,commands::save_enterprise_license_key,commands::save_enterprise_team_config,+ commands::get_cloud_token,spawn_screenpipe,stop_screenpipe,recording::start_capture,diff --git a/apps/screenpipe-app-tauri/src-tauri/tauri.enterprise.conf.json b/apps/screenpipe-app-tauri/src-tauri/tauri.enterprise.conf.jsonindex 96bd65708..6ad87d743 100644--- a/apps/screenpipe-app-tauri/src-tauri/tauri.enterprise.conf.json+++ b/apps/screenpipe-app-tauri/src-tauri/tauri.enterprise.conf.json@@ -1,6 +1,6 @@{"$schema": "https://schema.tauri.app/config/2",- "productName": "screenpipe",+ "productName": "screenpipe enterprise","identifier": "screenpi.pe.enterprise","build": {"beforeDevCommand": "bun run dev",diff --git a/ee/desktop-rust/enterprise_sync.rs b/ee/desktop-rust/enterprise_sync.rsindex a153893a2..40403352d 100644--- a/ee/desktop-rust/enterprise_sync.rs+++ b/ee/desktop-rust/enterprise_sync.rs@@ -104,10 +104,27 @@ impl EnterpriseSyncConfig {app_data_dir: PathBuf,device_id: String,device_label: String,+ ) -> Option<Self> {+ Self::from_env_with_fallback(app_data_dir, device_id, device_label, None)+ }++ /// Same as `from_env` but lets the caller pass a license key resolved+ /// from somewhere else (e.g. `~/.screenpipe/enterprise.json` populated+ /// by the desktop's in-app prompt). Env var still wins when set — that+ /// keeps MDM rollouts working — but a missing env no longer disables+ /// enterprise sync when the user has signed in normally through the+ /// app. Without this fallback the entire telemetry pipeline silently+ /// no-ops because the license key lives in the file, not the shell.+ pub fn from_env_with_fallback(+ app_data_dir: PathBuf,+ device_id: String,+ device_label: String,+ license_key_fallback: Option<String>,) -> Option<Self> {let license_key = std::env::var("SCREENPIPE_ENTERPRISE_LICENSE_KEY").ok()- .filter(|s| !s.trim().is_empty())?;+ .filter(|s| !s.trim().is_empty())+ .or_else(|| license_key_fallback.filter(|s| !s.trim().is_empty()))?;let ingest_url = std::env::var("SCREENPIPE_ENTERPRISE_INGEST_URL").ok().filter(|s| !s.trim().is_empty())