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