Commit Graph

43 Commits

Author SHA1 Message Date
bedd7d3470 feat(build): AI architecture recommendation with review + confirm flow
- New /api/projects/[projectId]/architecture (GET/POST/PATCH) — reads PRD
  + phases, calls AI to generate structured monorepo architecture JSON,
  persists to fs_projects.data.architecture; PATCH sets confirmed flag
- Rebuilt Build tab to show the AI-generated recommendation: expandable
  app cards (tech stack, key screens), shared packages, infrastructure,
  integrations, and risk notes; confirm button + "adjustable later" note

Made-with: Cursor
2026-03-03 21:02:06 -08:00
9e4450e400 Fix: strip tool messages from preloaded history (Gemini ordering error) + cast PRD param to text
Made-with: Cursor
2026-03-03 20:36:41 -08:00
5bfbe86541 feat: inline Save Phase button in Atlas chat when phase is complete
Made-with: Cursor
2026-03-02 20:24:08 -08:00
0146ae7df6 Persist Atlas chat history; fix re-greeting on refresh
- GET /api/projects/[id]/atlas-chat returns stored user+assistant messages
- POST handles __atlas_init__ trigger: runs once when no history exists,
  not stored as a user turn so Atlas intro appears cleanly
- Rewrite AtlasChat.tsx: fully self-contained component with own message
  state; loads history from DB on mount, only greets on first open
- Remove assistant-ui runtime dependency for message persistence
- Add Vision & Success Metrics, Integrations & Dependencies, Open Questions
  to PRD section tracker (now 12 sections matching the PDF)

Made-with: Cursor
2026-03-02 16:55:10 -08:00
7be66f60b7 fix: qualify table references in design-surfaces SQL to resolve ambiguous column error
Made-with: Cursor
2026-03-01 21:30:12 -08:00
62731af91f feat: design surfaces page with two-phase theme picker
Phase 1: user picks which surfaces their product needs (Web App,
Marketing Site, Admin, Mobile, Email, Docs). Phase 2: per-surface
horizontal card gallery with mini visual previews of each UI library.
Lock in confirms the choice; locked themes are saved to DB and shown
to the AI coder. Surfaces and themes stored in fs_projects.data.

Made-with: Cursor
2026-03-01 21:14:20 -08:00
287bc96fac feat: design packages page — pick UI library per Turborepo app
Replaces the old design page with a per-app package selector. Fetches
real apps/ from the project's Gitea repo and lets users assign a UI
library (shadcn, DaisyUI, HeroUI, Mantine, Headless UI, or Tailwind
only) independently per app. Selections saved to fs_projects.data.designPackages.

Made-with: Cursor
2026-03-01 20:33:39 -08:00
26a11412b5 feat: add Atlas discovery chat UI and API route
- components/AtlasChat.tsx — conversational PRD discovery UI (violet theme)
- app/api/projects/[projectId]/atlas-chat/route.ts — proxy + DB persistence
- overview/page.tsx — show Atlas for new projects, Orchestrator once PRD done

Made-with: Cursor
2026-03-01 15:56:32 -08:00
35675b7d86 fix: stop prisma from dropping custom tables on every deploy
entrypoint.sh: removed --accept-data-loss from prisma db push.
That flag was silently dropping fs_users, fs_projects etc. on every
container restart, wiping all user/project data. Made the push
non-fatal so a schema mismatch doesn't block startup.

create/route.ts: fixed same broken ON CONFLICT expression as
authOptions.ts — replaced with explicit SELECT + INSERT/UPDATE
to reliably upsert fs_users before inserting the project.

Made-with: Cursor
2026-02-27 19:15:55 -08:00
8c3486dd58 feat: persistent AI memory — chat history + knowledge store
agent-chat/route.ts:
- Loads conversation history from chat_conversations before each turn
- Passes history + knowledge context to agent runner
- Saves returned history back to chat_conversations after each turn
- Saves AI-generated memory updates to fs_knowledge_items

