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): screenpipe-team skill for admin chats over org telemetry

Louis Beaumont7871604adaef
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
index 434a5bb6d..0b8c6b9d4 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -662,6 +662,62 @@ pub fn save_enterprise_license_key(license_key: String) -> Result<(), String> {
Ok(())
}
+/// 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`.
+#[tauri::command]
+#[specta::specta]
+pub fn save_enterprise_team_config(
+ is_admin: Option<bool>,
+ license_active: Option<bool>,
+ team_api_token: Option<String>,
+) -> Result<(), String> {
+ let dir = screenpipe_core::paths::default_screenpipe_data_dir();
+ std::fs::create_dir_all(&dir).map_err(|e| format!("failed to create dir: {}", e))?;
+
+ let path = dir.join("enterprise.json");
+ let mut json = std::fs::read_to_string(&path)
+ .ok()
+ .and_then(|raw| serde_json::from_str::<serde_json::Value>(&raw).ok())
+ .unwrap_or_else(|| serde_json::json!({}));
+
+ if let Some(v) = is_admin {
+ json["is_admin"] = serde_json::Value::Bool(v);
+ }
+ if let Some(v) = license_active {
+ json["license_active"] = serde_json::Value::Bool(v);
+ }
+ let token_set = team_api_token.is_some();
+ if let Some(t) = team_api_token {
+ json["team_api_token"] = if t.is_empty() {
+ serde_json::Value::Null
+ } else {
+ serde_json::Value::String(t)
+ };
+ }
+
+ std::fs::write(&path, serde_json::to_string_pretty(&json).unwrap())
+ .map_err(|e| format!("failed to write {}: {}", path.display(), e))?;
+
+ info!(
+ "enterprise: team config saved to {} (is_admin set: {}, license_active set: {}, token set: {})",
+ path.display(),
+ is_admin.is_some(),
+ license_active.is_some(),
+ token_set
+ );
+ Ok(())
+}
+
#[tauri::command]
#[specta::specta]
pub fn write_browser_log(level: String, message: String) {
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index 0337c14f3..a650ef2b0 100755
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -737,6 +737,7 @@ async fn main() {
commands::set_cloud_media_analysis_skill,
commands::get_enterprise_license_key,
commands::save_enterprise_license_key,
+ commands::save_enterprise_team_config,
enterprise_policy::set_enterprise_policy,
commands::get_disk_usage,
commands::list_cache_files,
@@ -1011,6 +1012,7 @@ async fn main() {
commands::get_enterprise_license_key,
enterprise_policy::set_enterprise_policy,
commands::save_enterprise_license_key,
+ commands::save_enterprise_team_config,
spawn_screenpipe,
stop_screenpipe,
recording::start_capture,
diff --git a/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md b/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md
new file mode 100644
index 000000000..9569632ea
--- /dev/null
+++ b/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md
@@ -0,0 +1,109 @@
+---
+name: screenpipe-team
+description: Query the org's screenpipe telemetry as an enterprise admin — devices, members, recent activity, and substring search across the team's screen recordings and audio transcripts. Use when the user asks about their team, a teammate's activity, what their organization worked on, app usage across the org, or anything that requires seeing data beyond the user's own machine. The skill is only installed for enterprise admins; ordinary users won't see it.
+---
+
+# Screenpipe Team
+
+Query the customer's team telemetry. Data lives in the customer's own Azure Blob (or our R2 bucket for hosted ingest). All reads transit our control plane today (`https://screenpi.pe/api/enterprise/v1/*`) which checks the bearer's admin role and returns matched records. The model (you) is the user's own local pi-agent — your prompts and the user's chat never leave their machine.
+
+## 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:
+
+```bash
+TEAM_TOKEN=$(jq -r .team_api_token ~/.screenpipe/enterprise.json)
+SP_URL="https://screenpi.pe/api/enterprise/v1"
+```
+
+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.
+
+## Context window protection
+
+API responses can be large (matched OCR text + audio transcripts). **Always**:
+1. Write curl output to a file (`-o /tmp/sp_team_*.json`).
+2. Check size (`wc -c /tmp/sp_team_*.json`).
+3. If over ~5KB, extract with `jq` rather than dumping the file into context.
+4. Cite results by `t` (timestamp) and `device` (hostname or pseudonym) — don't quote multi-paragraph blocks.
+
+## Progressive disclosure
+
+Escalate from cheap to expensive:
+
+| Step | Endpoint | When |
+|------|----------|------|
+| 1 | `GET /devices` | Always start here when the user names a teammate — match the human to a `device_id`. |
+| 2 | `GET /search?q=...&since_hours_ago=24` | The user has a topic (e.g. "atlas", "q3 forecast"). Default 24h, narrow further if results are noisy. |
+| 3 | `GET /search?q=...&device_id=...` | Once you know whose data you want, scope to that device. |
+| 4 | `GET /records?device_id=...&since_hours_ago=4` | "Walk me through what X did between Y and Z" — chronological dump. Use AFTER you know the device + window from steps 1–3. |
+
+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
+jq '.devices[] | {device_id, label, platform, last_seen}' /tmp/sp_team_devices.json
+```
+
+Each device has:
+- `device_id` — the opaque id used by `/search` and `/records`
+- `label` — hostname OR pseudonym (e.g. `john-mbp` or `user_a3f201` for anonymous devices)
+- `last_seen` — ISO 8601; "offline" if older than ~30min
+- `platform`, `app_version` — for debugging stale clients
+
+When the user names a person ("what's john doing"), match against `label`. If multiple devices match, ask the user which one (or query all and aggregate).
+
+## 2. Search
+
+```bash
+curl -s -H "Authorization: Bearer $TEAM_TOKEN" \
+ "$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
+```
+
+### Parameters
+
+| Name | Description |
+|------|-------------|
+| `q` | Case-insensitive substring across app_name, window_name, frame text, audio transcription, speaker, device label, browser URL. Empty = all records in window. |
+| `device_id` | Restrict to one device. Get it from `/devices`. |
+| `app_name` | Exact match on app_name (case-insensitive), e.g. `Excel`, `Slack`. |
+| `since_hours_ago` | Default 24, max 720. Smaller = faster + cheaper. |
+| `since` / `until` | ISO 8601 alternatives to `since_hours_ago`. |
+| `limit` | Default 50, max 200. Keep small to protect context. |
+
+Response includes `truncated: true` if the byte budget was hit before the full window was scanned — narrow `q` or `since_hours_ago` and re-query rather than ask for `limit=200`.
+
+## 3. Records (chronological)
+
+```bash
+curl -s -H "Authorization: Bearer $TEAM_TOKEN" \
+ "$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
+```
+
+| Name | Description |
+|------|-------------|
+| `device_id` | Required-ish. Without it you get the whole org — usually noisy. |
+| `kind` | `frame` (screen) / `audio` / `all`. Default `all`. |
+| `since_hours_ago` / `since` / `until` | Time window. |
+| `limit` | Default 50, max 200. |
+
+Records come oldest-first so you can describe a chronological flow.
+
+---
+
+## Privacy & expectations
+
+- Some devices report as `user_xxxxxx` instead of a hostname — those users chose **anonymous** visibility. You can chat about them by pseudonym but should never speculate about their real identity. If the user asks "who is `user_a3f201`", say: that user opted into anonymous visibility and identity cannot be revealed without their consent.
+- Don't dump raw text in your reply when summarizing — quote short snippets, cite by timestamp + device.
+- Don't volunteer data the user didn't ask for. If they ask about engineering, don't include design.
+
+## When NOT to use this skill
+
+- The user is asking about **their own** machine → use `screenpipe-api` (queries `localhost:3030`).
+- The user isn't an admin → this skill shouldn't even be installed; if it is, the API will return 403 and you should tell them their license role doesn't permit team queries.
diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rs
index 14b9cb3a3..c9a240540 100644
--- a/crates/screenpipe-core/src/agents/pi.rs
+++ b/crates/screenpipe-core/src/agents/pi.rs
@@ -179,8 +179,83 @@ impl PiExecutor {
s
}
+ /// Install or wipe the `screenpipe-team` enterprise-admin skill in
+ /// `project_dir/.pi/skills/screenpipe-team/`.
+ ///
+ /// This skill teaches pi how to query org-wide telemetry (devices,
+ /// search, records) via `https://screenpi.pe/api/enterprise/v1/*`. It
+ /// MUST only be present when the user is an enterprise admin with an
+ /// active license, because exposing the prompts to non-admins is
+ /// misleading (every call would 403) and dropping it onto a personal
+ /// build leaks our enterprise affordances.
+ ///
+ /// Source of truth: `~/.screenpipe/enterprise.json`. The Tauri host
+ /// keeps that file populated with `{is_admin, license_active,
+ /// team_api_token, ...}` based on the user's current license + role.
+ /// We re-check on every pi-agent boot, so role downgrades + license
+ /// expirations wipe the skill automatically.
+ pub fn ensure_screenpipe_team_skill(project_dir: &Path) -> Result<()> {
+ let skill_dir = project_dir.join(".pi").join("skills").join("screenpipe-team");
+ let skill_path = skill_dir.join("SKILL.md");
+
+ let should_install = Self::is_enterprise_admin();
+
+ if should_install {
+ std::fs::create_dir_all(&skill_dir)?;
+ std::fs::write(
+ &skill_path,
+ include_str!("../../assets/skills/screenpipe-team/SKILL.md"),
+ )?;
+ debug!("screenpipe-team skill installed at {:?}", skill_path);
+ } else if skill_dir.exists() {
+ // Wipe the whole dir — defense against partial state if a user
+ // hand-edited or we ever ship sub-files in the future.
+ std::fs::remove_dir_all(&skill_dir)?;
+ info!(
+ "screenpipe-team skill removed (no longer an enterprise admin or license inactive)"
+ );
+ }
+
+ Ok(())
+ }
+
+ /// 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.
+ fn is_enterprise_admin() -> bool {
+ let path = match dirs::home_dir() {
+ Some(h) => h.join(".screenpipe").join("enterprise.json"),
+ None => return false,
+ };
+ let raw = match std::fs::read_to_string(&path) {
+ Ok(s) => s,
+ Err(_) => return false,
+ };
+ let parsed: serde_json::Value = match serde_json::from_str(&raw) {
+ Ok(v) => v,
+ 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.
+ let license_active = parsed
+ .get("license_active")
+ .and_then(|v| v.as_bool())
+ .unwrap_or(true);
+ let token_present = parsed
+ .get("team_api_token")
+ .and_then(|v| v.as_str())
+ .map(|s| !s.is_empty())
+ .unwrap_or(false);
+ is_admin && license_active && token_present
+ }
+
/// Ensure screenpipe skills exist in `project_dir/.pi/skills/`.
pub fn ensure_screenpipe_skill(project_dir: &Path) -> Result<()> {
+ // Always-on baseline skills (every pi-agent session needs these).
let api_skill = Self::render_screenpipe_api_skill();
let skills: &[(&str, &str)] = &[
("screenpipe-api", api_skill.as_str()),
@@ -221,6 +296,10 @@ impl PiExecutor {
debug!("{} skill installed at {:?}", name, skill_path);
}
+ // Conditional: enterprise admins get the team skill, others get it
+ // wiped if a stale copy exists (e.g. after a role downgrade).
+ Self::ensure_screenpipe_team_skill(project_dir)?;
+
Ok(())
}
@@ -289,6 +368,12 @@ impl PiExecutor {
}
}
+ // Enterprise-admin team skill is orthogonal to pipe permissions —
+ // it gates on the user's license role, not on what the pipe is
+ // allowed to do. Run it after the permission-filtered baseline so
+ // it correctly mirrors the user's current admin/license state.
+ Self::ensure_screenpipe_team_skill(project_dir)?;
+
Ok(())
}