Commit Graph

108 Commits

Author SHA1 Message Date
999c6ce55b docs(05-04): complete RBAC gap closure and wizard error fix plan
- Added 05-04-SUMMARY.md
- Updated STATE.md with decisions and session info
- Updated ROADMAP.md with Phase 5 plan progress (4/4 complete)
2026-03-24 20:52:31 -06:00
b287a95014 docs(05-employee-design): create gap closure plan for RBAC and error handling fixes 2026-03-24 20:50:30 -06:00
969cc4f917 docs(05-03): complete employee design human verification — Phase 5 complete 2026-03-24 20:42:19 -06:00
b917f7c54c docs(05-02): complete employee creation UI frontend plan
- Three-option entry screen, template gallery, 5-step wizard, advanced mode
- SUMMARY.md created with task commits, deviations, decisions
- STATE.md updated with decisions, metrics, session
- ROADMAP.md updated with phase 5 plan progress
- Requirements EMPL-01, EMPL-05 marked complete
2026-03-24 20:40:53 -06:00
c688b76c13 docs(05-01): complete agent templates backend plan — system prompt builder, migration 007, template API
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 20:33:44 -06:00
f9ce3d650f feat(05-01): template list/detail/deploy API + RBAC + integration tests
- Create shared/api/templates.py with templates_router
- GET /api/portal/templates: list active templates (any authenticated user)
- GET /api/portal/templates/{id}: get template detail (any authenticated user)
- POST /api/portal/templates/{id}/deploy: create Agent snapshot (tenant_admin only)
- customer_operator returns 403 on deploy (RBAC enforced)
- Export templates_router from shared/api/__init__.py
- Mount templates_router in gateway/main.py (Phase 5 section)
- 11 integration tests pass (list, detail, deploy, RBAC, 404, snapshot independence)
2026-03-24 20:32:30 -06:00
d1acb292a1 feat(05-01): AgentTemplate ORM model, migration 007, and system prompt builder
- Add AgentTemplate ORM model to tenant.py (global, not tenant-scoped)
- Create migration 007 with agent_templates table and 7 seed templates
- Create shared/prompts/system_prompt_builder.py with build_system_prompt()
- AI transparency clause always present (non-negotiable per Phase 1 decision)
- Unit tests pass (17 tests, all sections verified)
2026-03-24 20:27:54 -06:00
bffc1f2f67 docs(05-employee-design): create phase plan — 3 plans in 3 waves 2026-03-24 20:11:56 -06:00
5f0b74cf8c docs(05): add research and validation strategy 2026-03-24 20:05:39 -06:00
84d8059eac docs(phase-5): research employee design phase 2026-03-24 20:04:47 -06:00
40eb3106ab docs(state): record phase 5 context session 2026-03-24 19:59:49 -06:00
6a9516ed8b docs(05): capture phase context 2026-03-24 19:59:49 -06:00
03ec956379 docs: add Phase 5 — Employee Design wizard and agent templates 2026-03-24 19:33:23 -06:00
188ef4f6e1 fix: runtime deployment — CORS, Slack guard, litellm GitHub, CPU torch
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 19:31:57 -06:00
1b51499818 docs(phase-4): complete RBAC phase execution 2026-03-24 17:24:39 -06:00
279946a22a docs(04-rbac-03): finalize RBAC enforcement plan — human-verify checkpoint approved
- Task 3 (human-verify) approved — all 3 tasks complete
- SUMMARY.md updated: tasks 3/3, next phase readiness updated
- STATE.md stopped_at reflects full completion
- ROADMAP.md phase 4 progress confirmed 3/3 summaries complete

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 17:20:14 -06:00
94ada11fbd docs(04-rbac-03): complete RBAC API enforcement plan — guards, test-message endpoint, integration tests
- 17 portal API endpoints guarded with Depends() RBAC guards
- POST /agents/{aid}/test endpoint allows operators to QA agents
- GET /tenants/{tid}/users, GET /admin/users listing endpoints
- POST /admin/impersonate with AuditEvent audit trail
- 56 integration tests covering full RBAC matrix and invite flow
- STATE.md updated, ROADMAP.md phase 4 marked complete
Awaiting human-verify checkpoint (Task 3) before phase is fully done
2026-03-24 17:18:52 -06:00
9515c5374a test(04-rbac-03): add failing integration tests for RBAC enforcement and invite flow
RED phase — tests are written, will pass when connected to live DB.
Tests cover:
- Full RBAC matrix: platform_admin/customer_admin/operator on all endpoints
- Operator can POST /test but not POST /agents (create)
- Missing headers return 422
- Impersonation creates AuditEvent row
- Full invite flow: create -> accept -> login with correct role
- Expired invite rejection
- Resend generates new token and extends expiry
- Double-accept prevention
2026-03-24 17:16:13 -06:00
43b73aa6c5 feat(04-rbac-03): wire RBAC guards to all portal API endpoints + new endpoints
- Add require_platform_admin guard to GET/POST /tenants, PUT/DELETE /tenants/{id}
- Add require_tenant_member to GET /tenants/{id}, GET agents, GET agent/{id}
- Add require_tenant_admin to POST agents, PUT/DELETE agents
- Add require_tenant_admin to billing checkout and portal endpoints
- Add require_tenant_admin to channels slack/install and whatsapp/connect
- Add require_tenant_member to channels /{tid}/test
- Add require_tenant_admin to all llm_keys endpoints
- Add require_tenant_member to all usage GET endpoints
- Add POST /tenants/{tid}/agents/{aid}/test (require_tenant_member for operators)
- Add GET /tenants/{tid}/users with pending invitations (require_tenant_admin)
- Add GET /admin/users with tenant filter/role filter (require_platform_admin)
- Add POST /admin/impersonate with AuditEvent logging (require_platform_admin)
- Add POST /admin/stop-impersonation with AuditEvent logging (require_platform_admin)
2026-03-24 17:13:35 -06:00
e899b14fa7 docs(04-rbac-02): complete portal RBAC integration plan
- 04-02-SUMMARY.md: Auth.js JWT + role nav + tenant switcher + impersonation banner + user pages
- STATE.md: advanced to plan 3, metrics recorded, base-ui decisions added
- ROADMAP.md: phase 4 updated to 2/3 plans complete
- REQUIREMENTS.md: RBAC-05 marked complete
2026-03-24 17:08:50 -06:00
1fa4c3e3ad docs(04-rbac-01): complete RBAC foundation plan — migration, guards, invitations, tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 13:57:17 -06:00
7b0594e7cc test(04-rbac-01): unit tests for RBAC guards, invitation system, portal auth
- test_rbac_guards.py: 11 tests covering platform_admin pass-through,
  customer_admin/operator 403 rejection, tenant membership checks,
  and platform_admin bypass for tenant-scoped guards