knowledge/route.ts (new):
- GET  /api/projects/[id]/knowledge — list all knowledge items
- POST /api/projects/[id]/knowledge — add/update item by key
- DELETE /api/projects/[id]/knowledge?id=xxx — remove item

OrchestratorChat.tsx:
- Added "Saved to memory" label for save_memory tool calls

Made-with: Cursor
2026-02-27 18:55:41 -08:00
b2b3424b05 fix: clean up orchestrator chat UX
- Tool call names now show human-readable labels ("Dispatched agent"
  instead of "spawn_agent"), deduped if called multiple times
- Model label only shown when a real value is returned; "unknown"
  and null are suppressed; model names shortened (GLM-5, Gemini)

Made-with: Cursor
2026-02-27 18:15:50 -08:00
fe89087cc5 fix: correct auth import path in agent-chat route
Was importing from @/lib/auth (which doesn't exist); correct path
is @/lib/auth/authOptions — this caused the Turbopack build to fail.

Made-with: Cursor
2026-02-27 18:09:22 -08:00
8d95a74cc6 add orchestrator chat to project overview
- OrchestratorChat component with Lovable-style UI (suggestion chips, reasoning panel, tool call badges)
- /api/projects/[projectId]/agent-chat proxy route to agent runner
- Injects project context (repo, vision, deployment URL) into session
- AGENT_RUNNER_URL wired to agents.vibnai.com

Made-with: Cursor
2026-02-27 18:06:02 -08:00
c9ef2379ec fix: upsert fs_users before inserting fs_projects to satisfy FK constraint
Made-with: Cursor
2026-02-27 13:36:25 -08:00
ef7a88e913 migrate: replace Firebase with PostgreSQL across core routes
- chat-context.ts: session history now from fs_sessions
- /api/sessions: reads from fs_sessions (NextAuth session auth)
- /api/github/connect: NextAuth session + stores in fs_users.data
- /api/user/api-key: NextAuth session + stores in fs_users.data
- /api/projects/[id]/vision: PATCH to fs_projects JSONB
- /api/projects/[id]/knowledge/items: reads from fs_knowledge_items
- /api/projects/[id]/knowledge/import-ai-chat: uses pg createKnowledgeItem
- lib/server/knowledge.ts: fully rewritten to use PostgreSQL
- entrypoint.sh: add fs_knowledge_items and chat_conversations tables

Made-with: Cursor
2026-02-27 13:25:38 -08:00
8587644a62 feat: turborepo monorepo scaffold and provisioning
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-21 16:44:37 -08:00
f4ab70822c fix: handle Gitea 409 on project create by linking to existing repo
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 17:16:24 -08:00
aeedc76a18 fix: correct authOptions import path in prewarm route
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 16:26:43 -08:00
1ff58049c0 feat: pass GITEA_TOKEN to IDE containers + prewarm on project list load
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 16:13:09 -08:00
aa2f5dbc3a feat: add Provision IDE button for projects without a workspace
- POST /api/projects/[id]/workspace: provisions a Cloud Run Theia service
  on demand and saves the URL to the project record
- overview/page.tsx: shows 'Provision IDE' button when theiaWorkspaceUrl
  is null, 'Open IDE' link once provisioned
- Also fixes log spam: retired Firebase session tracking endpoint (410 Gone)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 15:36:18 -08:00
81cca70542 fix: retire legacy Firebase session tracking endpoint
Returns 410 Gone instead of crashing with adminDb.collection errors.
Was flooding logs with TypeError on every call from the old Cursor extension.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 15:26:12 -08:00
e7f33211b9 feat: migrate Gemini from Vertex AI to Google AI Studio API key
- gemini-client.ts: replaces Vertex AI REST + service account auth with
  direct generativelanguage.googleapis.com calls using GOOGLE_API_KEY.
  Removes all Firebase credential setup code.
- summarize/route.ts: same migration, simplified to a single fetch call.
- No longer depends on gen-lang-client-0980079410 GCP project for AI calls.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 14:35:44 -08:00
106d9c5ff1 feat: switch workspace provisioning from Coolify to Cloud Run
- lib/cloud-run-workspace.ts: provisions per-project Theia workspaces as
  Cloud Run services (theia-{slug}), scales to zero when idle, starts in
  ~5-15s from cached image
- create/route.ts: imports cloud-run-workspace instead of coolify-workspace
- Image: northamerica-northeast1-docker.pkg.dev/master-ai-484822/vibn-ide/theia:latest
- Includes prewarmWorkspace() for near-zero perceived load time on login

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 14:01:02 -08:00
a22d5a0f18 feat: provision dedicated per-project Theia workspaces
- lib/coolify-workspace.ts: creates a Coolify docker-image app at
  {slug}.ide.vibnai.com for each project, patches in vibn-auth Traefik
  labels, sets env vars, and starts deployment
- create/route.ts: provisions Theia workspace after Gitea repo creation;
  stores theiaWorkspaceUrl + theiaAppUuid on the project record
- theia-auth/route.ts: for *.ide.vibnai.com hosts, verifies the
  authenticated user is the project owner (slug → fs_projects lookup)
- overview/page.tsx: Open IDE always links (dedicated URL or shared fallback)
- project-creation-modal.tsx: shows dedicated workspace URL in success screen

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 13:14:21 -08:00
e3a6641e3c fix: migrate AI chat system from Firebase/Firestore to Postgres
Firebase was not configured so every chat request crashed with
'Firebase Admin credentials not configured'.

- chat-mode-resolver.ts: read project phase from fs_projects (Postgres)
- chat-context.ts: load project data from fs_projects instead of Firestore
- /api/ai/conversation: store/retrieve conversations in chat_conversations
  Postgres table (created automatically on first use)
- /api/ai/chat: replace all Firestore reads/writes with Postgres queries
- v_ai_chat/page.tsx: replace Firebase client auth with useSession from
  next-auth/react; remove Firestore listeners, use REST API for project data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 12:07:03 -08:00
1146d8d129 fix: correct Theia ForwardAuth redirect loop
Two issues:
1. ForwardAuth redirect used x-forwarded-host which Traefik sets to
   vibnai.com (the auth service host), not theia.vibnai.com. Now
   hardcodes THEIA_URL as the callbackUrl destination.
2. /auth page ignored callbackUrl and always sent users to
   /marks-account/projects. Now follows callbackUrl when it points
   to theia.vibnai.com, so users land in the IDE after login.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 18:17:16 -08:00
d00979f89e fix: use rows array returned by query(), not result.rows
db-postgres.ts query() returns T[] directly, not a QueryResult object.
result.rows was undefined, causing the session lookup to always
return null and redirect to login even with a valid session token.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 17:39:41 -08:00
c410c1759a debug: add logging to theia-auth session lookup
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 17:35:56 -08:00
008b04d2dd debug: add ?debug=1 endpoint to theia-auth for cookie inspection
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 16:57:49 -08:00
28cd9dd776 fix: correct snake_case column names in session lookup SQL
Prisma maps sessionToken → session_token and userId → user_id
in the PostgreSQL sessions table. The forwardAuth query was using
the wrong camelCase column names.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 16:53:32 -08:00
efcf20b8f6 fix: validate Theia auth via direct Postgres session lookup
Avoid importing authOptions/PrismaClient in the forwardAuth endpoint.
Under --network host (Coolify's build flag), routes that import Prisma
at module evaluation time are silently dropped from the build output.

Instead, read the NextAuth session-token cookie directly and verify
it with a raw SQL query against the sessions table - the same pattern
used by other working API routes via @/lib/db-postgres.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 16:33:47 -08:00
b9baefed0b fix: use getServerSession instead of getToken in theia-auth
next-auth/jwt subpath import causes Next.js to silently drop the
route from the standalone build output. Switch to getServerSession
which is used by all other working API routes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 15:28:22 -08:00
4e6fcbc566 fix: move forwardAuth endpoint to /api/theia-auth
NextAuth catches all /api/auth/* routes via [...nextauth] catch-all.
Move the Traefik forwardAuth endpoint to /api/theia-auth to avoid
the conflict. Traefik dynamic config updated to match.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 15:13:29 -08:00
22bf34c4e0 feat: add Traefik forwardAuth endpoint for Theia IDE
POST /api/auth/theia-check validates the NextAuth session cookie
forwarded by Traefik. Returns 200 for authenticated users with
X-Auth-User/Email/Name headers, or 302 redirect to /auth for
unauthenticated requests — preserving the original Theia URL as
callbackUrl so users land back in the IDE after login.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 15:10:56 -08:00
373bcee8c1 feat: Gitea auto-provisioning and webhook context sync
- Add lib/gitea.ts: Gitea API client (createRepo, createWebhook,
  deleteRepo, verifyWebhookSignature)
- Add lib/coolify.ts: Coolify API client (projects, databases,
  applications, deployments)
- Update api/projects/create: auto-creates a private Gitea repo and
  registers a webhook on every new project; stores giteaRepo,
  giteaRepoUrl, giteaCloneUrl, giteaSshUrl, giteaWebhookId in project
  data; Gitea errors are non-fatal so project creation still succeeds
- Add api/webhooks/gitea: handles push, pull_request, issues events;
  verifies HMAC signature; updates contextSnapshot on project record
- Add api/webhooks/coolify: handles deployment status events; updates
  contextSnapshot.lastDeployment on project record

Requires env vars: GITEA_API_URL, GITEA_API_TOKEN, GITEA_ADMIN_USER,
GITEA_WEBHOOK_SECRET, COOLIFY_URL, COOLIFY_API_TOKEN

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 14:48:46 -08:00
f7bbf2ea5e feat: rewrite project delete to use NextAuth session + Postgres 2026-02-18 01:24:49 +00:00
59415bb0d9 feat: rewrite project GET/PATCH to use NextAuth session + Postgres 2026-02-18 01:24:48 +00:00
710a24a2fb feat: rewrite project create to use NextAuth session + Postgres 2026-02-18 01:24:47 +00:00
3fa242076b feat: add GET /api/projects using NextAuth + Postgres 2026-02-18 01:24:46 +00:00
bbb22f1c37 Switch from SuperTokens to NextAuth.js
BREAKING CHANGE: Replace SuperTokens with NextAuth.js

Why:
- SuperTokens had persistent Traefik routing issues
- SSL certificate not issuing correctly
- Complex infrastructure (separate container)
- NextAuth runs in Next.js app (simpler, no separate service)

Changes:
- Install next-auth, @auth/prisma-adapter, prisma
- Create NextAuth API route: app/api/auth/[...nextauth]/route.ts
- Add Prisma schema for NextAuth tables (users, sessions, accounts)
- Update auth page to use NextAuth signIn()
- Remove all SuperTokens code and dependencies
- Keep same Google OAuth (just simpler integration)

Benefits:
- No separate auth service needed
- No Traefik routing issues
- Sessions stored in Montreal PostgreSQL
- Simpler configuration
- Battle-tested, widely used

All authentication data stays in Montreal!

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-17 15:12:21 -08:00
44895f9c31 Fix SuperTokens build error with lazy initialization
- Move SuperTokens.init() to runtime (not build time)
- Add dynamic route config to prevent build-time evaluation
- Move appInfo inside backendConfig function
- Update default URLs to vibnai.com

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-16 17:22:41 -08:00
6764c1feb0 Add SuperTokens authentication integration
- Install supertokens-auth-react, supertokens-node, supertokens-web-js
- Create frontend and backend SuperTokens configuration
- Add API route handler for auth endpoints
- Add SuperTokensProvider wrapper in root layout
- Create new auth component with SuperTokens UI
- Configure Google and GitHub OAuth providers
- Ready for SuperTokens core deployment

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-16 15:27:40 -08:00
40bf8428cd VIBN Frontend for Coolify deployment 2026-02-15 19:25:52 -08:00