Skip to content

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

feat(enterprise): zero-setup screenpipe-team skill — auto-detect admin

Louis Beaumonte8725c7dfc2d
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts b/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts
index 4493e09b9..2a275ad6c 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-enterprise-policy.ts
@@ -215,17 +215,33 @@ export function useEnterprisePolicy() {
const fetchPolicy = useCallback(async (licenseKey: string): Promise<FetchResult> => {
try {
- // Include device ID for pipe targeting
+ // Include device ID for pipe targeting + cloud session JWT so the
+ // server can tell us whether the signed-in user is an admin of this
+ // license. The admin bit gates installation of the screenpipe-team
+ // skill in the desktop pi-agent — see `Pi::is_enterprise_admin`.
let deviceId = "unknown";
+ let cloudToken: string | null = null;
try {
const store = await getStore();
const settings = (await store.get<Record<string, unknown>>("settings")) || {};
deviceId = (settings.deviceId as string) || "unknown";
+ const user = settings.user as Record<string, unknown> | undefined;
+ const token = user?.token;
+ if (typeof token === "string" && token.length > 0) {
+ cloudToken = token;
+ }
} catch {}
+ const headers: Record<string, string> = {
+ "X-License-Key": licenseKey,
+ "X-Device-Id": deviceId,
+ };
+ if (cloudToken) {
+ headers["Authorization"] = `Bearer ${cloudToken}`;
+ }
const res = await tauriFetch("https://screenpi.pe/api/enterprise/policy", {
method: "GET",
- headers: { "X-License-Key": licenseKey, "X-Device-Id": deviceId },
+ headers,
});
if (res.status === 401 || res.status === 402) {
console.error(`[enterprise] policy fetch: key rejected (${res.status})`);
@@ -286,6 +302,25 @@ export function useEnterprisePolicy() {
} catch (e) {
console.warn("[enterprise] failed to push policy to Rust:", e);
}
+
+ // Persist admin status into ~/.screenpipe/enterprise.json so the
+ // pi-agent can decide whether to install the screenpipe-team skill
+ // on its next boot. Only meaningful when we sent a cloud token in
+ // the request — without one, the server has no way to identify the
+ // user, so `data.isAdmin` is always false (don't accidentally wipe
+ // an existing admin marker just because the user was signed-out at
+ // policy-fetch time).
+ if (cloudToken) {
+ try {
+ await commands.saveEnterpriseTeamConfig({
+ isAdmin: Boolean(data.isAdmin),
+ licenseActive: true,
+ teamApiToken: null,
+ });
+ } catch (e) {
+ console.warn("[enterprise] failed to persist team config:", e);
+ }
+ }
return { ok: true, policy: result };
} catch (e) {
console.error("[enterprise] policy fetch error:", e);
diff --git a/apps/screenpipe-app-tauri/lib/utils/tauri.ts b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
index 84a822247..bef6b8ba7 100644
--- a/apps/screenpipe-app-tauri/lib/utils/tauri.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
@@ -303,6 +303,21 @@ async saveEnterpriseLicenseKey(licenseKey: string) : Promise<Result<null, string
else return { status: "error", error: e as any };
}
},
+/**
+ * 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.
+ */
+async saveEnterpriseTeamConfig(args: { 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) };
+} catch (e) {
+ if(e instanceof Error) throw e;
+ else return { status: "error", error: e as any };
+}
+},
/**
* Called by the frontend after fetching the enterprise policy.
*/
diff --git a/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md b/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md
index 9569632ea..1e7927c95 100644
--- a/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md
+++ b/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md
@@ -9,14 +9,23 @@ Query the customer's team telemetry. Data lives in the customer's own Azure Blob
## Auth
-All requests use the enterprise API token stored in `~/.screenpipe/enterprise.json` under the `team_api_token` key. Pull it once per session into a shell variable so you don't `jq` the file on every call:
+Two pieces, both already on disk — no separate token to paste:
+
+- **Cloud session JWT** from `~/.screenpipe/auth.json` (`.token`) — the same signed-in identity that powers cloud transcription and the chat proxy. The server validates this via Clerk; only admins of the license get past the check, non-admins get 403.
+- **License key** from `~/.screenpipe/enterprise.json` (`.license_key`) — tells the server which org the admin wants to query (one user can admin multiple).
+
+Pull both once per session into shell vars so you don't `jq` the files on every call:
```bash
-TEAM_TOKEN=$(jq -r .team_api_token ~/.screenpipe/enterprise.json)
+CLOUD_TOKEN=$(jq -r .token ~/.screenpipe/auth.json)
+LICENSE_KEY=$(jq -r .license_key ~/.screenpipe/enterprise.json)
SP_URL="https://screenpi.pe/api/enterprise/v1"
+AUTH_HEADERS=(-H "Authorization: Bearer $CLOUD_TOKEN" -H "X-License-Key: $LICENSE_KEY")
```
-If `team_api_token` is null or missing, tell the user: "I need an enterprise API token with the `read:devices`, `read:search`, `read:records` scopes. Generate one at https://screenpi.pe/enterprise?tab=tokens and paste it into Settings → Enterprise → Team API token." Don't proceed.
+If either is empty / null, tell the user: "I need you to be signed in to screenpipe cloud AND have an active enterprise license. Open the app's enterprise settings to check." Don't proceed.
+
+If the server returns 403 ("not an admin of this license"): tell the user "you're not listed as an admin on this license — ask whoever owns the license to add your email under enterprise → members".
## Context window protection
@@ -44,7 +53,7 @@ Default `since_hours_ago` to 24 unless the user implies otherwise. Max 720 (30d)
## 1. List devices
```bash
-curl -s -H "Authorization: Bearer $TEAM_TOKEN" "$SP_URL/devices" -o /tmp/sp_team_devices.json
+curl -s "${AUTH_HEADERS[@]}" "$SP_URL/devices" -o /tmp/sp_team_devices.json
jq '.devices[] | {device_id, label, platform, last_seen}' /tmp/sp_team_devices.json
```
@@ -59,7 +68,7 @@ When the user names a person ("what's john doing"), match against `label`. If mu
## 2. Search
```bash
-curl -s -H "Authorization: Bearer $TEAM_TOKEN" \
+curl -s "${AUTH_HEADERS[@]}" \
"$SP_URL/search?q=atlas&since_hours_ago=24&limit=20" -o /tmp/sp_team_search.json
jq '.results[] | {t, device, app, window, snippet: (.text // .transcription // "")[0:160]}' /tmp/sp_team_search.json
```
@@ -80,7 +89,7 @@ Response includes `truncated: true` if the byte budget was hit before the full w
## 3. Records (chronological)
```bash
-curl -s -H "Authorization: Bearer $TEAM_TOKEN" \
+curl -s "${AUTH_HEADERS[@]}" \
"$SP_URL/records?device_id=DEVICE&since_hours_ago=4&kind=frame&limit=100" \
-o /tmp/sp_team_records.json
jq '.records[] | {t, app, window, text: (.text // "")[0:120]}' /tmp/sp_team_records.json
diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rs
index c9a240540..6c2e35c4d 100644
--- a/crates/screenpipe-core/src/agents/pi.rs
+++ b/crates/screenpipe-core/src/agents/pi.rs
@@ -220,15 +220,23 @@ impl PiExecutor {
}
/// True when `~/.screenpipe/enterprise.json` declares this user as an
- /// active admin. Conservative: any I/O or parse error means "no" so we
- /// fail closed — we'd rather under-install the skill than show team
- /// affordances to someone who shouldn't see them.
+ /// active admin AND the user is signed into screenpipe cloud (the
+ /// Clerk JWT at `~/.screenpipe/auth.json` is what authenticates the
+ /// skill's HTTP calls to `screenpi.pe/api/enterprise/v1`).
+ ///
+ /// Conservative: any I/O or parse error means "no" so we fail closed —
+ /// we'd rather under-install the skill than show team affordances to
+ /// someone who shouldn't see them. Even if the skill DID get installed
+ /// to a non-admin, the server-side `authorizeApiRequest` re-checks
+ /// admin status on every call and returns 403, so this client-side
+ /// check is defense-in-depth, not the security boundary.
fn is_enterprise_admin() -> bool {
- let path = match dirs::home_dir() {
- Some(h) => h.join(".screenpipe").join("enterprise.json"),
+ let home = match dirs::home_dir() {
+ Some(h) => h,
None => return false,
};
- let raw = match std::fs::read_to_string(&path) {
+ let ent_path = home.join(".screenpipe").join("enterprise.json");
+ let raw = match std::fs::read_to_string(&ent_path) {
Ok(s) => s,
Err(_) => return false,
};
@@ -237,20 +245,31 @@ impl PiExecutor {
Err(_) => return false,
};
let is_admin = parsed.get("is_admin").and_then(|v| v.as_bool()).unwrap_or(false);
- // license_active defaults to true if the field is absent, so older
- // enterprise.json files (which only carry license_key) don't lose
- // skill access. The website-side claim flow can start writing
- // `license_active: false` explicitly when a license lapses.
+ // license_active defaults to true if the field is absent so older
+ // enterprise.json files don't lose skill access on upgrade. The
+ // website-side claim flow writes `license_active: false` when a
+ // license lapses.
let license_active = parsed
.get("license_active")
.and_then(|v| v.as_bool())
.unwrap_or(true);
- let token_present = parsed
- .get("team_api_token")
+ let license_key_present = parsed
+ .get("license_key")
.and_then(|v| v.as_str())
.map(|s| !s.is_empty())
.unwrap_or(false);
- is_admin && license_active && token_present
+
+ // The skill needs the cloud session JWT (auth.json) to talk to
+ // screenpi.pe — no token means no session, means no admin.
+ let auth_path = home.join(".screenpipe").join("auth.json");
+ let cloud_signed_in = std::fs::read_to_string(&auth_path)
+ .ok()
+ .and_then(|raw| serde_json::from_str::<serde_json::Value>(&raw).ok())
+ .and_then(|v| v.get("token").and_then(|t| t.as_str()).map(String::from))
+ .map(|s| !s.is_empty())
+ .unwrap_or(false);
+
+ is_admin && license_active && license_key_present && cloud_signed_in
}
/// Ensure screenpipe skills exist in `project_dir/.pi/skills/`.