- test_invitations.py: 11 tests covering HMAC token roundtrip,
  tamper/expiry rejection, invitation create/accept/resend/list
- test_portal_auth.py: 7 tests covering role field (not is_admin),
  tenant_ids list, active_tenant_id, platform_admin all-tenants,
  customer_admin own-tenants-only
- All 27 tests pass
2026-03-24 13:55:55 -06:00
d59f85cd87 feat(04-rbac-01): RBAC guards + invite token + email + invitation API
- rbac.py: PortalCaller dataclass + get_portal_caller dependency (header-based)
- rbac.py: require_platform_admin (403 for non-platform_admin)
- rbac.py: require_tenant_admin (platform_admin bypasses; customer_admin
  checks UserTenantRole; operator always rejected)
- rbac.py: require_tenant_member (platform_admin bypasses; all roles
  checked against UserTenantRole)
- invite_token.py: generate_invite_token (HMAC-SHA256, base64url, 48h TTL)
- invite_token.py: validate_invite_token (timing-safe compare_digest, TTL check)
- invite_token.py: token_to_hash (SHA-256 for DB storage)
- email.py: send_invite_email (sync smtplib, skips if smtp_host empty)
- invitations.py: POST /api/portal/invitations (create, requires tenant admin)
- invitations.py: POST /api/portal/invitations/accept (accept invitation)
- invitations.py: POST /api/portal/invitations/{id}/resend (regenerate token)
- invitations.py: GET /api/portal/invitations (list pending)
- portal.py: AuthVerifyResponse now returns role+tenant_ids+active_tenant_id
- portal.py: auth/register gated behind require_platform_admin
- tasks.py: send_invite_email_task Celery task (fire-and-forget)
- gateway/main.py: invitations_router mounted
2026-03-24 13:52:45 -06:00
f710c9c5fe feat(04-rbac-01): DB migration 006 + RBAC ORM models + config fields
- Migration 006: adds role TEXT+CHECK column to portal_users, backfills
  is_admin -> platform_admin/customer_admin, drops is_admin
- Migration 006: creates user_tenant_roles table (UNIQUE user_id+tenant_id)
- Migration 006: creates portal_invitations table with token_hash, status, expires_at
- PortalUser: replaced is_admin (bool) with role (str, default customer_admin)
- Added UserRole enum (PLATFORM_ADMIN, CUSTOMER_ADMIN, CUSTOMER_OPERATOR)
- Added UserTenantRole ORM model with FK cascade deletes
- Added PortalInvitation ORM model with token_hash unique constraint
- Settings: added invite_secret, smtp_host, smtp_port, smtp_username,
  smtp_password, smtp_from_email fields
