CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
app.tsx
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 79136bb | 1 | import { Hono } from "hono"; |
| 2 | import { logger } from "hono/logger"; | |
| 3 | import { cors } from "hono/cors"; | |
| 05b973e | 4 | import { compress } from "hono/compress"; |
| f1ffd50 | 5 | import { etag } from "hono/etag"; |
| c63b860 | 6 | // BLOCK O2 — shared error-page surface (404 / 500 / 403). |
| 7 | import { NotFoundPage, ServerErrorPage } from "./views/error-page"; | |
| 80bed05 | 8 | import { reportError } from "./lib/observability"; |
| 3ef4c9d | 9 | import { requestContext } from "./middleware/request-context"; |
| 10 | import { rateLimit } from "./middleware/rate-limit"; | |
| 79136bb | 11 | import gitRoutes from "./routes/git"; |
| 12 | import apiRoutes from "./routes/api"; | |
| 45e31d0 | 13 | import apiV2Routes from "./routes/api-v2"; |
| 14 | import apiDocsRoutes from "./routes/api-docs"; | |
| 4a80519 | 15 | import buildAgentSpecRoutes from "./routes/build-agent-spec"; |
| a6ff0f2 | 16 | import pullsDashboardRoutes from "./routes/pulls-dashboard"; |
| e9aa4d8 | 17 | import issuesDashboardRoutes from "./routes/issues-dashboard"; |
| 18 | import inboxRoutes from "./routes/inbox"; | |
| 19 | import activityRoutes from "./routes/activity"; | |
| 79136bb | 20 | import authRoutes from "./routes/auth"; |
| c63b860 | 21 | import passwordResetRoutes from "./routes/password-reset"; |
| 22 | import emailVerificationRoutes from "./routes/email-verification"; | |
| cd4f63b | 23 | import magicLinkRoutes from "./routes/magic-link"; |
| 79136bb | 24 | import settingsRoutes from "./routes/settings"; |
| 7298a17 | 25 | import settings2faRoutes from "./routes/settings-2fa"; |
| e75eddc | 26 | import settingsAgentsRoutes from "./routes/settings-agents"; |
| 1d4ff60 | 27 | import settingsIntegrationsRoutes from "./routes/settings-integrations"; |
| 28 | import integrationsChatRoutes from "./routes/integrations-chat"; | |
| e75eddc | 29 | import agentsRoutes from "./routes/agents"; |
| 79136bb | 30 | import issueRoutes from "./routes/issues"; |
| cb5a796 | 31 | import commentModerationRoutes from "./routes/comment-moderation"; |
| 79136bb | 32 | import repoSettings from "./routes/repo-settings"; |
| 23d1a81 | 33 | import collaboratorRoutes from "./routes/collaborators"; |
| 04f6b7f | 34 | import teamCollaboratorRoutes from "./routes/team-collaborators"; |
| 35 | import invitesRoutes from "./routes/invites"; | |
| 36 | import liveEventsRoutes from "./routes/live-events"; | |
| 3c03977 | 37 | import prLiveRoutes from "./routes/pr-live"; |
| 79136bb | 38 | import compareRoutes from "./routes/compare"; |
| 0074234 | 39 | import pullRoutes from "./routes/pulls"; |
| 79ed944 | 40 | import prSandboxRoutes from "./routes/pr-sandbox"; |
| 9b3a183 | 41 | import devEnvRoutes from "./routes/dev-env"; |
| 0074234 | 42 | import editorRoutes from "./routes/editor"; |
| c81ab7a | 43 | import forkRoutes from "./routes/fork"; |
| 44 | import webhookRoutes from "./routes/webhooks"; | |
| 45 | import exploreRoutes from "./routes/explore"; | |
| 46 | import tokenRoutes from "./routes/tokens"; | |
| 43de941 | 47 | import contributorRoutes from "./routes/contributors"; |
| 699e5c7 | 48 | import healthRoutes from "./routes/health-probe"; |
| 49 | import healthDashboardRoutes from "./routes/health"; | |
| 2316be6 | 50 | import statusRoutes from "./routes/status"; |
| b1be050 | 51 | import adminStatusRoutes from "./routes/admin-status"; |
| 80bed05 | 52 | import helpRoutes from "./routes/help"; |
| e1fc7db | 53 | import changelogRoutes from "./routes/changelog"; |
| b0148e9 | 54 | import marketingRoutes from "./routes/marketing"; |
| 5f2e749 | 55 | import pricingRoutes from "./routes/pricing"; |
| 5618f9a | 56 | import seoRoutes from "./routes/seo"; |
| 05cdb85 | 57 | import versionRoutes from "./routes/version"; |
| f295f78 | 58 | import { platformStatus } from "./routes/platform-status"; |
| 52ad8b1 | 59 | import publicStatsRoutes from "./routes/public-stats"; |
| 60 | import demoRoutes from "./routes/demo"; | |
| 16b325c | 61 | import insightRoutes from "./routes/insights"; |
| 8d1483c | 62 | import doraRoutes from "./routes/dora"; |
| f1ab587 | 63 | import dashboardRoutes from "./routes/dashboard"; |
| 36b4cbd | 64 | import legalRoutes from "./routes/legal"; |
| 4b66018 | 65 | import legalDmcaRoutes from "./routes/legal/dmca"; |
| 66 | import legalTermsRoutes from "./routes/legal/terms"; | |
| 67 | import legalPrivacyRoutes from "./routes/legal/privacy"; | |
| 68 | import legalAcceptableUseRoutes from "./routes/legal/acceptable-use"; | |
| bdbd0de | 69 | import importRoutes from "./routes/import"; |
| 14c3cc8 | 70 | import importBulkRoutes from "./routes/import-bulk"; |
| f390cfa | 71 | import importSecretsRoutes from "./routes/import-secrets"; |
| 14c3cc8 | 72 | import migrationRoutes from "./routes/migrations"; |
| 73 | import specsRoutes from "./routes/specs"; | |
| 23d0abf | 74 | import refactorRoutes from "./routes/refactors"; |
| 79136bb | 75 | import webRoutes from "./routes/web"; |
| 0316dbb | 76 | import hookRoutes from "./routes/hooks"; |
| 77 | import eventsRoutes from "./routes/events"; | |
| 78 | import passkeyRoutes from "./routes/passkeys"; | |
| 79 | import oauthRoutes from "./routes/oauth"; | |
| 80 | import developerAppsRoutes from "./routes/developer-apps"; | |
| 81 | import themeRoutes from "./routes/theme"; | |
| 82 | import auditRoutes from "./routes/audit"; | |
| 83 | import reactionRoutes from "./routes/reactions"; | |
| 84 | import savedReplyRoutes from "./routes/saved-replies"; | |
| 85 | import deploymentRoutes from "./routes/deployments"; | |
| 86 | import orgRoutes from "./routes/orgs"; | |
| 87 | import notificationRoutes from "./routes/notifications"; | |
| 88 | import onboardingRoutes from "./routes/onboarding"; | |
| 89 | import adminRoutes from "./routes/admin"; | |
| f764c07 | 90 | import adminDeploysRoutes from "./routes/admin-deploys"; |
| 91 | import adminDeploysPageRoutes from "./routes/admin-deploys-page"; | |
| 783dd46 | 92 | import adminServerTargetsRoutes from "./routes/admin-server-targets"; |
| 9aaa128 | 93 | import deployTargetsRoutes from "./routes/deploy-targets"; |
| 90c7531 | 94 | import claudeWebRoutes from "./routes/claude-web"; |
| 9dd96b9 | 95 | import adminOpsRoutes from "./routes/admin-ops"; |
| f2c00b4 | 96 | import adminSelfHostRoutes from "./routes/admin-self-host"; |
| 826eccf | 97 | import adminDiagnoseRoutes from "./routes/admin-diagnose"; |
| 509c376 | 98 | import adminIntegrationsRoutes from "./routes/admin-integrations"; |
| 79ed944 | 99 | import adminAdvancementRoutes from "./routes/admin-advancement"; |
| 0316dbb | 100 | import advisoriesRoutes from "./routes/advisories"; |
| 101 | import aiChangelogRoutes from "./routes/ai-changelog"; | |
| 102 | import aiExplainRoutes from "./routes/ai-explain"; | |
| 103 | import aiTestsRoutes from "./routes/ai-tests"; | |
| 104 | import askRoutes from "./routes/ask"; | |
| 38d31d3 | 105 | import repoChatRoutes from "./routes/repo-chat"; |
| ee7e577 | 106 | import personalChatRoutes from "./routes/personal-chat"; |
| 0316dbb | 107 | import billingRoutes from "./routes/billing"; |
| 8809b87 | 108 | import billingUsageRoutes from "./routes/billing-usage"; |
| 6778ad2 | 109 | import stripeWebhookRoutes from "./routes/stripe-webhook"; |
| 0316dbb | 110 | import codeScanningRoutes from "./routes/code-scanning"; |
| 111 | import commitStatusesRoutes from "./routes/commit-statuses"; | |
| 112 | import copilotRoutes from "./routes/copilot"; | |
| 113 | import depUpdaterRoutes from "./routes/dep-updater"; | |
| 114 | import depsRoutes from "./routes/deps"; | |
| 115 | import discussionsRoutes from "./routes/discussions"; | |
| 116 | import environmentsRoutes from "./routes/environments"; | |
| 4bbacbe | 117 | import previewsRoutes from "./routes/previews"; |
| 79ed944 | 118 | import docsTrackingRoutes from "./routes/docs-tracking"; |
| 0316dbb | 119 | import followsRoutes from "./routes/follows"; |
| 120 | import gatesRoutes from "./routes/gates"; | |
| 121 | import gistsRoutes from "./routes/gists"; | |
| 122 | import graphqlRoutes from "./routes/graphql"; | |
| 2c2163e | 123 | import mcpRoutes from "./routes/mcp"; |
| 0316dbb | 124 | import marketplaceRoutes from "./routes/marketplace"; |
| 5ca514a | 125 | import marketplaceAgentsRoutes from "./routes/marketplace-agents"; |
| 0316dbb | 126 | import mergeQueueRoutes from "./routes/merge-queue"; |
| 127 | import mirrorsRoutes from "./routes/mirrors"; | |
| 128 | import orgInsightsRoutes from "./routes/org-insights"; | |
| 129 | import packagesRoutes from "./routes/packages"; | |
| 130 | import packagesApiRoutes from "./routes/packages-api"; | |
| 131 | import pagesRoutes from "./routes/pages"; | |
| 132 | import projectsRoutes from "./routes/projects"; | |
| 133 | import protectedTagsRoutes from "./routes/protected-tags"; | |
| 134 | import pwaRoutes from "./routes/pwa"; | |
| 46d6165 | 135 | import installRoutes from "./routes/install"; |
| cd4f63b | 136 | import dxtRoutes from "./routes/dxt"; |
| 662ce86 | 137 | import connectClaudeRoutes from "./routes/connect-claude"; |
| ebbb527 | 138 | import claudeDeployRoutes from "./routes/claude-deploy"; |
| f5b9ef5 | 139 | import claudeIntegration from "./routes/claude-integration"; |
| 140 | import connectRoutes from "./routes/connect"; | |
| 05ab9b1 | 141 | import pushWatchRoutes from "./routes/push-watch"; |
| 142 | import orgSecretsRoutes from "./routes/org-secrets"; | |
| 0316dbb | 143 | import releasesRoutes from "./routes/releases"; |
| 144 | import requiredChecksRoutes from "./routes/required-checks"; | |
| 145 | import rulesetsRoutes from "./routes/rulesets"; | |
| 146 | import searchRoutes from "./routes/search"; | |
| 147 | import semanticSearchRoutes from "./routes/semantic-search"; | |
| 148 | import signingKeysRoutes from "./routes/signing-keys"; | |
| 149 | import sponsorsRoutes from "./routes/sponsors"; | |
| 150 | import ssoRoutes from "./routes/sso"; | |
| 46d6165 | 151 | import githubOauthRoutes from "./routes/github-oauth"; |
| 582cdac | 152 | import googleOauthRoutes from "./routes/google-oauth"; |
| 0316dbb | 153 | import symbolsRoutes from "./routes/symbols"; |
| 154 | import templatesRoutes from "./routes/templates"; | |
| 155 | import trafficRoutes from "./routes/traffic"; | |
| 156 | import wikisRoutes from "./routes/wikis"; | |
| 157 | import workflowsRoutes from "./routes/workflows"; | |
| 5ff9cc2 | 158 | import workflowArtifactsRoutes from "./routes/workflow-artifacts"; |
| 159 | import workflowSecretsRoutes from "./routes/workflow-secrets"; | |
| 46d6165 | 160 | import sleepModeRoutes from "./routes/sleep-mode"; |
| 56801e1 | 161 | import standupRoutes from "./routes/standups"; |
| 52ad8b1 | 162 | import vsGithubRoutes from "./routes/vs-github"; |
| 45f3b73 | 163 | import voiceRoutes from "./routes/voice-to-pr"; |
| cd4f63b | 164 | import playgroundRoutes from "./routes/playground"; |
| a2b3e99 | 165 | import crossRepoSearchRoutes from "./routes/cross-repo-search"; |
| 166 | import pushNotifRoutes from "./routes/push-notifications"; | |
| 9fbe6cd | 167 | import velocityRoutes from "./routes/velocity"; |
| 168 | import { staleBranchRoutes } from "./routes/stale-branches"; | |
| 22f43f3 | 169 | import pulseRoutes from "./routes/pulse"; |
| 74d8c4d | 170 | import healthScoreRoutes from "./routes/health-score"; |
| 171 | import hotFilesRoutes from "./routes/hot-files"; | |
| 59b6fb2 | 172 | import { authRateLimit, gitRateLimit, searchRateLimit } from "./middleware/rate-limit"; |
| 173 | import { csrfToken, csrfProtect } from "./middleware/csrf"; | |
| f5b9ef5 | 174 | import { noCache } from "./middleware/no-cache"; |
| 79136bb | 175 | |
| 2316901 | 176 | import type { AuthEnv } from "./middleware/auth"; |
| bf19c50 | 177 | import { softAuth } from "./middleware/auth"; |
| 2316901 | 178 | |
| 179 | const app = new Hono<AuthEnv>(); | |
| 79136bb | 180 | |
| 3ef4c9d | 181 | // Request context (request ID, start time) runs before everything else |
| 182 | app.use("*", requestContext); | |
| 05b973e | 183 | // Middleware — compression first (wraps all responses) |
| 184 | app.use("*", compress()); | |
| f1ffd50 | 185 | |
| 186 | // ETag middleware — returns 304 Not Modified on unchanged responses. | |
| 187 | // Saves ~95% bandwidth on repeat visits. Skipped on git protocol + | |
| 188 | // SSE + the API surface where it would interfere with streaming. | |
| 189 | app.use("*", async (c, next) => { | |
| 190 | const p = c.req.path; | |
| 191 | if ( | |
| 192 | p.includes(".git/") || | |
| 193 | p.startsWith("/live-events") || | |
| 194 | p.startsWith("/api/events/deploy") || | |
| 3c03977 | 195 | p.startsWith("/admin/status") || |
| 196 | // PR live co-editing SSE stream — never etag streaming responses. | |
| 197 | /^\/api\/v2\/pulls\/[^/]+\/live(\/|$)/.test(p) | |
| f1ffd50 | 198 | ) { |
| 199 | return next(); | |
| 200 | } | |
| 201 | return etag()(c, next); | |
| 202 | }); | |
| 203 | ||
| 204 | // Cache-Control middleware — sets sensible defaults on public, anonymous | |
| 205 | // requests. Crontech (when wired as our edge layer) and downstream | |
| 206 | // browsers will honor these. Auth'd users get private,no-store | |
| 207 | // automatically — we never cache responses tied to a session. | |
| 208 | app.use("*", async (c, next) => { | |
| 209 | await next(); | |
| 210 | // Don't overwrite explicit headers set by route handlers — BUT the | |
| 211 | // ETag middleware unconditionally sets "private, no-cache, must- | |
| 212 | // revalidate" so we have to treat that specific value as "no | |
| 213 | // policy chosen yet" and apply ours. Any route that explicitly set | |
| 214 | // a different cache-control wins. | |
| 215 | const existing = c.res.headers.get("cache-control"); | |
| 216 | const etagDefault = | |
| 217 | existing === "private, no-cache, must-revalidate" || | |
| 218 | existing === "no-cache"; | |
| 219 | if (existing && !etagDefault) return; | |
| 220 | // Anything past auth: private + no-store (avoid leaking session | |
| 221 | // content into shared caches). softAuth runs before this on the | |
| 222 | // request, but the response side is what we're stamping. | |
| 223 | const hasSession = c.req.header("cookie")?.includes("session=") ?? false; | |
| 224 | const p = c.req.path; | |
| 225 | // Always private for known-authed paths regardless of cookie. | |
| 226 | if ( | |
| 227 | p.startsWith("/admin") || | |
| 228 | p.startsWith("/settings") || | |
| 229 | p.startsWith("/dashboard") || | |
| 230 | p.startsWith("/notifications") || | |
| 231 | p.startsWith("/connect/") || | |
| 232 | hasSession | |
| 233 | ) { | |
| 234 | c.res.headers.set("cache-control", "private, no-store"); | |
| 235 | return; | |
| 236 | } | |
| 237 | // Public marketing surfaces — short edge cache, longer browser cache, | |
| 238 | // stale-while-revalidate so the user never waits on a stale fetch. | |
| 239 | const isMarketing = | |
| 240 | p === "/" || | |
| 241 | p === "/features" || | |
| 242 | p === "/pricing" || | |
| 243 | p === "/about" || | |
| 244 | p === "/vs-github" || | |
| 245 | p === "/explore" || | |
| 246 | p === "/help" || | |
| 247 | p === "/changelog" || | |
| 248 | p.startsWith("/legal/") || | |
| 249 | p === "/terms" || | |
| 250 | p === "/privacy" || | |
| 251 | p === "/acceptable-use" || | |
| 252 | p.startsWith("/docs/"); | |
| 253 | if (isMarketing) { | |
| 254 | c.res.headers.set( | |
| 255 | "cache-control", | |
| 256 | "public, max-age=60, s-maxage=300, stale-while-revalidate=86400" | |
| 257 | ); | |
| 258 | return; | |
| 259 | } | |
| 260 | // Public repo browse pages — cache aggressively. Edge invalidates | |
| 261 | // on push via the post-receive hook (future Crontech surge purge). | |
| 262 | if (/^\/[^/]+\/[^/]+(\/.*)?$/.test(p) && c.req.method === "GET") { | |
| 263 | c.res.headers.set( | |
| 264 | "cache-control", | |
| 265 | "public, max-age=30, s-maxage=120, stale-while-revalidate=600" | |
| 266 | ); | |
| 267 | return; | |
| 268 | } | |
| 269 | // Default: don't cache anything we haven't explicitly opted in. | |
| 270 | c.res.headers.set("cache-control", "private, no-store"); | |
| 271 | }); | |
| 05b973e | 272 | // Logger only on non-git routes to avoid overhead on clone/push |
| 273 | app.use("*", async (c, next) => { | |
| 274 | if (c.req.path.includes(".git/")) return next(); | |
| 275 | return logger()(c, next); | |
| 276 | }); | |
| 79136bb | 277 | app.use("/api/*", cors()); |
| bf19c50 | 278 | // Global softAuth — populates c.get("user") for every downstream middleware |
| 279 | // + route. This was previously per-route, which meant rate-limit middleware | |
| 280 | // (and anything else inspecting auth state) always saw a null user. Keep | |
| 281 | // individual routes free to add requireAuth on top for hard gating; this | |
| 282 | // just establishes the user object cheaply. | |
| 283 | app.use("*", softAuth); | |
| 290ea77 | 284 | |
| 36cc17a | 285 | // Force-revalidate HTML on every request — kills browser cache holding stale |
| 290ea77 | 286 | // pre-redesign markup. JSON / static assets keep their own cache rules; only |
| 287 | // text/html responses get the no-cache stamp. Without this, every push to | |
| 288 | // main left users staring at cached 80s-looking pages from before the design | |
| 289 | // landed. | |
| 36cc17a | 290 | // |
| 291 | // We deliberately use `private, no-cache, must-revalidate` rather than | |
| 292 | // `no-store`. `no-store` disables Safari/Chrome's back-forward cache (bfcache), | |
| 293 | // which makes every Back/Forward press a cold server round-trip — that | |
| 294 | // contributed to the "every nav feels like a fresh login" UX complaint. | |
| 295 | // `no-cache` still revalidates on direct fetch but lets bfcache hold the | |
| 296 | // page in memory between navigations. | |
| 290ea77 | 297 | app.use("*", async (c, next) => { |
| 298 | await next(); | |
| 299 | const ct = c.res.headers.get("content-type") || ""; | |
| 300 | if (ct.startsWith("text/html")) { | |
| 36cc17a | 301 | c.header("cache-control", "private, no-cache, must-revalidate"); |
| 290ea77 | 302 | } |
| 303 | }); | |
| 826eccf | 304 | // Rate-limit API + auth endpoints. |
| 305 | // | |
| a41e675 | 306 | // `/api/*`: 1000/min per IP — generous so an admin clicking around the |
| 307 | // operator console (or a CDN/proxy concentrating multiple users behind one | |
| 308 | // IP) doesn't hit the wall. Bot-resistant headroom comes from the auth | |
| 309 | // rate limits below, not this one. | |
| 310 | // | |
| 311 | // `authedMultiplier` is set but only fires when an upstream middleware has | |
| 312 | // already populated c.get("user") — most app.use() chains apply softAuth | |
| 313 | // per-route, so the multiplier is best-effort. Keep the anonymous base | |
| 314 | // high enough that humans never feel it. | |
| 315 | // | |
| 316 | // Skip-paths: dashboard plumbing endpoints that the layout polls on a | |
| 317 | // fixed cadence and that we don't want consuming any bucket: | |
| 318 | // /api/version — layout polls every 15s | |
| 826eccf | 319 | // /api/notifications/count — nav bell unread-count fetcher |
| 320 | // /pwa/vapid-public-key — fetched once per push-notification opt-in | |
| 321 | app.use( | |
| 322 | "/api/*", | |
| a41e675 | 323 | rateLimit(1000, 60_000, "api", { |
| 826eccf | 324 | authedMultiplier: 4, |
| 325 | skipPaths: ["/api/version", "/api/notifications/count", "/pwa/vapid-public-key"], | |
| 326 | }) | |
| 327 | ); | |
| 0316dbb | 328 | app.use("/login", rateLimit(20, 60_000, "login")); |
| 329 | app.use("/register", rateLimit(10, 60_000, "register")); | |
| c63b860 | 330 | // BLOCK P1 — throttle forgot-password to deter enumeration + mail spam. |
| 331 | app.use("/forgot-password", rateLimit(5, 60_000, "forgot-password")); | |
| cd4f63b | 332 | // BLOCK Q2 — throttle magic-link sign-in for the same reason. |
| 333 | app.use("/login/magic", rateLimit(5, 60_000, "magic-link")); | |
| 79136bb | 334 | |
| 59b6fb2 | 335 | // CSRF protection — set token on all requests, validate on mutations |
| 336 | app.use("*", csrfToken); | |
| 337 | app.use("*", csrfProtect); | |
| 338 | ||
| 45e31d0 | 339 | // Rate limit auth routes |
| 340 | app.use("/login", authRateLimit); | |
| 341 | app.use("/register", authRateLimit); | |
| 342 | ||
| 59b6fb2 | 343 | // Rate limit git operations |
| 344 | app.use("/:owner/:repo.git/*", gitRateLimit); | |
| 345 | ||
| 346 | // Rate limit search | |
| 347 | app.use("/:owner/:repo/search", searchRateLimit); | |
| 348 | app.use("/explore", searchRateLimit); | |
| 79136bb | 349 | |
| f5b9ef5 | 350 | // No-cache for HTML — ensures browsers and proxies never serve stale pages. |
| 351 | // The middleware only stamps text/html responses so static assets keep | |
| 352 | // their own cache policies unchanged. | |
| 353 | app.use("*", noCache); | |
| 354 | ||
| 79136bb | 355 | // Git Smart HTTP protocol routes (must be before web routes) |
| 356 | app.route("/", gitRoutes); | |
| 357 | ||
| 45e31d0 | 358 | // REST API v1 (legacy) |
| 79136bb | 359 | app.route("/", apiRoutes); |
| 360 | ||
| 52ad8b1 | 361 | // Block L3 — /demo + /api/v2/demo/* live demo endpoints. Mounted BEFORE |
| 362 | // apiV2Routes so the /api/v2/demo/* JSON endpoints win over the v2 base | |
| 363 | // router's catch-shape, and BEFORE adminRoutes so the live /demo page | |
| 364 | // wins over the legacy /demo redirect in src/routes/admin.tsx. | |
| 365 | app.route("/", demoRoutes); | |
| 366 | ||
| 0316dbb | 367 | // REST API v2 (basePath /api/v2) |
| 368 | app.route("/", apiV2Routes); | |
| 369 | ||
| e75eddc | 370 | // Agent multiplayer v1 — /api/v2/agents/* (sessions, leases, usage). |
| 371 | // Mounted alongside apiV2Routes (its own basePath, no path conflict). | |
| 372 | app.route("/", agentsRoutes); | |
| 373 | ||
| ad6d4ad | 374 | // Inbound API hooks (GateTest callback + backup PAT-authed /api/v1/gate-runs) |
| 375 | app.route("/", hookRoutes); | |
| 21f8dbd | 376 | app.route("/api/events", eventsRoutes); |
| ad6d4ad | 377 | |
| 45e31d0 | 378 | // API documentation |
| 379 | app.route("/", apiDocsRoutes); | |
| 4a80519 | 380 | app.route("/", buildAgentSpecRoutes); |
| a6ff0f2 | 381 | // PR command center — global PR dashboard with AI/GateTest/auto-merge signal |
| 382 | app.route("/", pullsDashboardRoutes); | |
| e9aa4d8 | 383 | // Issue command center — global issue dashboard with AI-triage + autopilot signal |
| 384 | app.route("/", issuesDashboardRoutes); | |
| 385 | // Personal activity timeline — every event across the user's repos, with | |
| 386 | // AI-driven events surfaced separately (the Gluecron differentiator). | |
| 387 | app.route("/", activityRoutes); | |
| 388 | // Unified inbox — mentions + review requests + CI failures + AI events in one timeline | |
| 389 | app.route("/", inboxRoutes); | |
| 56801e1 | 390 | // AI standup feed — daily / weekly Claude-generated team brief |
| 391 | app.route("/", standupRoutes); | |
| 79136bb | 392 | |
| 393 | // Auth routes (register, login, logout) | |
| 394 | app.route("/", authRoutes); | |
| 395 | ||
| c63b860 | 396 | // BLOCK P1 — Password reset (forgot-password + reset-password) |
| 397 | app.route("/", passwordResetRoutes); | |
| 398 | ||
| 399 | // BLOCK P2 — Email verification (verify-email + resend) | |
| 400 | app.route("/", emailVerificationRoutes); | |
| 401 | ||
| cd4f63b | 402 | // BLOCK Q2 — Magic-link sign-in (/login/magic + callback) |
| 403 | app.route("/", magicLinkRoutes); | |
| 404 | ||
| 79136bb | 405 | // Settings routes (profile, SSH keys) |
| 406 | app.route("/", settingsRoutes); | |
| 407 | ||
| 7298a17 | 408 | // 2FA / TOTP settings (Block B4) |
| 409 | app.route("/", settings2faRoutes); | |
| 410 | ||
| e75eddc | 411 | // Agent multiplayer — /settings/agents management UI |
| 412 | app.route("/", settingsAgentsRoutes); | |
| 413 | ||
| 1d4ff60 | 414 | // Chat integrations — Slack / Discord / Teams (/settings/integrations |
| 415 | // + /api/v2/integrations/{slack,discord}/*). See src/lib/chat-bot.ts. | |
| 416 | app.route("/", settingsIntegrationsRoutes); | |
| 417 | app.route("/", integrationsChatRoutes); | |
| 418 | ||
| 2df1f8c | 419 | // WebAuthn / passkey routes (Block B5) |
| 420 | app.route("/", passkeyRoutes); | |
| 421 | ||
| 058d752 | 422 | // OAuth 2.0 provider (Block B6) |
| 423 | app.route("/", oauthRoutes); | |
| 424 | app.route("/", developerAppsRoutes); | |
| 425 | ||
| 6fc53bd | 426 | // Theme toggle (dark/light cookie) |
| 427 | app.route("/", themeRoutes); | |
| 428 | ||
| 429 | // Audit log UI | |
| 430 | app.route("/", auditRoutes); | |
| 431 | ||
| 432 | // Reactions API (issues, PRs, comments) | |
| 433 | app.route("/", reactionRoutes); | |
| 434 | ||
| 24cf2ca | 435 | // Saved replies (per-user canned comment templates) |
| 436 | app.route("/", savedReplyRoutes); | |
| 437 | ||
| 438 | // Environments + deployment history UI | |
| 439 | app.route("/", deploymentRoutes); | |
| 440 | ||
| 6563f0a | 441 | // Organizations + teams (Block B1) |
| 442 | app.route("/", orgRoutes); | |
| 443 | ||
| c81ab7a | 444 | // API tokens |
| 445 | app.route("/", tokenRoutes); | |
| 446 | ||
| 59b6fb2 | 447 | // Notifications |
| 3ef4c9d | 448 | app.route("/", notificationRoutes); |
| 449 | ||
| 79136bb | 450 | // Repo settings (description, visibility, delete) |
| 451 | app.route("/", repoSettings); | |
| 452 | ||
| 23d1a81 | 453 | // Repo collaborators (add/list/remove) |
| 454 | app.route("/", collaboratorRoutes); | |
| 455 | ||
| 04f6b7f | 456 | // Team-based repo collaborators (invite a whole team) |
| 457 | app.route("/", teamCollaboratorRoutes); | |
| 458 | ||
| 459 | // Collaborator invite accept flow (token-based) | |
| 460 | app.route("/", invitesRoutes); | |
| 461 | ||
| 462 | // Real-time SSE endpoint (topic-based live updates) | |
| 463 | app.route("/", liveEventsRoutes); | |
| 464 | ||
| 3c03977 | 465 | // PR live co-editing — presence + cursors + content sync via SSE. |
| 466 | app.route("/", prLiveRoutes); | |
| 467 | ||
| c81ab7a | 468 | // Webhooks management |
| 469 | app.route("/", webhookRoutes); | |
| 470 | ||
| 79136bb | 471 | // Compare view (branch diffs) |
| 472 | app.route("/", compareRoutes); | |
| 473 | ||
| 474 | // Issue tracker | |
| 475 | app.route("/", issueRoutes); | |
| 476 | ||
| cb5a796 | 477 | // Comment moderation queue — owner-only `/:owner/:repo/comments/pending` |
| 478 | // + per-row approve/reject/spam actions. Mounted before `pullRoutes` so | |
| 479 | // the `/:owner/:repo/comments/*` paths resolve before the broader PR | |
| 480 | // patterns kick in. | |
| 481 | app.route("/", commentModerationRoutes); | |
| 482 | ||
| 0074234 | 483 | // Pull requests |
| 484 | app.route("/", pullRoutes); | |
| 79ed944 | 485 | // PR sandboxes — runnable per-PR environments. Migration 0067. |
| 486 | app.route("/", prSandboxRoutes); | |
| 0074234 | 487 | |
| 9b3a183 | 488 | // Cloud dev environments — hosted VS Code in the browser. Migration 0072. |
| 489 | app.route("/", devEnvRoutes); | |
| 490 | ||
| c81ab7a | 491 | // Fork |
| 492 | app.route("/", forkRoutes); | |
| 493 | ||
| 0074234 | 494 | // Web file editor |
| 495 | app.route("/", editorRoutes); | |
| 496 | ||
| 43de941 | 497 | // Contributors |
| 498 | app.route("/", contributorRoutes); | |
| 499 | ||
| 699e5c7 | 500 | // Health liveness + metrics endpoints |
| 2c34075 | 501 | app.route("/", healthRoutes); |
| 502 | ||
| f295f78 | 503 | // Cross-product platform status (public, CORS-open — see docs/PLATFORM_STATUS.md) |
| 504 | app.route("/api/platform-status", platformStatus); | |
| 505 | ||
| 52ad8b1 | 506 | // Block L4 — Public stats counters (powers landing-page social proof) |
| 507 | app.route("/", publicStatsRoutes); | |
| 508 | ||
| 509 | // Block L3 — Live /demo page + /api/v2/demo/* endpoints | |
| 510 | app.route("/", demoRoutes); | |
| 511 | ||
| 2316be6 | 512 | // Public /status — human-readable platform health page |
| 513 | app.route("/", statusRoutes); | |
| 514 | ||
| b1be050 | 515 | // BLOCK S4 — Site-admin synthetic-monitor dashboard (/admin/status). |
| 516 | // Mounted near the public status route so the two surfaces are visible | |
| 517 | // side-by-side; routes are gated by isSiteAdmin internally. | |
| 518 | app.route("/", adminStatusRoutes); | |
| 519 | ||
| 80bed05 | 520 | // /help — quickstart + API cheatsheet |
| 521 | app.route("/", helpRoutes); | |
| 522 | ||
| 5f2e749 | 523 | // L8 — public /pricing page (free-tier polish). Mounted BEFORE marketing |
| 524 | // so the new editorial pricing layout wins the route; the legacy marketing | |
| 525 | // pricing remains as a safety net but is shadowed at the router. | |
| 526 | app.route("/", pricingRoutes); | |
| 527 | ||
| e1fc7db | 528 | // /changelog — manually curated platform release history |
| 529 | app.route("/", changelogRoutes); | |
| 530 | ||
| b0148e9 | 531 | // /pricing, /features, /about — marketing surface |
| 532 | app.route("/", marketingRoutes); | |
| 533 | ||
| 5618f9a | 534 | // SEO: robots.txt + sitemap.xml |
| 535 | app.route("/", seoRoutes); | |
| 536 | ||
| 05cdb85 | 537 | // /api/version — live build SHA + uptime; client poller uses this to |
| 538 | // surface 'New version available — reload' banners on deploy. | |
| 539 | app.route("/", versionRoutes); | |
| 540 | ||
| 699e5c7 | 541 | // Health dashboard (per-repo health page) |
| 542 | app.route("/", healthDashboardRoutes); | |
| 543 | ||
| 9dd96b9 | 544 | // Block R1 — site-admin operations console. MUST be mounted BEFORE |
| 545 | // insightRoutes because its POST `/:owner/:repo/rollback` catch-all would | |
| 546 | // otherwise intercept `/admin/ops/rollback` (matching :owner=admin :repo=ops). | |
| 547 | app.route("/", adminOpsRoutes); | |
| f2c00b4 | 548 | // BLOCK W — Self-host status + bootstrap dashboard. |
| 549 | app.route("/", adminSelfHostRoutes); | |
| 826eccf | 550 | // BLOCK X — AI health-scan diagnose page (/admin/diagnose). |
| 551 | app.route("/", adminDiagnoseRoutes); | |
| 9dd96b9 | 552 | |
| 16b325c | 553 | // Insights (time-travel, dependencies, rollback) |
| 554 | app.route("/", insightRoutes); | |
| 555 | ||
| 8d1483c | 556 | // DORA metrics page (/:owner/:repo/insights/dora) |
| 557 | app.route("/", doraRoutes); | |
| 558 | ||
| f1ab587 | 559 | // Command center dashboard |
| 560 | app.route("/", dashboardRoutes); | |
| 561 | ||
| 36b4cbd | 562 | // Legal pages (terms, privacy, AUP) |
| 563 | app.route("/", legalRoutes); | |
| 4b66018 | 564 | // Long-form legal sub-pages — /legal/{terms,privacy,acceptable-use,dmca}. |
| 565 | // The main `legal.tsx` serves the short canonical paths (/terms, /privacy, | |
| 566 | // /acceptable-use); these are the formal versions that the legal pages | |
| 567 | // internally link to each other. | |
| 568 | app.route("/", legalTermsRoutes); | |
| 569 | app.route("/", legalPrivacyRoutes); | |
| 570 | app.route("/", legalAcceptableUseRoutes); | |
| 571 | app.route("/", legalDmcaRoutes); | |
| 36b4cbd | 572 | |
| bdbd0de | 573 | // GitHub import / migration |
| 574 | app.route("/", importRoutes); | |
| 14c3cc8 | 575 | app.route("/", importBulkRoutes); |
| f390cfa | 576 | app.route("/", importSecretsRoutes); |
| 14c3cc8 | 577 | app.route("/", migrationRoutes); |
| 578 | ||
| 579 | // Spec-to-PR (experimental AI-generated draft PRs) | |
| 580 | app.route("/", specsRoutes); | |
| 23d0abf | 581 | app.route("/", refactorRoutes); |
| bdbd0de | 582 | |
| c81ab7a | 583 | // Explore page |
| 584 | app.route("/", exploreRoutes); | |
| 585 | ||
| 59b6fb2 | 586 | // Onboarding |
| 587 | app.route("/", onboardingRoutes); | |
| 588 | ||
| 0316dbb | 589 | // Admin + feature routes |
| 590 | app.route("/", adminRoutes); | |
| 509c376 | 591 | app.route("/", adminIntegrationsRoutes); |
| 79ed944 | 592 | app.route("/", adminAdvancementRoutes); |
| f764c07 | 593 | app.route("/", adminDeploysRoutes); |
| 594 | app.route("/", adminDeploysPageRoutes); | |
| 783dd46 | 595 | app.route("/", adminServerTargetsRoutes); |
| 9aaa128 | 596 | app.route("/", deployTargetsRoutes); |
| 90c7531 | 597 | app.route("/", claudeWebRoutes); |
| 9dd96b9 | 598 | // Note: adminOpsRoutes is mounted earlier (before insightRoutes) — see comment above. |
| 0316dbb | 599 | app.route("/", advisoriesRoutes); |
| 600 | app.route("/", aiChangelogRoutes); | |
| 601 | app.route("/", aiExplainRoutes); | |
| 602 | app.route("/", aiTestsRoutes); | |
| 603 | app.route("/", askRoutes); | |
| 38d31d3 | 604 | app.route("/", repoChatRoutes); |
| ee7e577 | 605 | // Personal cross-repo chat — `/chat` (user-scoped). Mounted alongside |
| 606 | // repoChatRoutes so the two surfaces share the catch-all priority. | |
| 607 | app.route("/", personalChatRoutes); | |
| 0316dbb | 608 | app.route("/", billingRoutes); |
| 8809b87 | 609 | app.route("/", billingUsageRoutes); |
| 6778ad2 | 610 | app.route("/", stripeWebhookRoutes); |
| 0316dbb | 611 | app.route("/", codeScanningRoutes); |
| 612 | app.route("/", commitStatusesRoutes); | |
| 613 | app.route("/", copilotRoutes); | |
| 614 | app.route("/", depUpdaterRoutes); | |
| 615 | app.route("/", depsRoutes); | |
| 616 | app.route("/", discussionsRoutes); | |
| 617 | app.route("/", environmentsRoutes); | |
| 4bbacbe | 618 | app.route("/", previewsRoutes); |
| 79ed944 | 619 | app.route("/", docsTrackingRoutes); |
| 0316dbb | 620 | app.route("/", followsRoutes); |
| 621 | app.route("/", gatesRoutes); | |
| 622 | app.route("/", gistsRoutes); | |
| 623 | app.route("/", graphqlRoutes); | |
| 2c2163e | 624 | app.route("/", mcpRoutes); |
| 0316dbb | 625 | app.route("/", marketplaceRoutes); |
| 5ca514a | 626 | app.route("/", marketplaceAgentsRoutes); |
| 0316dbb | 627 | app.route("/", mergeQueueRoutes); |
| 628 | app.route("/", mirrorsRoutes); | |
| 629 | app.route("/", orgInsightsRoutes); | |
| 630 | app.route("/", packagesRoutes); | |
| 631 | app.route("/", packagesApiRoutes); | |
| 632 | app.route("/", pagesRoutes); | |
| 633 | app.route("/", projectsRoutes); | |
| 634 | app.route("/", protectedTagsRoutes); | |
| 635 | app.route("/", pwaRoutes); | |
| 46d6165 | 636 | app.route("/", installRoutes); |
| cd4f63b | 637 | // BLOCK Q1 — /gluecron.dxt download (Claude Desktop one-click extension) |
| 638 | app.route("/", dxtRoutes); | |
| 662ce86 | 639 | // Connect Claude — user-facing one-click MCP setup (/connect/claude). Mounted |
| 640 | // next to the other one-click flows (install.sh + .dxt) for surface symmetry. | |
| 641 | app.route("/", connectClaudeRoutes); | |
| f5b9ef5 | 642 | // Claude Code Integration Receiver — /api/claude/connect + /api/claude/session. |
| 643 | app.route("/", claudeIntegration); | |
| 644 | // Connect guide — public onboarding page (/connect/claude-guide). | |
| 645 | app.route("/", connectRoutes); | |
| 05ab9b1 | 646 | // Push Watch — per-commit live status (gates + deploy + latency) at /:owner/:repo/push/:sha |
| 647 | app.route("/", pushWatchRoutes); | |
| 648 | // Org Secrets Manager — BLOCK M2 — /orgs/:slug/settings/secrets | |
| 649 | app.route("/", orgSecretsRoutes); | |
| a2b3e99 | 650 | // Cross-repo code search — BLOCK M3 — /search/code + /api/search/code |
| 651 | app.route("/", crossRepoSearchRoutes); | |
| 652 | // Browser push notifications — BLOCK M4 — /settings/notifications/push + /api/push/* | |
| 653 | app.route("/", pushNotifRoutes); | |
| 9fbe6cd | 654 | // Developer Velocity Dashboard — BLOCK M9 — /:owner/:repo/insights/velocity |
| 655 | app.route("/", velocityRoutes); | |
| 656 | // Stale Branch Cleanup — BLOCK M10 — /:owner/:repo/branches/stale | |
| 657 | app.route("/", staleBranchRoutes); | |
| 22f43f3 | 658 | // Repository Pulse — BLOCK M12 — /:owner/:repo/pulse |
| 659 | app.route("/", pulseRoutes); | |
| 74d8c4d | 660 | // Repository Health Score — BLOCK M14 — /:owner/:repo/insights/health |
| 661 | app.route("/", healthScoreRoutes); | |
| 662 | // Hot Files Heatmap — BLOCK M16 — /:owner/:repo/insights/hotfiles | |
| 663 | app.route("/", hotFilesRoutes); | |
| ebbb527 | 664 | // Hosted Claude tool-use loops — paste loop, get endpoint, billing meter. |
| 665 | // See src/routes/claude-deploy.tsx + src/lib/hosted-claude-loop.ts. | |
| 666 | app.route("/", claudeDeployRoutes); | |
| 0316dbb | 667 | app.route("/", releasesRoutes); |
| 668 | app.route("/", requiredChecksRoutes); | |
| 669 | app.route("/", rulesetsRoutes); | |
| 670 | app.route("/", searchRoutes); | |
| 671 | app.route("/", semanticSearchRoutes); | |
| 672 | app.route("/", signingKeysRoutes); | |
| 673 | app.route("/", sponsorsRoutes); | |
| 674 | app.route("/", ssoRoutes); | |
| 46d6165 | 675 | app.route("/", githubOauthRoutes); |
| 582cdac | 676 | app.route("/", googleOauthRoutes); |
| 0316dbb | 677 | app.route("/", symbolsRoutes); |
| 678 | app.route("/", templatesRoutes); | |
| 679 | app.route("/", trafficRoutes); | |
| 680 | app.route("/", wikisRoutes); | |
| 681 | app.route("/", workflowsRoutes); | |
| 5ff9cc2 | 682 | app.route("/", workflowArtifactsRoutes); |
| 683 | app.route("/", workflowSecretsRoutes); | |
| 46d6165 | 684 | app.route("/", sleepModeRoutes); |
| 52ad8b1 | 685 | app.route("/", vsGithubRoutes); |
| 0316dbb | 686 | |
| 45f3b73 | 687 | // Voice-to-PR — phone-first dictation → spec or issue |
| 688 | app.route("/", voiceRoutes); | |
| 689 | ||
| cd4f63b | 690 | // Block Q3 — Anonymous playground (`/play`, `/play/claim`). Mounted |
| 691 | // before the web catch-all so the bare `/play` literal wins over the | |
| 692 | // `/:owner` user-profile route. | |
| 693 | app.route("/", playgroundRoutes); | |
| 694 | ||
| 79136bb | 695 | // Web UI (catch-all, must be last) |
| 696 | app.route("/", webRoutes); | |
| 697 | ||
| c63b860 | 698 | // Global 404 — BLOCK O2 routes the shared `NotFoundPage` view so |
| 699 | // the markup stays consistent with /500 and the admin /403 page. | |
| 79136bb | 700 | app.notFound((c) => { |
| 36cc17a | 701 | const user = c.get("user") ?? null; |
| 79136bb | 702 | return c.html( |
| c63b860 | 703 | <NotFoundPage user={user} method={c.req.method} path={c.req.path} />, |
| 79136bb | 704 | 404 |
| 705 | ); | |
| 706 | }); | |
| 707 | ||
| c63b860 | 708 | // Global error handler — BLOCK O2 uses the shared `ServerErrorPage` |
| 709 | // view. Trace block only shown outside production. | |
| 79136bb | 710 | app.onError((err, c) => { |
| 80bed05 | 711 | reportError(err, { |
| 712 | requestId: c.get("requestId"), | |
| 713 | path: c.req.path, | |
| 714 | method: c.req.method, | |
| 715 | }); | |
| c63b860 | 716 | // Prefer the inbound `x-request-id` header (LB-supplied) and fall |
| 717 | // back to the context value set by request-context middleware. | |
| 718 | const requestId = | |
| 719 | c.req.header("x-request-id") || | |
| 720 | ((c.get("requestId" as never) as string | undefined) ?? undefined); | |
| 36cc17a | 721 | const user = c.get("user") ?? null; |
| c63b860 | 722 | const trace = |
| 723 | process.env.NODE_ENV !== "production" && err && err.message | |
| 724 | ? err.message | |
| 725 | : undefined; | |
| 79136bb | 726 | return c.html( |
| c63b860 | 727 | <ServerErrorPage user={user} requestId={requestId} trace={trace} />, |
| 79136bb | 728 | 500 |
| 729 | ); | |
| 730 | }); | |
| 731 | ||
| 732 | export default app; |