Commit Graph

86 Commits

Author SHA1 Message Date
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
3ce10dc45b fix: remove SSL for internal Docker DB connections — fixes 500 on projects API
Made-with: Cursor
2026-02-27 13:01:57 -08:00
0625943cc1 fix: remove SSL from internal DB connection in entrypoint
Made-with: Cursor
2026-02-27 12:51:50 -08:00
cb0ece541f fix: ensure fs_ app tables created on every startup via node/pg
Made-with: Cursor
2026-02-27 12:48:02 -08:00
d8ead667d0 fix: create fs_user on sign-in, fix projects fetch
Made-with: Cursor
2026-02-27 12:39:25 -08:00
17056ea00c fix: restore auth fixes — next-auth prisma adapter, serverExternalPackages, prisma db push on start
Made-with: Cursor
2026-02-27 12:30:52 -08:00
8e6406232d fix: pass GOOGLE_API_KEY to Cloud Run workspace services
Without this, Theia's startup script could not configure Gemini AI
features or write the correct settings.json (dark theme, API key).
New workspaces now receive GOOGLE_API_KEY from the vibn-frontend env.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 11:50:55 -08:00
6eaa6d64ac feat: add Code OS project-info prompt template to scaffold
Adds .prompts/project-info.prompttemplate to the Turborepo scaffold so
every new user project gets a customized context file loaded by the Code
OS agent — including build commands, workspace structure, and shared
package import paths with the project's actual slug injected.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-21 17:27:34 -08:00
91f579dbc5 fix: add pnpm-workspace.yaml, .node-version, remove npm workspaces from scaffold
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-21 16:55:49 -08:00
8587644a62 feat: turborepo monorepo scaffold and provisioning
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-21 16:44:37 -08:00
e22f5e379f chore: remove test file 2026-02-22 00:36:35 +00:00
1154592ab8 test: add test file 2026-02-22 00:35:43 +00:00
b42edbe681 fix: handle Cloud Run 409 by linking to existing service; show provisioning spinner not failure
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 17:31:01 -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
97df21883b fix: remove name field from Cloud Run create body (v2 API requires empty)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 15:59:12 -08:00
c68152d999 fix: base64-encode SA key to survive Docker ARG special chars
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 15:48:41 -08:00
68f844ce52 fix: use service account key for Cloud Run workspace provisioning
GCE metadata tokens lack the cloud-platform OAuth scope, causing 403
PERMISSION_DENIED when creating Cloud Run services. Use an explicit JWT
from GOOGLE_SERVICE_ACCOUNT_KEY env var when present, with ADC as fallback.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 15:45:51 -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
783700a7db feat: add proper marketing footer with privacy/terms links
- marketing/components/footer.tsx: multi-column footer with product,
  resources, and legal columns — Privacy Policy clearly linked on homepage
  (satisfies Google OAuth consent screen requirement)
- Replaces thin single-line footer in layout.tsx

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 15:16:53 -08:00
85a355334a feat: add privacy policy and terms of service pages
- /privacy — BC PIPA/PIPEDA compliant privacy policy
- /terms — Terms of service governed by BC law
- Footer updated with Privacy, Terms, and Contact links

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 15:06:49 -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
4678928ee0 fix: redirect to /overview after project creation
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 12:30:22 -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
a281d4d373 feat: update project creation modal success screen
Replace .vibn file instruction with Gitea repo link, provisioning
checklist, and Open IDE / Go to Project buttons. Store gitea repo
info from API response to display in the success state.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-19 10:59:30 -08:00
6668cc84fa fix: wrap useSearchParams in Suspense, add linux-musl prisma target
- useSearchParams() requires a Suspense boundary in Next.js App Router
- Prisma binaryTargets was missing linux-musl (alpine build environment)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 18:21:10 -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
8e0d9090be fix: replace Firebase signOut with NextAuth signOut in left rail
Firebase is not configured - auth was undefined causing the error
'Cannot read properties of undefined (reading signOut)'.
Use next-auth/react signOut with callbackUrl to redirect to /auth.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 18:07:27 -08:00
e18db985b6 fix: set session cookie on .vibnai.com for subdomain ForwardAuth
Without domain: .vibnai.com the cookie is scoped to vibnai.com only.
Browsers don't send it to theia.vibnai.com, so ForwardAuth sees no
token and redirects to login even when the user is already logged in.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 18:02:06 -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
a8aefc0099 fix: exclude .env files from Docker build context
Coolify writes a .env file into the build context directory which
gets COPY'd into the builder container. Next.js then loads these
env vars (including DATABASE_URL, GITEA_API_TOKEN etc.) during
the build, causing some routes that reference those vars to fail
static analysis and be silently dropped from the build output.

Exclude all .env* files from the Docker build context so the
Next.js build runs with only the vars explicitly passed as build
args or set in the Dockerfile.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 16:41:11 -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
8bf69e1ae2 feat: update project dashboard UI for Vibn architecture
- project layout.tsx: replace Firebase Admin SDK with direct Postgres
  query to resolve project name; removes firebase/admin dependency
- overview page: full rewrite — fetches from /api/projects/:id, shows
  Gitea repo + last commit, branch, clone URLs; deployment status badge;
  open PRs and issues from contextSnapshot; recent commits list;
  resources section; Open IDE button; context freshness timestamp
- projects list page: cards now show Gitea repo + last commit inline,
  deploy status dot, IDE quick-link; updated empty state copy to reflect
  auto-provisioning; removed Firebase imports

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-18 14:57:16 -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
1f13d4ef74 fix: remove prisma db push from entrypoint (was dropping fs_* tables!) 2026-02-18 01:39:47 +00:00
7c3ff5e280 fix: install prisma@5 globally in runner stage for entrypoint db push 2026-02-18 01:35:41 +00:00
bc17ee661f fix: use global prisma cli in entrypoint 2026-02-18 01:35:25 +00:00
5986dfd50c fix: use local prisma binary in entrypoint (avoid npx downloading wrong version) 2026-02-18 01:34:50 +00:00
89cc366175 fix: remove --skip-generate from prisma db push (not a valid flag) 2026-02-18 01:31:09 +00:00
25f963d201 feat: rewrite project creation modal to remove Firebase auth 2026-02-18 01:26:26 +00:00