2026-03-24 13:49:16 -06:00
2aecc5c787 fix(04-rbac): revise plans based on checker feedback 2026-03-24 13:46:03 -06:00
bf4adf0b21 docs(04-rbac): create phase plan — 3 plans in 3 waves 2026-03-24 13:37:36 -06:00
4706a87355 docs(04): add research and validation strategy 2026-03-24 13:28:17 -06:00
0dc21c6ee5 docs(04-rbac): research phase RBAC domain 2026-03-24 13:27:22 -06:00
dc758e9e3a docs(state): record phase 4 context session 2026-03-24 13:09:47 -06:00
52a30dd8e1 docs(04): capture phase context 2026-03-24 13:09:47 -06:00
7252845455 docs: add Phase 4 — RBAC with 3-tier roles and invitation flow
Three roles: platform admin (full SaaS), customer admin (tenant-scoped),
customer operator (read-only). Email invitation flow for tenant user
onboarding. 6 new requirements (RBAC-01 through RBAC-06).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 12:40:43 -06:00
0e0ea5fb66 fix: runtime deployment fixes for Docker Compose stack
- Add .gitignore for __pycache__, node_modules, .playwright-mcp
- Add CLAUDE.md project instructions
- docker-compose: remove host port exposure for internal services,
  remove Ollama container (use host), add CORS origin, bake
  NEXT_PUBLIC_API_URL at build time, run alembic migrations on
  gateway startup, add CPU-only torch pre-install
- gateway: add CORS middleware, graceful Slack degradation without
  bot token, fix None guard on slack_handler
- gateway pyproject: add aiohttp dependency for slack-bolt async
- llm-pool pyproject: install litellm from GitHub (removed from PyPI),
  enable hatch direct references
