20 Commits

Author SHA1 Message Date
Rohit Kushwaha
205ab3731b Merge branch 'ee' into feat/workspace-rbac-and-invite-flow 2026-04-15 13:40:05 +05:30
Rohit Kushwaha
d1b5870278 feat(ee-cloud): workspace RBAC consolidation + invite flow + visibility defaults
Consolidates the two parallel RBAC frameworks into a single route-level
authorization system and adds the missing pieces needed for a managed-onboarding
pilot: an endpoint to list pending invites, sane visibility defaults for
pockets/groups so invited teammates actually see shared work, and audit
logging on every denial.

RBAC consolidation
- New ACTIONS table (src/pocketpaw/ee/guards/actions.py) is the single source
  of truth for every guarded action → (minimum role, stable deny code).
  Covers workspace, group, message, pocket, agent, session, KB, invite,
  and billing — 32 rows total.
- New audit helpers (src/pocketpaw/ee/guards/audit.py): log_denial() +
  log_privileged_action() backed by the existing append-only audit log.
- New FastAPI deps: require_action(), require_action_any_workspace(),
  require_group_action(), require_membership(), require_agent_owner_or_admin(),
  require_pocket_edit(), require_pocket_owner().
- Route-level enforcement across workspace/chat/pockets/agents/sessions/kb
  routers; permission checks removed from service bodies where now redundant.
- Group role model extended to 3 tiers (owner > admin > member), with per-member
  override via Group.member_roles. Admin tier enforced via resolve_group_role()
  and the updated _require_group_admin helper.
- Legacy ee/cloud/shared/permissions.py deleted; legacy require_role shim
  removed from ee/cloud/shared/deps.py.
- Matrix test (tests/cloud/test_rbac_matrix.py) iterates every ACTIONS entry
  across every peer role, verifying both allow and deny paths and the exact
  Forbidden.code. Meta-test enforces coverage.
- Redundant tests/cloud/test_permissions.py removed.

Invite list endpoint
- GET /workspaces/{workspace_id}/invites returns all pending invites,
  admin-only via require_action("invite.create"). Wires the admin UX for
  listing + copy-link + revoke.

Visibility defaults
- Pocket.visibility default flipped "private" → "workspace" so new pockets
  are visible to all workspace members out of the box. Owners can tighten
  per-pocket via the Share tab.
- Group.type default flipped "public" → "private" so new groups are
  invite-only. Public channels remain explicit via type="channel" or "public".
- CreateGroupRequest and UpdateGroupRequest updated; GroupService.update_group
  now supports type changes. list_groups() treats "channel" same as "public"
  for workspace-wide readability.
