mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
## W4: team collaboration on Orca Cloud workspaces ### Control plane (`cloud/apps/sandbox-control`) - **Registry** (`0024_workspace_registry.sql`, applied on dev D1): owner (reassignable), `created_by`, branch, `visibility` (private default / team), section, last activity, token spend. Reuses 0020's `name`/`archived_at`. - **Routes under `/v1/team/*`** (W5 owns `/v1/workspaces`): list with Mine/Team/All, By, In, Archived filters; PATCH (rename, share or make private, section, archive, reassign owner); presence heartbeats; wake and lease for teammates; links resolve; org prompts/PR instructions (compare-and-set). - **Security fix:** `/v1/sandboxes/:id` used to be account-scoped, so any org member could resume a teammate's sandbox and receive its orcad pairing code. It is now owner-only; admins can still suspend and destroy. - **Per-member, per-device E2EE grants:** - The VM mints a single-device orcad offer and seals it to the requesting device's X25519 key. - The control plane stores only the orcad device id. - Revocation runs `orca pair --revoke`, which closes the device's live sockets, plus an on-disk registry removal. - When the VM is asleep, the revoke is queued and applied at boot before orcad starts. - Triggers: explicit revoke, making a workspace private, archive, reassign, member removal (internal route), and phone device-session revoke (W8). - VMs from older images get the entry points installed on demand. - **Git as the sender:** a member's own GitHub user-to-server token (App OAuth, envelope-encrypted) is swapped in at egress only for the workspace repo. The VM gets per-member git configs and `orca-git-as`. - **Cost:** metered compute × billing rate, plus optional token spend. ### orcad (generic) - New owner-only RPC `pairing.revokeDevice` and `orca pair --revoke <device-id>`: revokes a device and closes its open connections immediately. ### Desktop - A "Cloud workspaces" section on Home: Team/Mine, By, In and Archived filters; sections; live presence; cost; last activity. Single-click Open on a teammate workspace pairs this device through an E2EE grant. Also a row menu (share/private, move to section, reassign, archive) and copy link. - Deep links `orca://cloud/w/<id>[/c/<chat>]` (open-url, argv, second instance, sidecar handoff) and the `cloudWorkspace.copyLink` keybinding. - Messages to agents in shared workspaces carry a sender envelope. - Uses the W10 shared primitives. - Two rounds of adversarial design and frontend review. ### Evidence Real Vercel VMs; see the W4 report. Numbers: - grant issued in 0.55 s, paired in 1.35 s - revoke closes the live desktop socket ~30 ms after the PATCH returns - two members' pushes land on GitHub with their own author identities (shared dev Worker, preview alias w4); a push to another repo gets 403
80 lines
3.6 KiB
SQL
80 lines
3.6 KiB
SQL
-- Team workspace registry. A sandbox row is the cloud-owned record of one workspace: who made it,
|
|
-- who owns it now (`user_id`, reassignable), who in the org can see it. Name and archive reuse
|
|
-- `name` / `archived_at` from 0020 (W5); routine-made rows (`hidden`) stay out of team lists.
|
|
ALTER TABLE sandboxes ADD COLUMN created_by TEXT;
|
|
ALTER TABLE sandboxes ADD COLUMN repo_branch TEXT;
|
|
-- private (default): owner only. team: every member of the owning org can see and open it.
|
|
ALTER TABLE sandboxes ADD COLUMN visibility TEXT NOT NULL DEFAULT 'private';
|
|
ALTER TABLE sandboxes ADD COLUMN section TEXT;
|
|
ALTER TABLE sandboxes ADD COLUMN last_activity_at INTEGER;
|
|
ALTER TABLE sandboxes ADD COLUMN last_activity_by TEXT;
|
|
-- Optional model spend the workspace's agents reported (USD micros); null = never reported.
|
|
ALTER TABLE sandboxes ADD COLUMN token_usd_micros INTEGER;
|
|
UPDATE sandboxes SET created_by = user_id WHERE created_by IS NULL;
|
|
CREATE INDEX sandboxes_account_visibility ON sandboxes (account_id, visibility, status);
|
|
|
|
-- Who is looking at / typing in a workspace right now. Heartbeat rows; stale after 45 s.
|
|
CREATE TABLE workspace_presence (
|
|
sandbox_id TEXT NOT NULL,
|
|
user_id TEXT NOT NULL,
|
|
-- one row per member device, so two laptops of one member do not flap each other
|
|
client_id TEXT NOT NULL,
|
|
state TEXT NOT NULL CHECK (state IN ('viewing', 'typing')),
|
|
chat_id TEXT,
|
|
updated_at INTEGER NOT NULL,
|
|
PRIMARY KEY (sandbox_id, user_id, client_id)
|
|
);
|
|
CREATE INDEX workspace_presence_recent ON workspace_presence (sandbox_id, updated_at);
|
|
|
|
-- Per-member, per-device access to a workspace's orcad. The pairing offer itself never lands here:
|
|
-- the VM seals it to the requesting device's X25519 key, and only the device id is recorded so the
|
|
-- grant can be revoked (removed from orcad's device registry) later.
|
|
CREATE TABLE workspace_grants (
|
|
id TEXT PRIMARY KEY,
|
|
sandbox_id TEXT NOT NULL REFERENCES sandboxes (id),
|
|
account_id TEXT NOT NULL,
|
|
user_id TEXT NOT NULL,
|
|
device_kind TEXT NOT NULL CHECK (device_kind IN ('desktop', 'mobile')),
|
|
device_label TEXT NOT NULL,
|
|
-- orcad device id from the minted offer; null until the VM answered.
|
|
orcad_device_id TEXT,
|
|
-- issuing | active | revoking (queued: applied at next boot) | revoked | failed
|
|
status TEXT NOT NULL,
|
|
created_at INTEGER NOT NULL,
|
|
revoked_at INTEGER,
|
|
revoked_by TEXT,
|
|
revoke_reason TEXT,
|
|
-- Phone device session that requested it (W8); revoking the session revokes its grants.
|
|
device_session_id TEXT
|
|
);
|
|
CREATE INDEX workspace_grants_sandbox ON workspace_grants (sandbox_id, status);
|
|
CREATE INDEX workspace_grants_user ON workspace_grants (account_id, user_id, status);
|
|
|
|
-- Org-synced prompts and PR instructions (simple key/value documents per org account).
|
|
CREATE TABLE org_prompts (
|
|
account_id TEXT PRIMARY KEY,
|
|
-- JSON: {prompts:[{id,name,body}], prInstructions}
|
|
document TEXT NOT NULL,
|
|
revision INTEGER NOT NULL,
|
|
updated_at INTEGER NOT NULL,
|
|
updated_by TEXT NOT NULL
|
|
);
|
|
|
|
-- Per-member GitHub user-to-server tokens (GitHub App OAuth), envelope-encrypted like secrets.
|
|
-- They never enter a VM: the egress proxy swaps a member placeholder for the token, only for the
|
|
-- workspace repository, so pushes land on GitHub as the member who made them.
|
|
CREATE TABLE github_user_tokens (
|
|
account_id TEXT NOT NULL,
|
|
user_id TEXT NOT NULL,
|
|
github_user_id INTEGER NOT NULL,
|
|
github_login TEXT NOT NULL,
|
|
github_name TEXT,
|
|
kek_id TEXT NOT NULL,
|
|
wrapped_dek TEXT NOT NULL,
|
|
ciphertext TEXT NOT NULL,
|
|
access_expires_at INTEGER,
|
|
refresh_expires_at INTEGER,
|
|
updated_at INTEGER NOT NULL,
|
|
PRIMARY KEY (account_id, user_id)
|
|
);
|