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
revert(screenpipe-team): keep auto-detect via auth.json Clerk JWT
Louis Beaumont6279c1b07771
diff --git a/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md b/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.mdindex d84825431..108f41988 100644--- a/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md+++ b/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md@@ -9,25 +9,26 @@ Query the customer's team telemetry. Data lives in the customer's own Azure Blob## Auth-The skill uses an **enterprise API token** (format `sk_ent_…`) which the admin mints once on `https://screenpi.pe/enterprise?tab=tokens` with the `read:devices`, `read:search`, and `read:records` scopes. It's stored in `~/.screenpipe/enterprise.json` under the `team_api_token` key.+Two pieces, both already on disk after the admin signs in to screenpipe cloud — no separate token to mint or paste:++- **Cloud session JWT** from `~/.screenpipe/auth.json` (`.token`). This is a long-lasting Clerk JWT minted by the screenpipe-cloud sign-in flow (`getToken({template:"long-lasting"})`); the v1 endpoints validate it via Clerk and check the user's email against the license's `admin_emails`.+- **License key** from `~/.screenpipe/enterprise.json` (`.license_key`). Tells the server which org the admin wants to query (one user can admin multiple licenses).```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 $TEAM_TOKEN")+AUTH_HEADERS=(-H "Authorization: Bearer $CLOUD_TOKEN" -H "X-License-Key: $LICENSE_KEY")```-If `team_api_token` is null or empty, tell the user verbatim:--> I need an enterprise API token to query team data. Open-> https://screenpi.pe/enterprise?tab=tokens, create a token with the-> `read:devices`, `read:search`, `read:records` scopes, then either-> paste it into Settings → Enterprise → Team API token in the desktop-> app, or add it to `~/.screenpipe/enterprise.json` as `"team_api_token": "sk_ent_…"`.+If `CLOUD_TOKEN` doesn't start with `eyJ` (real Clerk JWT prefix — anything shorter like `sp-…` is leftover from an older auth scheme) OR if the v1 endpoints return **401 invalid bearer token**: tell the user verbatim:-Then stop. Don't try to call the endpoints — they'll 401.+> Your screenpipe cloud session looks stale (auth.json doesn't have a+> current Clerk JWT). Sign out and sign back into screenpipe cloud+> from the desktop app — that re-mints a long-lasting token, and the+> team skill works automatically afterward.-If the server returns 401 the token is invalid or revoked; tell the user to mint a new one. If it returns 403, the token is missing the required scope — same dashboard, regenerate with the right scopes.+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 protectiondiff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rsindex df841fed9..30ac7b998 100644--- a/crates/screenpipe-core/src/agents/pi.rs+++ b/crates/screenpipe-core/src/agents/pi.rs@@ -259,20 +259,27 @@ impl PiExecutor {.map(|s| !s.is_empty()).unwrap_or(false);- // The skill needs an enterprise API token (sk_ent_…, format- // accepted by `withApiAuth` on the v1 endpoints). Admins mint- // one on screenpi.pe/enterprise?tab=tokens and paste it into- // enterprise.json. We previously tried using the cloud session- // token from auth.json but that's an `sp-…` value the v1 auth- // layer doesn't validate; the team-token path is the one that- // currently works end-to-end.- let team_token_present = parsed- .get("team_api_token")- .and_then(|v| v.as_str())+ // The skill authenticates v1 calls with the long-lasting Clerk+ // JWT minted on screenpipe-cloud sign-in (cli-login.tsx →+ // getToken({ template: "long-lasting" })), persisted to+ // auth.json by the desktop's auth flow. Older installs may+ // have a stale `sp-…` API key in this slot from a prior auth+ // scheme — those will 401 against v1; the user has to sign+ // out + sign back in to mint a fresh JWT.+ //+ // We only gate skill install on token PRESENCE here, not+ // format — the validation happens server-side. The skill's own+ // bash blocks notice the 401 and surface a clear "re-sign-in"+ // message to the user.+ 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 && team_token_present+ is_admin && license_active && license_key_present && cloud_signed_in}/// Ensure screenpipe skills exist in `project_dir/.pi/skills/`.