- Existing tests updated to match new defaults.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 10:21:16 +05:30
Rohit Kushwaha
c3d59c7018 feat: add avatar uploads, channel type, and agent event streaming
- Add profile picture upload endpoints for agents and users
- Serve uploaded avatars from ~/.pocketpaw/uploads/ with static files mount
- Exempt /uploads paths from dashboard auth middleware
- Add "channel" to allowed group types in schema and model
- Stream agent tool_use and thinking events to WebSocket clients
- Add soul-protocol to enterprise dependencies

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 20:31:39 +05:30
Rohit Kushwaha
ff5bb0350a fix: resolve all 394 ruff lint errors
- Auto-fix 155 errors (import sorting, annotations, deprecated imports)
- Format 87 files with ruff format for line length compliance
- Fix 15 F401 unused imports (add __all__ for re-exports, remove truly unused)
- Fix 7 F841 unused variables (prefix with _)
- Fix 2 F821 undefined names (add missing imports)
- Fix 3 E402 module-level imports not at top
- Fix 2 UP042 str+Enum → StrEnum
- Fix 1 E712 == False comparison
- Fix remaining 51 E501 line-too-long in string literals and expressions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 10:08:58 +05:30
Prakash
fbaea85950 Reapply "Merge pull request #778 from pocketpaw/feat/close-critical-gaps"
This reverts commit 2b76f2acc6.
2026-04-10 17:42:15 +05:30
Prakash
2b76f2acc6 Revert "Merge pull request #778 from pocketpaw/feat/close-critical-gaps"
This reverts commit 5d16110ac3, reversing
changes made to 52ac737e1e.
2026-04-10 17:36:02 +05:30
Prakash
290f9b37d7 chore: merge base branch to resolve conflicts
Resolves one trivial conflict in dashboard_lifecycle.py — comment
wording difference ("Seed default admin user" vs "Seed default admin
user and workspace"). Took the base branch's more descriptive version.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 16:28:12 +05:30
Prakash
e5d10f8b7d refactor(cloud): split chat service, clean agent_bridge, add 66 E2E tests
Three targeted refactors based on clean architecture audit:

1. Split chat/service.py (658L) into focused modules:
   - group_service.py — GroupService + group helpers
   - message_service.py — MessageService + create_agent_message()
   - service.py — thin re-export for backward compat

2. Fix N+1 queries in _group_response() — batch $in queries
   replace per-member User.get() loops

3. Move pocket creation from agent_bridge to PocketService:
   - PocketService.create_from_ripple_spec() handles auto-creation
   - agent_bridge stays focused on agent orchestration + streaming

4. Add 66 E2E API tests covering auth, workspace, chat, pockets,
   sessions, and cross-domain flows against real MongoDB

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 12:59:45 +05:30
Rohit Kushwaha
e74d0eb6ed fix(cloud): fix syntax error in chat_persistence — missing except block
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 18:30:12 +05:30
Rohit Kushwaha
1f009ab282 feat(cloud): persist all runtime WebSocket chat messages to MongoDB
Chat persistence bridge that saves both user and agent messages to the
cloud Message collection regardless of which chat system produced them:

- User messages: saved via hook in WebSocket adapter handle_message()
- Agent responses: saved via outbound message bus subscriber (stream accumulation)
- Auto-creates cloud session + group for runtime WebSocket chats
- Session history endpoint now finds these messages via group_id

This unifies the two chat systems — runtime file memory + cloud MongoDB.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 18:20:29 +05:30
Rohit Kushwaha
4a590ec433 feat(cloud): auto-create pocket when agent generates ripple spec
When an agent's response contains a ripple UI spec, the bridge now
automatically creates a Pocket document with the spec, workspace
visibility, and agent attribution. The pocket_id is broadcast to
the group so the frontend can navigate to it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 17:38:24 +05:30
Rohit Kushwaha
1d90a7373e fix(cloud): inject knowledge into system prompt, not conversation history
The agent was ignoring knowledge because it was injected as fake
user/assistant messages in history. Now knowledge context is appended
to the system prompt with explicit instructions to use it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 16:15:38 +05:30
Rohit Kushwaha
0ca2335990 debug(cloud): add logging to agent bridge for troubleshooting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 15:33:02 +05:30
Rohit Kushwaha
4bebc62cf7 feat(knowledge): add KnowledgeEngine — scope-agnostic knowledge pipeline
Full knowledge engine with ingest → LLM compile → index → BM25 search:

- knowledge/models.py: RawDoc, WikiArticle, Concept, KnowledgeIndex, LintIssue
- knowledge/store.py: File-based wiki store (.md with frontmatter + index.json)
- knowledge/ingest.py: Text extraction from PDF, images, URLs, docx, text files
- knowledge/compiler.py: LLM compiles raw docs into structured wiki articles
- knowledge/indexer.py: Concept extraction, backlinks, categories
- knowledge/search.py: BM25 search over compiled wiki (no vector DB needed)
- knowledge/linter.py: LLM health checks — inconsistencies, gaps, suggestions
- knowledge/__init__.py: KnowledgeEngine public API

Scope-agnostic — works at any level:
  KnowledgeEngine(scope="agent:abc")
  KnowledgeEngine(scope="workspace:ws1")
  KnowledgeEngine(scope="pocket:p1")

Agent bridge now injects knowledge context before agent responses.
ee/cloud/agents/knowledge.py is now a thin wrapper over KnowledgeEngine.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 14:44:24 +05:30
Rohit Kushwaha
f1938ba75a feat(cloud): add agent bridge — triggers agents in groups, streams responses with ripple
- Agent bridge listens for message.sent events, checks respond_mode per agent
- Smart mode uses haiku-class LLM relevance check
- Responses stream via WebSocket (agent.stream_start/chunk/end)
- Ripple specs detected and attached to agent messages
- Pool lifecycle wired into app startup/shutdown
- message.sent event enriched with sender_type, mentions, workspace_id

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 12:38:23 +05:30
Rohit Kushwaha
e4a222c9b6 feat(cloud): wire domain architecture into serve.py, add event handlers, remove old code
Replace old cloud router mounting in v1/__init__.py and Socket.IO wrapping
in serve.py with unified mount_cloud() entry point. Delete 9 legacy files
(flat routers, deps, socketio_server, models/room). Add cross-domain event
handlers for invite acceptance, message stats, pocket sharing, and member
removal cleanup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 05:58:35 +05:30
Rohit Kushwaha
5489dc9855 feat(cloud): add shared db init and FastAPI dependencies
Move MongoDB/Beanie init logic to ee/cloud/shared/db.py (with
get_client accessor), make ee/cloud/db.py a backward-compat re-export.
Add ee/cloud/shared/deps.py with reusable FastAPI dependencies:
current_user, current_user_id, current_workspace_id,
optional_workspace_id, and require_role() factory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 05:16:27 +05:30
Rohit Kushwaha
fcbdb5e00d feat(cloud): add role and access level permission checks
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 05:14:51 +05:30
Rohit Kushwaha
a0a40f86ae feat(cloud): add internal async event bus for cross-domain side effects
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 05:09:30 +05:30
Rohit Kushwaha
a82ca931eb feat(cloud): add unified error hierarchy for cloud module
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 05:04:42 +05:30