- portal: enable standalone output in next.config.ts
- Remove orphaned migration 003_phase2_audit_kb.py (renamed to 004)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 12:26:34 -06:00
d936bcf361 docs(phase-3): complete phase execution 2026-03-24 00:58:18 -06:00
80fd097e25 docs(03-05): complete gap closure plan — router wiring and field name fixes
- Add 03-05-SUMMARY.md
- Update STATE.md: advance metrics, record decision, update session
- Update ROADMAP.md: Phase 3 now shows 5/5 plans complete
2026-03-24 00:55:36 -06:00
7c8d219835 fix(03-05): fix Slack OAuth and budget alert field name mismatches
- Slack callback: check data.ok (not data.success) to match backend response
- SlackInstallResponse: use url + state fields (not authorize_url)
- connect-channel.tsx: update all authorize_url refs to url
- BudgetAlert: use current_usd (not current_cost_usd) to match backend Pydantic model
- usage page: update alert.current_cost_usd to alert.current_usd
2026-03-24 00:54:21 -06:00
c47cc2f5bf feat(03-05): mount Phase 3 API routers on gateway FastAPI app
- Import all 6 Phase 3 routers from shared.api (portal, billing, channels, llm_keys, usage, webhook)
- Add include_router() calls after existing whatsapp_router
- Update module docstring to document portal API endpoints
2026-03-24 00:53:32 -06:00
60c393b137 docs(03): create gap closure plan for router mounting and field name fixes 2026-03-23 22:39:34 -06:00
2416fe36b1 docs(03-04): mark plan complete after human-verify approval 2026-03-23 21:52:20 -06:00
f324beefba docs(03-02): mark plan complete — human-verify approved, state updated to 100%
- STATE.md: percent 86->100, position updated to all phases complete
- ROADMAP.md: Phase 3 Operator Experience marked 4/4 Complete
- Decisions from 03-02 added to accumulated context

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 21:52:08 -06:00
be61f94941 docs(03-03): complete billing management page plan — human-verify approved
- Updated SUMMARY.md: Task 2 (human-verify) marked approved, plan fully complete
- STATE.md: progress updated to 100%, decisions recorded, session updated
- ROADMAP.md: phase 3 plan progress updated (4/4 summaries complete)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 21:51:46 -06:00
521cec46f7 docs(03-02): complete onboarding wizard and BYO API key management plan
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 21:49:52 -06:00
b73f6bf7da docs(03-04): complete usage & cost dashboard plan
- Added Recharts cost tracking dashboard at /usage/[tenantId]
- UsageChart, ProviderCostChart, MessageVolumeChart components
- BudgetAlertBadge with ok/warning/exceeded color coding
- TanStack Query hooks for usage summary, provider costs, message volume, budget alerts
- Time range selector (Last 7/30 days, This month, Last 3 months)
- Usage nav link and /usage tenant picker index page
- Installed recharts (was in package.json but missing from node_modules)
- Portal builds cleanly with /usage and /usage/[tenantId] routes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 21:49:13 -06:00
11c1e52ea0 feat(03-02): onboarding wizard, Slack OAuth, WhatsApp connect, and BYO API keys UI
- Slack OAuth callback route handler (/api/slack/callback)
- Onboarding wizard: 3-step stepper (connect channel -> configure agent -> test message)
- Connect Channel: Slack OAuth button + WhatsApp manual credentials form
- Configure Agent: links to Agent Designer, Next enabled only with active agent
- Test Message: per-channel test buttons, required step, no separate Go Live button
- BYO API key management settings page at /settings/api-keys
- API Keys nav link in sidebar
- recharts installed (was missing, blocked portal build)
2026-03-23 21:48:06 -06:00
67632c11ce docs(03-03): complete billing management page plan — paused at human-verify checkpoint
- Billing page at /billing with SubscriptionCard, status badge, agent count +/- adjuster
- BillingStatus component with 6 subscription states (none/trialing/active/past_due/canceled/unpaid)
- TanStack Query mutation hooks: useCreateCheckoutSession, useCreateBillingPortalSession, useUpdateSubscriptionQuantity
- Billing nav link added to dashboard sidebar (CreditCard icon)
- Past-due warning banner and Checkout success toast with session_id URL cleanup
- Stopped at Task 2 checkpoint:human-verify awaiting visual confirmation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 21:47:31 -06:00
e0342f8ec1 docs(03-01): complete backend foundation plan — billing, encryption, HMAC OAuth, LLM key CRUD, usage aggregation
- Create 03-01-SUMMARY.md with full plan documentation
- Update STATE.md: progress 79%, 4 new decisions, session stopped at 03-01
- Update ROADMAP.md: Phase 3 plan progress (1/4 summaries)
- Update REQUIREMENTS.md: mark AGNT-07, LLM-03, PRTA-03, PRTA-05, PRTA-06 complete
2026-03-23 21:38:10 -06:00
3c8fc255bc feat(03-01): LLM key CRUD API endpoints with encryption
- Create llm_keys.py: GET list (redacted, key_hint only), POST (encrypt + store), DELETE (204 or 404)
- LlmKeyResponse never exposes encrypted_key or raw api_key
- 409 returned on duplicate (tenant_id, provider) key
- Cross-tenant deletion prevented by tenant_id verification in DELETE query
- Update api/__init__.py to export llm_keys_router
- All 5 LLM key CRUD tests passing (32 total unit tests green)
2026-03-23 21:36:08 -06:00
4cbf192fa5 feat(03-01): backend API endpoints — channels, billing, usage, and audit logger enhancement
- Create channels.py: HMAC-signed OAuth state generation/verification, Slack OAuth install/callback, WhatsApp manual connect, test message endpoint
- Create billing.py: Stripe Checkout session, billing portal session, webhook handler with idempotency (StripeEvent table), subscription lifecycle management
- Update usage.py: add _aggregate_rows_by_agent and _aggregate_rows_by_provider helpers (unit-testable without DB), complete usage endpoints
- Fix audit.py: rename 'metadata' attribute to 'event_metadata' (SQLAlchemy 2.0 DeclarativeBase reserves 'metadata')
- Enhance runner.py: audit log now includes prompt_tokens, completion_tokens, total_tokens, cost_usd, provider in LLM call metadata
- Update api/__init__.py to export all new routers
- All 27 unit tests passing
2026-03-23 21:24:08 -06:00
215e67a7eb feat(03-01): DB migrations, models, encryption service, and test scaffolds
- Add stripe and cryptography to shared pyproject.toml
- Add recharts, @stripe/stripe-js, stripe to portal package.json (submodule)
- Add billing fields to Tenant model (stripe_customer_id, subscription_status, agent_quota, trial_ends_at)
- Add budget_limit_usd to Agent model
- Create TenantLlmKey and StripeEvent models in billing.py (AuditBase and Base respectively)
- Create KeyEncryptionService (MultiFernet encrypt/decrypt/rotate) in crypto.py
- Create compute_budget_status helper in usage.py (threshold logic: ok/warning/exceeded)
- Add platform_encryption_key, stripe_, slack_oauth settings to config.py
- Create Alembic migration 005 with all schema changes, RLS, grants, and composite index
- All 12 tests passing (key encryption roundtrip, rotation, budget thresholds)
2026-03-23 21:19:09 -06:00
ac606cf9ff fix(03): revise plans based on checker feedback 2026-03-23 21:10:23 -06:00
1ff61d9ba4 docs(03-operator-experience): create phase plan 2026-03-23 21:03:30 -06:00