Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesPull RequestsActionsSecurityInsightsSettings
✨ AI
More
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.

app.tsxBlame1042 lines · 6 contributors
79136bbClaude1import { Hono } from "hono";
4abf6f1ccantynz-alt2import type { Context } from "hono";
79136bbClaude3import { logger } from "hono/logger";
4import { cors } from "hono/cors";
05b973eClaude5import { compress } from "hono/compress";
f1ffd50Claude6import { etag } from "hono/etag";
c63b860Claude7// BLOCK O2 — shared error-page surface (404 / 500 / 403).
8import { NotFoundPage, ServerErrorPage } from "./views/error-page";
80bed05Claude9import { reportError } from "./lib/observability";
3ef4c9dClaude10import { requestContext } from "./middleware/request-context";
11import { rateLimit } from "./middleware/rate-limit";
79136bbClaude12import gitRoutes from "./routes/git";
13import apiRoutes from "./routes/api";
45e31d0Claude14import apiV2Routes from "./routes/api-v2";
15import apiDocsRoutes from "./routes/api-docs";
4a80519Claude16import buildAgentSpecRoutes from "./routes/build-agent-spec";
a6ff0f2Claude17import pullsDashboardRoutes from "./routes/pulls-dashboard";
e9aa4d8Claude18import issuesDashboardRoutes from "./routes/issues-dashboard";
19import inboxRoutes from "./routes/inbox";
cc34156Claude20import digestRoutes from "./routes/digest";
e9aa4d8Claude21import activityRoutes from "./routes/activity";
79136bbClaude22import authRoutes from "./routes/auth";
c63b860Claude23import passwordResetRoutes from "./routes/password-reset";
24import emailVerificationRoutes from "./routes/email-verification";
cd4f63bTest User25import magicLinkRoutes from "./routes/magic-link";
79136bbClaude26import settingsRoutes from "./routes/settings";
7298a17Claude27import settings2faRoutes from "./routes/settings-2fa";
e75eddcClaude28import settingsAgentsRoutes from "./routes/settings-agents";
1d4ff60Claude29import settingsIntegrationsRoutes from "./routes/settings-integrations";
30import integrationsChatRoutes from "./routes/integrations-chat";
e75eddcClaude31import agentsRoutes from "./routes/agents";
ef3fd93Claude32import agentPipelinesRoutes from "./routes/agent-pipelines";
79136bbClaude33import issueRoutes from "./routes/issues";
85c4e13Claude34import milestonesRoutes from "./routes/milestones";
f928118Claude35import shipAgentRoutes from "./routes/ship-agent";
cb5a796Claude36import commentModerationRoutes from "./routes/comment-moderation";
79136bbClaude37import repoSettings from "./routes/repo-settings";
479dcd9Claude38import automationSettingsRoutes from "./routes/automation-settings";
23d1a81Claude39import collaboratorRoutes from "./routes/collaborators";
04f6b7fClaude40import teamCollaboratorRoutes from "./routes/team-collaborators";
41import invitesRoutes from "./routes/invites";
42import liveEventsRoutes from "./routes/live-events";
3c03977Claude43import prLiveRoutes from "./routes/pr-live";
79136bbClaude44import compareRoutes from "./routes/compare";
0074234Claude45import pullRoutes from "./routes/pulls";
79ed944Claude46import prSandboxRoutes from "./routes/pr-sandbox";
9b3a183Claude47import devEnvRoutes from "./routes/dev-env";
0074234Claude48import editorRoutes from "./routes/editor";
6f2809fClaude49import aiEditorRoutes from "./routes/ai-editor";
c81ab7aClaude50import forkRoutes from "./routes/fork";
51import webhookRoutes from "./routes/webhooks";
52import exploreRoutes from "./routes/explore";
53import tokenRoutes from "./routes/tokens";
43de941Claude54import contributorRoutes from "./routes/contributors";
699e5c7Claude55import healthRoutes from "./routes/health-probe";
56import healthDashboardRoutes from "./routes/health";
2316be6Claude57import statusRoutes from "./routes/status";
b1be050CC LABS App58import adminStatusRoutes from "./routes/admin-status";
80bed05Claude59import helpRoutes from "./routes/help";
e1fc7dbClaude60import changelogRoutes from "./routes/changelog";
e0e4219Claude61import docsRoutes from "./routes/docs";
b0148e9Claude62import marketingRoutes from "./routes/marketing";
5f2e749Claude63import pricingRoutes from "./routes/pricing";
9f29b65Claude64import enterpriseRoutes from "./routes/enterprise";
5618f9aClaude65import seoRoutes from "./routes/seo";
05cdb85Claude66import versionRoutes from "./routes/version";
f295f78Dictation App67import { platformStatus } from "./routes/platform-status";
52ad8b1Claude68import publicStatsRoutes from "./routes/public-stats";
69import demoRoutes from "./routes/demo";
16b325cClaude70import insightRoutes from "./routes/insights";
8286942Claude71import engineeringInsightsRoutes from "./routes/engineering-insights";
8d1483cClaude72import doraRoutes from "./routes/dora";
f1ab587Claude73import dashboardRoutes from "./routes/dashboard";
36b4cbdClaude74import legalRoutes from "./routes/legal";
4b66018Claude75import legalDmcaRoutes from "./routes/legal/dmca";
76import legalTermsRoutes from "./routes/legal/terms";
77import legalPrivacyRoutes from "./routes/legal/privacy";
78import legalAcceptableUseRoutes from "./routes/legal/acceptable-use";
bdbd0deClaude79import importRoutes from "./routes/import";
14c3cc8Claude80import importBulkRoutes from "./routes/import-bulk";
f390cfaCC LABS App81import importSecretsRoutes from "./routes/import-secrets";
bb2dea9Claude82import actionsImporterRoutes from "./routes/actions-importer";
14c3cc8Claude83import migrationRoutes from "./routes/migrations";
ba23fe2Claude84import migrationAssistantRoutes from "./routes/migration-assistant";
9a8b8deClaude85import migrateRoutes from "./routes/migrate";
14c3cc8Claude86import specsRoutes from "./routes/specs";
23d0abfClaude87import refactorRoutes from "./routes/refactors";
b665cacClaude88import codebaseMigratorRoutes from "./routes/codebase-migrator";
79136bbClaude89import webRoutes from "./routes/web";
0316dbbClaude90import hookRoutes from "./routes/hooks";
91import eventsRoutes from "./routes/events";
92import passkeyRoutes from "./routes/passkeys";
93import oauthRoutes from "./routes/oauth";
369ad65ccanty labs94import wellKnownRoutes from "./routes/well-known";
0316dbbClaude95import developerAppsRoutes from "./routes/developer-apps";
96import themeRoutes from "./routes/theme";
97import auditRoutes from "./routes/audit";
98import reactionRoutes from "./routes/reactions";
99import savedReplyRoutes from "./routes/saved-replies";
100import deploymentRoutes from "./routes/deployments";
2c61840Claude101import pipelineRoutes from "./routes/pipeline";
0316dbbClaude102import orgRoutes from "./routes/orgs";
103import notificationRoutes from "./routes/notifications";
104import onboardingRoutes from "./routes/onboarding";
105import adminRoutes from "./routes/admin";
7293c67Claude106import adminDeletionsRoutes from "./routes/admin-deletions";
107import adminStripeRoutes from "./routes/admin-stripe";
f764c07Claude108import adminDeploysRoutes from "./routes/admin-deploys";
109import adminDeploysPageRoutes from "./routes/admin-deploys-page";
783dd46Claude110import adminServerTargetsRoutes from "./routes/admin-server-targets";
9aaa128Claude111import deployTargetsRoutes from "./routes/deploy-targets";
90c7531Claude112import claudeWebRoutes from "./routes/claude-web";
9dd96b9Test User113import adminOpsRoutes from "./routes/admin-ops";
f2c00b4CC LABS App114import adminSelfHostRoutes from "./routes/admin-self-host";
826eccfTest User115import adminDiagnoseRoutes from "./routes/admin-diagnose";
f9814d2Claude116import adminCommandRoutes from "./routes/admin-command";
509c376Claude117import adminIntegrationsRoutes from "./routes/admin-integrations";
bc519aeClaude118import adminEnvHealthRoutes from "./routes/admin-env-health";
79ed944Claude119import adminAdvancementRoutes from "./routes/admin-advancement";
ba9e143Claude120import adminSecurityRoutes from "./routes/admin-security";
121import settingsSessionsRoutes from "./routes/settings-sessions";
0316dbbClaude122import advisoriesRoutes from "./routes/advisories";
123import aiChangelogRoutes from "./routes/ai-changelog";
0a69faaClaude124import explainRoutes from "./routes/explain";
0316dbbClaude125import aiExplainRoutes from "./routes/ai-explain";
2be65d0Claude126import archaeologyRoutes from "./routes/ai-archaeology";
0316dbbClaude127import aiTestsRoutes from "./routes/ai-tests";
128import askRoutes from "./routes/ask";
38d31d3Claude129import repoChatRoutes from "./routes/repo-chat";
ee7e577Claude130import personalChatRoutes from "./routes/personal-chat";
0316dbbClaude131import billingRoutes from "./routes/billing";
8809b87Claude132import billingUsageRoutes from "./routes/billing-usage";
6778ad2Claude133import stripeWebhookRoutes from "./routes/stripe-webhook";
0316dbbClaude134import codeScanningRoutes from "./routes/code-scanning";
da3fc18Claude135import securityRoutes from "./routes/security";
0316dbbClaude136import commitStatusesRoutes from "./routes/commit-statuses";
137import copilotRoutes from "./routes/copilot";
f5d020fClaude138import { pairProgrammerRoutes } from "./routes/pair-programmer";
0316dbbClaude139import depUpdaterRoutes from "./routes/dep-updater";
140import depsRoutes from "./routes/deps";
141import discussionsRoutes from "./routes/discussions";
142import environmentsRoutes from "./routes/environments";
4bbacbeClaude143import previewsRoutes from "./routes/previews";
79ed944Claude144import docsTrackingRoutes from "./routes/docs-tracking";
0316dbbClaude145import followsRoutes from "./routes/follows";
146import gatesRoutes from "./routes/gates";
147import gistsRoutes from "./routes/gists";
148import graphqlRoutes from "./routes/graphql";
2c2163eClaude149import mcpRoutes from "./routes/mcp";
0316dbbClaude150import marketplaceRoutes from "./routes/marketplace";
5ca514aClaude151import marketplaceAgentsRoutes from "./routes/marketplace-agents";
0316dbbClaude152import mergeQueueRoutes from "./routes/merge-queue";
153import mirrorsRoutes from "./routes/mirrors";
154import orgInsightsRoutes from "./routes/org-insights";
2be65d0Claude155import orgHealthRoutes from "./routes/org-health";
0316dbbClaude156import packagesRoutes from "./routes/packages";
157import packagesApiRoutes from "./routes/packages-api";
845fd8aClaude158import ociRegistryRoutes from "./routes/oci-registry";
0316dbbClaude159import pagesRoutes from "./routes/pages";
160import projectsRoutes from "./routes/projects";
161import protectedTagsRoutes from "./routes/protected-tags";
162import pwaRoutes from "./routes/pwa";
46d6165Claude163import installRoutes from "./routes/install";
cd4f63bTest User164import dxtRoutes from "./routes/dxt";
662ce86Claude165import connectClaudeRoutes from "./routes/connect-claude";
ebbb527Claude166import claudeDeployRoutes from "./routes/claude-deploy";
f5b9ef5Claude167import claudeIntegration from "./routes/claude-integration";
168import connectRoutes from "./routes/connect";
05ab9b1Claude169import pushWatchRoutes from "./routes/push-watch";
170import orgSecretsRoutes from "./routes/org-secrets";
0316dbbClaude171import releasesRoutes from "./routes/releases";
172import requiredChecksRoutes from "./routes/required-checks";
173import rulesetsRoutes from "./routes/rulesets";
174import searchRoutes from "./routes/search";
175import semanticSearchRoutes from "./routes/semantic-search";
77cf834Claude176import nlSearchRoutes from "./routes/nl-search";
0316dbbClaude177import signingKeysRoutes from "./routes/signing-keys";
178import sponsorsRoutes from "./routes/sponsors";
179import ssoRoutes from "./routes/sso";
3a845e4Claude180import samlSsoRoutes from "./routes/saml-sso";
181import scimRoutes from "./routes/scim";
182import orgSsoSettingsRoutes from "./routes/org-sso-settings";
46d6165Claude183import githubOauthRoutes from "./routes/github-oauth";
582cdacClaude184import googleOauthRoutes from "./routes/google-oauth";
0316dbbClaude185import symbolsRoutes from "./routes/symbols";
186import templatesRoutes from "./routes/templates";
187import trafficRoutes from "./routes/traffic";
188import wikisRoutes from "./routes/wikis";
189import workflowsRoutes from "./routes/workflows";
5ff9cc2Claude190import workflowArtifactsRoutes from "./routes/workflow-artifacts";
191import workflowSecretsRoutes from "./routes/workflow-secrets";
46d6165Claude192import sleepModeRoutes from "./routes/sleep-mode";
56801e1Claude193import standupRoutes from "./routes/standups";
52ad8b1Claude194import vsGithubRoutes from "./routes/vs-github";
45f3b73Claude195import voiceRoutes from "./routes/voice-to-pr";
3122762Claude196import blogRoutes from "./routes/blog";
cd4f63bTest User197import playgroundRoutes from "./routes/playground";
a2b3e99Claude198import crossRepoSearchRoutes from "./routes/cross-repo-search";
199import pushNotifRoutes from "./routes/push-notifications";
9fbe6cdClaude200import velocityRoutes from "./routes/velocity";
201import { staleBranchRoutes } from "./routes/stale-branches";
22f43f3Claude202import pulseRoutes from "./routes/pulse";
74d8c4dClaude203import healthScoreRoutes from "./routes/health-score";
77cf834Claude204import repoHealthRoutes from "./routes/repo-health";
74d8c4dClaude205import hotFilesRoutes from "./routes/hot-files";
bcc4020Claude206import debtMapRoutes from "./routes/debt-map";
1d6db4dClaude207import busFactorRoutes from "./routes/bus-factor";
2be65d0Claude208import testGapsRoutes from "./routes/test-gaps";
f5d020fClaude209import crossRepoImpactRoutes from "./routes/cross-repo-impact";
adf5e18Claude210import developerProgramRoutes from "./routes/developer-program";
891efbeClaude211import shareRoutes from "./routes/share";
70e3293Claude212import incidentHookRoutes from "./routes/incident-hooks";
77cf834Claude213import workspaceRoutes from "./routes/ai-workspace";
2c61840Claude214import workspaceHubRoutes from "./routes/workspace-hub";
4d4bd4bccantynz-alt215import { apiRateLimit, authRateLimit, gitRateLimit, searchRateLimit } from "./middleware/rate-limit";
59b6fb2Claude216import { csrfToken, csrfProtect } from "./middleware/csrf";
f5b9ef5Claude217import { noCache } from "./middleware/no-cache";
79136bbClaude218
2316901Claude219import type { AuthEnv } from "./middleware/auth";
bf19c50Test User220import { softAuth } from "./middleware/auth";
2316901Claude221
222const app = new Hono<AuthEnv>();
79136bbClaude223
3ef4c9dClaude224// Request context (request ID, start time) runs before everything else
225app.use("*", requestContext);
05b973eClaude226// Middleware — compression first (wraps all responses)
227app.use("*", compress());
f1ffd50Claude228
229// ETag middleware — returns 304 Not Modified on unchanged responses.
230// Saves ~95% bandwidth on repeat visits. Skipped on git protocol +
231// SSE + the API surface where it would interfere with streaming.
232app.use("*", async (c, next) => {
233 const p = c.req.path;
234 if (
235 p.includes(".git/") ||
236 p.startsWith("/live-events") ||
237 p.startsWith("/api/events/deploy") ||
3c03977Claude238 p.startsWith("/admin/status") ||
239 // PR live co-editing SSE stream — never etag streaming responses.
240 /^\/api\/v2\/pulls\/[^/]+\/live(\/|$)/.test(p)
f1ffd50Claude241 ) {
242 return next();
243 }
244 return etag()(c, next);
245});
246
247// Cache-Control middleware — sets sensible defaults on public, anonymous
9ecf5a4Claude248// requests. Vapron (when wired as our edge layer) and downstream
f1ffd50Claude249// browsers will honor these. Auth'd users get private,no-store
250// automatically — we never cache responses tied to a session.
251app.use("*", async (c, next) => {
252 await next();
253 // Don't overwrite explicit headers set by route handlers — BUT the
254 // ETag middleware unconditionally sets "private, no-cache, must-
255 // revalidate" so we have to treat that specific value as "no
256 // policy chosen yet" and apply ours. Any route that explicitly set
257 // a different cache-control wins.
258 const existing = c.res.headers.get("cache-control");
259 const etagDefault =
260 existing === "private, no-cache, must-revalidate" ||
261 existing === "no-cache";
262 if (existing && !etagDefault) return;
263 // Anything past auth: private + no-store (avoid leaking session
264 // content into shared caches). softAuth runs before this on the
265 // request, but the response side is what we're stamping.
266 const hasSession = c.req.header("cookie")?.includes("session=") ?? false;
267 const p = c.req.path;
268 // Always private for known-authed paths regardless of cookie.
269 if (
270 p.startsWith("/admin") ||
271 p.startsWith("/settings") ||
272 p.startsWith("/dashboard") ||
273 p.startsWith("/notifications") ||
274 p.startsWith("/connect/") ||
275 hasSession
276 ) {
277 c.res.headers.set("cache-control", "private, no-store");
278 return;
279 }
280 // Public marketing surfaces — short edge cache, longer browser cache,
281 // stale-while-revalidate so the user never waits on a stale fetch.
282 const isMarketing =
283 p === "/" ||
284 p === "/features" ||
285 p === "/pricing" ||
286 p === "/about" ||
287 p === "/vs-github" ||
288 p === "/explore" ||
289 p === "/help" ||
290 p === "/changelog" ||
9f29b65Claude291 p === "/enterprise" ||
f1ffd50Claude292 p.startsWith("/legal/") ||
293 p === "/terms" ||
294 p === "/privacy" ||
295 p === "/acceptable-use" ||
296 p.startsWith("/docs/");
297 if (isMarketing) {
298 c.res.headers.set(
299 "cache-control",
300 "public, max-age=60, s-maxage=300, stale-while-revalidate=86400"
301 );
302 return;
303 }
304 // Public repo browse pages — cache aggressively. Edge invalidates
9ecf5a4Claude305 // on push via the post-receive hook (future Vapron surge purge).
f1ffd50Claude306 if (/^\/[^/]+\/[^/]+(\/.*)?$/.test(p) && c.req.method === "GET") {
307 c.res.headers.set(
308 "cache-control",
309 "public, max-age=30, s-maxage=120, stale-while-revalidate=600"
310 );
311 return;
312 }
313 // Default: don't cache anything we haven't explicitly opted in.
314 c.res.headers.set("cache-control", "private, no-store");
315});
05b973eClaude316// Logger only on non-git routes to avoid overhead on clone/push
317app.use("*", async (c, next) => {
318 if (c.req.path.includes(".git/")) return next();
319 return logger()(c, next);
320});
79136bbClaude321app.use("/api/*", cors());
bf19c50Test User322// Global softAuth — populates c.get("user") for every downstream middleware
323// + route. This was previously per-route, which meant rate-limit middleware
324// (and anything else inspecting auth state) always saw a null user. Keep
325// individual routes free to add requireAuth on top for hard gating; this
326// just establishes the user object cheaply.
327app.use("*", softAuth);
290ea77Claude328
36cc17aClaude329// Force-revalidate HTML on every request — kills browser cache holding stale
290ea77Claude330// pre-redesign markup. JSON / static assets keep their own cache rules; only
331// text/html responses get the no-cache stamp. Without this, every push to
332// main left users staring at cached 80s-looking pages from before the design
333// landed.
36cc17aClaude334//
335// We deliberately use `private, no-cache, must-revalidate` rather than
336// `no-store`. `no-store` disables Safari/Chrome's back-forward cache (bfcache),
337// which makes every Back/Forward press a cold server round-trip — that
338// contributed to the "every nav feels like a fresh login" UX complaint.
339// `no-cache` still revalidates on direct fetch but lets bfcache hold the
340// page in memory between navigations.
290ea77Claude341app.use("*", async (c, next) => {
342 await next();
343 const ct = c.res.headers.get("content-type") || "";
344 if (ct.startsWith("text/html")) {
36cc17aClaude345 c.header("cache-control", "private, no-cache, must-revalidate");
290ea77Claude346 }
347});
826eccfTest User348// Rate-limit API + auth endpoints.
349//
a41e675Test User350// `/api/*`: 1000/min per IP — generous so an admin clicking around the
351// operator console (or a CDN/proxy concentrating multiple users behind one
352// IP) doesn't hit the wall. Bot-resistant headroom comes from the auth
353// rate limits below, not this one.
354//
355// `authedMultiplier` is set but only fires when an upstream middleware has
356// already populated c.get("user") — most app.use() chains apply softAuth
357// per-route, so the multiplier is best-effort. Keep the anonymous base
358// high enough that humans never feel it.
359//
360// Skip-paths: dashboard plumbing endpoints that the layout polls on a
361// fixed cadence and that we don't want consuming any bucket:
362// /api/version — layout polls every 15s
826eccfTest User363// /api/notifications/count — nav bell unread-count fetcher
364// /pwa/vapid-public-key — fetched once per push-notification opt-in
365app.use(
366 "/api/*",
a41e675Test User367 rateLimit(1000, 60_000, "api", {
826eccfTest User368 authedMultiplier: 4,
369 skipPaths: ["/api/version", "/api/notifications/count", "/pwa/vapid-public-key"],
370 })
371);
0316dbbClaude372app.use("/login", rateLimit(20, 60_000, "login"));
373app.use("/register", rateLimit(10, 60_000, "register"));
c63b860Claude374// BLOCK P1 — throttle forgot-password to deter enumeration + mail spam.
375app.use("/forgot-password", rateLimit(5, 60_000, "forgot-password"));
cd4f63bTest User376// BLOCK Q2 — throttle magic-link sign-in for the same reason.
377app.use("/login/magic", rateLimit(5, 60_000, "magic-link"));
79136bbClaude378
59b6fb2Claude379// CSRF protection — set token on all requests, validate on mutations
380app.use("*", csrfToken);
381app.use("*", csrfProtect);
382
45e31d0Claude383// Rate limit auth routes
384app.use("/login", authRateLimit);
385app.use("/register", authRateLimit);
386
59b6fb2Claude387// Rate limit git operations
388app.use("/:owner/:repo.git/*", gitRateLimit);
389
390// Rate limit search
391app.use("/:owner/:repo/search", searchRateLimit);
392app.use("/explore", searchRateLimit);
79136bbClaude393
4d4bd4bccantynz-alt394// Rate limit the v1 REST API and the MCP surface. api-v2 already applies its
395// own apiRateLimit internally (this stacks harmlessly for /api/v2/*); v1
396// (src/routes/api.ts) and /mcp had NO rate limiting at all despite /mcp
397// being the primary, anonymously-reachable AI-agent interface and able to
398// trigger expensive per-call work (e.g. gluecron_repo_health scans every
399// file in a repo). softAuth already runs on both, so the existing
400// authedMultiplier (4x for a signed-in caller) applies automatically.
401app.use("/api/*", apiRateLimit);
402app.use("/mcp", apiRateLimit);
403
f5b9ef5Claude404// No-cache for HTML — ensures browsers and proxies never serve stale pages.
405// The middleware only stamps text/html responses so static assets keep
406// their own cache policies unchanged.
407app.use("*", noCache);
408
79136bbClaude409// Git Smart HTTP protocol routes (must be before web routes)
410app.route("/", gitRoutes);
411
45e31d0Claude412// REST API v1 (legacy)
79136bbClaude413app.route("/", apiRoutes);
414
52ad8b1Claude415// Block L3 — /demo + /api/v2/demo/* live demo endpoints. Mounted BEFORE
416// apiV2Routes so the /api/v2/demo/* JSON endpoints win over the v2 base
417// router's catch-shape, and BEFORE adminRoutes so the live /demo page
418// wins over the legacy /demo redirect in src/routes/admin.tsx.
419app.route("/", demoRoutes);
420
0316dbbClaude421// REST API v2 (basePath /api/v2)
422app.route("/", apiV2Routes);
423
e75eddcClaude424// Agent multiplayer v1 — /api/v2/agents/* (sessions, leases, usage).
425// Mounted alongside apiV2Routes (its own basePath, no path conflict).
426app.route("/", agentsRoutes);
427
ef3fd93Claude428// Multi-agent pipeline UI — /:owner/:repo/agents (list, new, live view).
429// Must be before webRoutes (the catch-all) so the /agents sub-paths are
430// resolved before the generic tree/blob route takes over.
431app.route("/", agentPipelinesRoutes);
432
ad6d4adClaude433// Inbound API hooks (GateTest callback + backup PAT-authed /api/v1/gate-runs)
434app.route("/", hookRoutes);
21f8dbdClaude435app.route("/api/events", eventsRoutes);
ad6d4adClaude436
45e31d0Claude437// API documentation
438app.route("/", apiDocsRoutes);
4a80519Claude439app.route("/", buildAgentSpecRoutes);
a6ff0f2Claude440// PR command center — global PR dashboard with AI/GateTest/auto-merge signal
441app.route("/", pullsDashboardRoutes);
e9aa4d8Claude442// Issue command center — global issue dashboard with AI-triage + autopilot signal
443app.route("/", issuesDashboardRoutes);
444// Personal activity timeline — every event across the user's repos, with
445// AI-driven events surfaced separately (the Gluecron differentiator).
446app.route("/", activityRoutes);
447// Unified inbox — mentions + review requests + CI failures + AI events in one timeline
448app.route("/", inboxRoutes);
56801e1Claude449// AI standup feed — daily / weekly Claude-generated team brief
450app.route("/", standupRoutes);
cc34156Claude451// Smart morning digest — AI-curated daily developer queue (/digest)
452app.route("/", digestRoutes);
79136bbClaude453
454// Auth routes (register, login, logout)
455app.route("/", authRoutes);
456
c63b860Claude457// BLOCK P1 — Password reset (forgot-password + reset-password)
458app.route("/", passwordResetRoutes);
459
460// BLOCK P2 — Email verification (verify-email + resend)
461app.route("/", emailVerificationRoutes);
462
cd4f63bTest User463// BLOCK Q2 — Magic-link sign-in (/login/magic + callback)
464app.route("/", magicLinkRoutes);
465
79136bbClaude466// Settings routes (profile, SSH keys)
467app.route("/", settingsRoutes);
468
ba9e143Claude469// Session management (SOC 2 CC6.1 — /settings/sessions)
470app.route("/", settingsSessionsRoutes);
471
7298a17Claude472// 2FA / TOTP settings (Block B4)
473app.route("/", settings2faRoutes);
474
e75eddcClaude475// Agent multiplayer — /settings/agents management UI
476app.route("/", settingsAgentsRoutes);
477
1d4ff60Claude478// Chat integrations — Slack / Discord / Teams (/settings/integrations
479// + /api/v2/integrations/{slack,discord}/*). See src/lib/chat-bot.ts.
480app.route("/", settingsIntegrationsRoutes);
481app.route("/", integrationsChatRoutes);
4cd6791ccantynz-alt482// Incident hooks — /settings/incident-hooks (page) + the inbound incident
483// webhook receivers. Was imported but NEVER mounted, so the whole file was
484// dead and /settings/incident-hooks (linked from the settings nav) 404'd.
485app.route("/", incidentHookRoutes);
1d4ff60Claude486
2df1f8cClaude487// WebAuthn / passkey routes (Block B5)
488app.route("/", passkeyRoutes);
489
058d752Claude490// OAuth 2.0 provider (Block B6)
491app.route("/", oauthRoutes);
492app.route("/", developerAppsRoutes);
369ad65ccanty labs493// OAuth / agent discovery metadata (RFC 8414 + RFC 9728) — lets claude.ai,
494// Cursor, Copilot, etc. auto-discover how to authenticate.
495app.route("/", wellKnownRoutes);
058d752Claude496
6fc53bdClaude497// Theme toggle (dark/light cookie)
498app.route("/", themeRoutes);
499
500// Audit log UI
501app.route("/", auditRoutes);
502
503// Reactions API (issues, PRs, comments)
504app.route("/", reactionRoutes);
505
24cf2caClaude506// Saved replies (per-user canned comment templates)
507app.route("/", savedReplyRoutes);
508
509// Environments + deployment history UI
510app.route("/", deploymentRoutes);
2c61840Claude511// Unified CI/CD pipeline timeline
512app.route("/", pipelineRoutes);
24cf2caClaude513
6563f0aClaude514// Organizations + teams (Block B1)
515app.route("/", orgRoutes);
516
c81ab7aClaude517// API tokens
518app.route("/", tokenRoutes);
519
59b6fb2Claude520// Notifications
3ef4c9dClaude521app.route("/", notificationRoutes);
522
79136bbClaude523// Repo settings (description, visibility, delete)
524app.route("/", repoSettings);
479dcd9Claude525// Per-repo automation settings (off / suggest / auto) — migration 0106
526app.route("/", automationSettingsRoutes);
79136bbClaude527
23d1a81Claude528// Repo collaborators (add/list/remove)
529app.route("/", collaboratorRoutes);
530
04f6b7fClaude531// Team-based repo collaborators (invite a whole team)
532app.route("/", teamCollaboratorRoutes);
533
534// Collaborator invite accept flow (token-based)
535app.route("/", invitesRoutes);
536
537// Real-time SSE endpoint (topic-based live updates)
538app.route("/", liveEventsRoutes);
539
3c03977Claude540// PR live co-editing — presence + cursors + content sync via SSE.
541app.route("/", prLiveRoutes);
542
c81ab7aClaude543// Webhooks management
544app.route("/", webhookRoutes);
545
79136bbClaude546// Compare view (branch diffs)
547app.route("/", compareRoutes);
548
549// Issue tracker
550app.route("/", issueRoutes);
551
85c4e13Claude552// Milestones — group issues + PRs toward a shared goal with due dates + progress tracking.
553// Mounted after issueRoutes so /:owner/:repo/issues/* paths win before the milestone patterns.
554app.route("/", milestonesRoutes);
555
f928118Claude556// Ship Agent — autonomous AI feature implementation
557app.route("/", shipAgentRoutes);
558
77cf834Claude559// AI Copilot Workspace — issue-to-PR autonomous agent
560app.route("/", workspaceRoutes);
2c61840Claude561app.route("/", workspaceHubRoutes);
77cf834Claude562
cb5a796Claude563// Comment moderation queue — owner-only `/:owner/:repo/comments/pending`
564// + per-row approve/reject/spam actions. Mounted before `pullRoutes` so
565// the `/:owner/:repo/comments/*` paths resolve before the broader PR
566// patterns kick in.
567app.route("/", commentModerationRoutes);
568
0074234Claude569// Pull requests
570app.route("/", pullRoutes);
09d5f39Claude571
2be65d0Claude572// Streaming PR review — SSE stream + embeddable widget
573// Mounted immediately after pullRoutes so /:owner/:repo/pulls/:number/review/*
574// resolves before the webRoutes catch-all takes over.
575import streamingReviewRoutes from "./routes/streaming-review";
576app.route("/", streamingReviewRoutes);
577
09d5f39Claude578// /stage PR preview — serve built static files from .stage-previews/{jobId}/
579// Registered immediately after pullRoutes so the path `/preview/:id/*` is
580// specific enough to never clash with repo browse routes (`/:owner/:repo/*`).
581app.get("/preview/:stageJobId/*", async (c) => {
582 const { stageJobId } = c.req.param();
583 // Validate job ID format (UUID)
584 if (!/^[0-9a-f-]{32,}$/i.test(stageJobId)) {
585 return c.text("Not found", 404);
586 }
587 const { getPreviewDir, isPreviewExpired } = await import("./lib/pr-stage");
588 if (isPreviewExpired(stageJobId)) {
589 return c.html(
590 "<html><body style='font-family:sans-serif;padding:40px;color:#888'>" +
591 "<h2>Preview expired</h2><p>This stage preview has expired (48h TTL). " +
592 "Comment <code>/stage</code> on the PR to redeploy.</p></body></html>",
593 410
594 );
595 }
596 const { join } = await import("path");
597 const previewDir = getPreviewDir(stageJobId);
598 // Extract the wildcard path after /preview/:id/
599 const rawPath = c.req.path.replace(/^\/preview\/[^/]+/, "") || "/";
600 const filePath = rawPath === "/" || rawPath === "" ? "/index.html" : rawPath;
601 const fullPath = join(previewDir, filePath);
602 const file = Bun.file(fullPath);
603 if (!(await file.exists())) {
604 // Try index.html fallback (SPA behaviour)
605 const indexFile = Bun.file(join(previewDir, "index.html"));
606 if (await indexFile.exists()) {
607 const html = await indexFile.text();
608 return c.html(html);
609 }
610 return c.text("Not found", 404);
611 }
612 const content = await file.arrayBuffer();
613 const ext = fullPath.split(".").pop()?.toLowerCase() ?? "";
614 const contentTypeMap: Record<string, string> = {
615 html: "text/html; charset=utf-8",
616 htm: "text/html; charset=utf-8",
617 css: "text/css; charset=utf-8",
618 js: "application/javascript; charset=utf-8",
619 mjs: "application/javascript; charset=utf-8",
620 json: "application/json; charset=utf-8",
621 png: "image/png",
622 jpg: "image/jpeg",
623 jpeg: "image/jpeg",
624 gif: "image/gif",
625 svg: "image/svg+xml",
626 ico: "image/x-icon",
627 webp: "image/webp",
628 woff: "font/woff",
629 woff2: "font/woff2",
630 ttf: "font/ttf",
631 txt: "text/plain; charset=utf-8",
632 xml: "application/xml",
633 webmanifest: "application/manifest+json",
634 };
635 const ct = contentTypeMap[ext] ?? "application/octet-stream";
636 return c.body(content, 200, {
637 "content-type": ct,
638 "cache-control": "public, max-age=300",
639 "x-stage-job-id": stageJobId,
640 });
641});
642
79ed944Claude643// PR sandboxes — runnable per-PR environments. Migration 0067.
644app.route("/", prSandboxRoutes);
0074234Claude645
9b3a183Claude646// Cloud dev environments — hosted VS Code in the browser. Migration 0072.
647app.route("/", devEnvRoutes);
648
c81ab7aClaude649// Fork
650app.route("/", forkRoutes);
651
0074234Claude652// Web file editor
653app.route("/", editorRoutes);
654
6f2809fClaude655// AI editor API routes (inline suggestions, explain, fix)
656app.route("/", aiEditorRoutes);
657
43de941Claude658// Contributors
659app.route("/", contributorRoutes);
660
699e5c7Claude661// Health liveness + metrics endpoints
2c34075Claude662app.route("/", healthRoutes);
663
f295f78Dictation App664// Cross-product platform status (public, CORS-open — see docs/PLATFORM_STATUS.md)
665app.route("/api/platform-status", platformStatus);
666
52ad8b1Claude667// Block L4 — Public stats counters (powers landing-page social proof)
668app.route("/", publicStatsRoutes);
669
670// Block L3 — Live /demo page + /api/v2/demo/* endpoints
671app.route("/", demoRoutes);
672
2316be6Claude673// Public /status — human-readable platform health page
674app.route("/", statusRoutes);
675
b1be050CC LABS App676// BLOCK S4 — Site-admin synthetic-monitor dashboard (/admin/status).
677// Mounted near the public status route so the two surfaces are visible
678// side-by-side; routes are gated by isSiteAdmin internally.
679app.route("/", adminStatusRoutes);
680
80bed05Claude681// /help — quickstart + API cheatsheet
682app.route("/", helpRoutes);
683
e0e4219Claude684// /docs — expanded documentation site (getting started, workflow YAML, MCP, API, agents)
685app.route("/", docsRoutes);
686
5f2e749Claude687// L8 — public /pricing page (free-tier polish). Mounted BEFORE marketing
688// so the new editorial pricing layout wins the route; the legacy marketing
689// pricing remains as a safety net but is shadowed at the router.
690app.route("/", pricingRoutes);
691
e1fc7dbClaude692// /changelog — manually curated platform release history
693app.route("/", changelogRoutes);
694
9f29b65Claude695// Enterprise sales page + contact form lead capture.
696app.route("/", enterpriseRoutes);
697
b0148e9Claude698// /pricing, /features, /about — marketing surface
699app.route("/", marketingRoutes);
700
adf5e18Claude701// /developer-program — partner + marketplace revenue-share page
702app.route("/", developerProgramRoutes);
703
5618f9aClaude704// SEO: robots.txt + sitemap.xml
705app.route("/", seoRoutes);
706
05cdb85Claude707// /api/version — live build SHA + uptime; client poller uses this to
708// surface 'New version available — reload' banners on deploy.
709app.route("/", versionRoutes);
710
ad189d6ccantynz-alt711// Site-admin console (admin.tsx). MUST be mounted BEFORE healthDashboardRoutes
712// — its generic GET `/:owner/:repo/health` (matching :owner=admin :repo=autopilot)
713// was shadowing `/admin/autopilot/health`, returning a real "repo not found"
714// 404 for a route that exists and works fine once actually reached. Same bug
715// class as the adminOpsRoutes/insightRoutes note below; found via a live
716// production HTTP sweep (curled all 201 static page routes) — the health
717// dashboard existing didn't stop this specific admin page being unreachable.
718app.route("/", adminRoutes);
719
76ee7bcccantynz-alt720// Org health — MUST be mounted BEFORE healthDashboardRoutes. Its literal
721// `/orgs/:slug/health` was shadowed by healthDashboardRoutes' generic
722// `/:owner/:repo/health` (matching :owner=orgs :repo=<slug>), so every
723// org-health page 404'd and the whole feature was dead. Mirrors the
724// orgInsightsRoutes-before-insightRoutes fix below. org-health only matches
725// the literal `/orgs/...` prefix, so mounting it first is safe.
726app.route("/", orgHealthRoutes);
727
699e5c7Claude728// Health dashboard (per-repo health page)
729app.route("/", healthDashboardRoutes);
730
9dd96b9Test User731// Block R1 — site-admin operations console. MUST be mounted BEFORE
732// insightRoutes because its POST `/:owner/:repo/rollback` catch-all would
733// otherwise intercept `/admin/ops/rollback` (matching :owner=admin :repo=ops).
734app.route("/", adminOpsRoutes);
f2c00b4CC LABS App735// BLOCK W — Self-host status + bootstrap dashboard.
736app.route("/", adminSelfHostRoutes);
826eccfTest User737// BLOCK X — AI health-scan diagnose page (/admin/diagnose).
738app.route("/", adminDiagnoseRoutes);
f9814d2Claude739// Unified admin command center — /admin/command
740app.route("/", adminCommandRoutes);
9dd96b9Test User741
6a645f0ccantynz-alt742// Org insights — MUST be mounted BEFORE insightRoutes. insightRoutes' repo
743// insights hub (GET /:owner/:repo/insights) would otherwise match
744// /orgs/:slug/insights (owner="orgs") and 404 it before the org router runs.
745// Same route-shadowing class as the adminOps/insights note above. org-insights
746// only matches the literal "/orgs/..." prefix, so mounting it first is safe.
747app.route("/", orgInsightsRoutes);
748
749// Insights (repo insights hub, time-travel, dependencies, rollback)
16b325cClaude750app.route("/", insightRoutes);
751
8286942Claude752// Engineering Intelligence Dashboard — /insights + /:owner/:repo/insights/engineering
753app.route("/", engineeringInsightsRoutes);
754
8d1483cClaude755// DORA metrics page (/:owner/:repo/insights/dora)
756app.route("/", doraRoutes);
757
f1ab587Claude758// Command center dashboard
759app.route("/", dashboardRoutes);
760
36b4cbdClaude761// Legal pages (terms, privacy, AUP)
762app.route("/", legalRoutes);
4b66018Claude763// Long-form legal sub-pages — /legal/{terms,privacy,acceptable-use,dmca}.
764// The main `legal.tsx` serves the short canonical paths (/terms, /privacy,
765// /acceptable-use); these are the formal versions that the legal pages
766// internally link to each other.
767app.route("/", legalTermsRoutes);
768app.route("/", legalPrivacyRoutes);
769app.route("/", legalAcceptableUseRoutes);
770app.route("/", legalDmcaRoutes);
36b4cbdClaude771
bdbd0deClaude772// GitHub import / migration
773app.route("/", importRoutes);
14c3cc8Claude774app.route("/", importBulkRoutes);
f390cfaCC LABS App775app.route("/", importSecretsRoutes);
bb2dea9Claude776// GitHub Actions → Gluecron gates.yml importer (stateless converter)
777app.route("/", actionsImporterRoutes);
14c3cc8Claude778app.route("/", migrationRoutes);
ba23fe2Claude779app.route("/", migrationAssistantRoutes);
9a8b8deClaude780// GitHub Org Migration Wizard — live progress bulk importer
781app.route("/", migrateRoutes);
14c3cc8Claude782
783// Spec-to-PR (experimental AI-generated draft PRs)
784app.route("/", specsRoutes);
23d0abfClaude785app.route("/", refactorRoutes);
b665cacClaude786app.route("/", codebaseMigratorRoutes);
bdbd0deClaude787
c81ab7aClaude788// Explore page
789app.route("/", exploreRoutes);
790
59b6fb2Claude791// Onboarding
792app.route("/", onboardingRoutes);
793
ad189d6ccantynz-alt794// Admin + feature routes (adminRoutes itself is mounted earlier — see the
795// comment above healthDashboardRoutes)
7293c67Claude796app.route("/", adminDeletionsRoutes);
797app.route("/", adminStripeRoutes);
ba9e143Claude798
799// SOC 2 security dashboard + readiness checklist (/admin/security, /admin/soc2)
800app.route("/", adminSecurityRoutes);
509c376Claude801app.route("/", adminIntegrationsRoutes);
bc519aeClaude802app.route("/", adminEnvHealthRoutes);
79ed944Claude803app.route("/", adminAdvancementRoutes);
f764c07Claude804app.route("/", adminDeploysRoutes);
805app.route("/", adminDeploysPageRoutes);
783dd46Claude806app.route("/", adminServerTargetsRoutes);
9aaa128Claude807app.route("/", deployTargetsRoutes);
90c7531Claude808app.route("/", claudeWebRoutes);
9dd96b9Test User809// Note: adminOpsRoutes is mounted earlier (before insightRoutes) — see comment above.
0316dbbClaude810app.route("/", advisoriesRoutes);
811app.route("/", aiChangelogRoutes);
0a69faaClaude812// "Explain This Repo" — rich structured AI analysis dashboard (mounted before
813// the simpler aiExplainRoutes so the new routes win on /:owner/:repo/explain).
814app.route("/", explainRoutes);
0316dbbClaude815app.route("/", aiExplainRoutes);
2be65d0Claude816app.route("/", archaeologyRoutes);
0316dbbClaude817app.route("/", aiTestsRoutes);
818app.route("/", askRoutes);
38d31d3Claude819app.route("/", repoChatRoutes);
ee7e577Claude820// Personal cross-repo chat — `/chat` (user-scoped). Mounted alongside
821// repoChatRoutes so the two surfaces share the catch-all priority.
822app.route("/", personalChatRoutes);
0316dbbClaude823app.route("/", billingRoutes);
8809b87Claude824app.route("/", billingUsageRoutes);
6778ad2Claude825app.route("/", stripeWebhookRoutes);
0316dbbClaude826app.route("/", codeScanningRoutes);
da3fc18Claude827// Dependency CVE scanner findings page — /:owner/:repo/security/vulnerabilities
828app.route("/", securityRoutes);
0316dbbClaude829app.route("/", commitStatusesRoutes);
830app.route("/", copilotRoutes);
f5d020fClaude831app.route("/", pairProgrammerRoutes);
0316dbbClaude832app.route("/", depUpdaterRoutes);
833app.route("/", depsRoutes);
834app.route("/", discussionsRoutes);
835app.route("/", environmentsRoutes);
4bbacbeClaude836app.route("/", previewsRoutes);
79ed944Claude837app.route("/", docsTrackingRoutes);
0316dbbClaude838app.route("/", followsRoutes);
839app.route("/", gatesRoutes);
840app.route("/", gistsRoutes);
841app.route("/", graphqlRoutes);
2c2163eClaude842app.route("/", mcpRoutes);
8102dd4ccantynz-alt843// marketplaceAgentsRoutes MUST precede marketplaceRoutes: the latter defines
844// the generic `/marketplace/:slug`, which otherwise swallows the literal
845// `/marketplace/agents` (and `/marketplace/agents/publish`) and 404s them as
846// unknown app slugs.
5ca514aClaude847app.route("/", marketplaceAgentsRoutes);
8102dd4ccantynz-alt848app.route("/", marketplaceRoutes);
0316dbbClaude849app.route("/", mergeQueueRoutes);
850app.route("/", mirrorsRoutes);
76ee7bcccantynz-alt851// orgInsightsRoutes + orgHealthRoutes are mounted earlier (before the generic
852// repo routes) — see the notes there.
0316dbbClaude853app.route("/", packagesRoutes);
854app.route("/", packagesApiRoutes);
845fd8aClaude855// OCI / Docker container registry — /v2/* (OCI Distribution Spec v1.0)
856app.route("/", ociRegistryRoutes);
0316dbbClaude857app.route("/", pagesRoutes);
858app.route("/", projectsRoutes);
859app.route("/", protectedTagsRoutes);
860app.route("/", pwaRoutes);
46d6165Claude861app.route("/", installRoutes);
cd4f63bTest User862// BLOCK Q1 — /gluecron.dxt download (Claude Desktop one-click extension)
863app.route("/", dxtRoutes);
662ce86Claude864// Connect Claude — user-facing one-click MCP setup (/connect/claude). Mounted
865// next to the other one-click flows (install.sh + .dxt) for surface symmetry.
866app.route("/", connectClaudeRoutes);
f5b9ef5Claude867// Claude Code Integration Receiver — /api/claude/connect + /api/claude/session.
868app.route("/", claudeIntegration);
869// Connect guide — public onboarding page (/connect/claude-guide).
870app.route("/", connectRoutes);
05ab9b1Claude871// Push Watch — per-commit live status (gates + deploy + latency) at /:owner/:repo/push/:sha
872app.route("/", pushWatchRoutes);
873// Org Secrets Manager — BLOCK M2 — /orgs/:slug/settings/secrets
874app.route("/", orgSecretsRoutes);
a2b3e99Claude875// Cross-repo code search — BLOCK M3 — /search/code + /api/search/code
876app.route("/", crossRepoSearchRoutes);
877// Browser push notifications — BLOCK M4 — /settings/notifications/push + /api/push/*
878app.route("/", pushNotifRoutes);
9fbe6cdClaude879// Developer Velocity Dashboard — BLOCK M9 — /:owner/:repo/insights/velocity
880app.route("/", velocityRoutes);
881// Stale Branch Cleanup — BLOCK M10 — /:owner/:repo/branches/stale
882app.route("/", staleBranchRoutes);
22f43f3Claude883// Repository Pulse — BLOCK M12 — /:owner/:repo/pulse
884app.route("/", pulseRoutes);
74d8c4dClaude885// Repository Health Score — BLOCK M14 — /:owner/:repo/insights/health
886app.route("/", healthScoreRoutes);
77cf834Claude887// Repository Health Score breakdown page — /:owner/:repo/health
888app.route("/", repoHealthRoutes);
74d8c4dClaude889// Hot Files Heatmap — BLOCK M16 — /:owner/:repo/insights/hotfiles
890app.route("/", hotFilesRoutes);
bcc4020Claude891// AI Technical Debt Map — /:owner/:repo/debt-map (visual debt graph + Claude analysis)
892app.route("/", debtMapRoutes);
1d6db4dClaude893// Bus Factor Analysis — /:owner/:repo/insights/bus-factor
894app.route("/", busFactorRoutes);
b02ce30Claude895// Test Gap Detector — /:owner/:repo/insights/test-gaps
896app.route("/", testGapsRoutes);
f5d020fClaude897// Cross-Repo Dependency Impact Detection — /:owner/:repo/pulls/:number/cross-repo-impact
898app.route("/", crossRepoImpactRoutes);
ebbb527Claude899// Hosted Claude tool-use loops — paste loop, get endpoint, billing meter.
900// See src/routes/claude-deploy.tsx + src/lib/hosted-claude-loop.ts.
901app.route("/", claudeDeployRoutes);
0316dbbClaude902app.route("/", releasesRoutes);
903app.route("/", requiredChecksRoutes);
904app.route("/", rulesetsRoutes);
905app.route("/", searchRoutes);
906app.route("/", semanticSearchRoutes);
77cf834Claude907app.route("/", nlSearchRoutes);
0316dbbClaude908app.route("/", signingKeysRoutes);
909app.route("/", sponsorsRoutes);
910app.route("/", ssoRoutes);
3a845e4Claude911// Enterprise per-org SAML 2.0 + OIDC SSO routes
912app.route("/", samlSsoRoutes);
913// SCIM 2.0 user provisioning endpoints
914app.route("/", scimRoutes);
915// Per-org SSO + SCIM admin settings UI
916app.route("/", orgSsoSettingsRoutes);
46d6165Claude917app.route("/", githubOauthRoutes);
582cdacClaude918app.route("/", googleOauthRoutes);
0316dbbClaude919app.route("/", symbolsRoutes);
920app.route("/", templatesRoutes);
921app.route("/", trafficRoutes);
922app.route("/", wikisRoutes);
923app.route("/", workflowsRoutes);
5ff9cc2Claude924app.route("/", workflowArtifactsRoutes);
925app.route("/", workflowSecretsRoutes);
46d6165Claude926app.route("/", sleepModeRoutes);
52ad8b1Claude927app.route("/", vsGithubRoutes);
0316dbbClaude928
45f3b73Claude929// Voice-to-PR — phone-first dictation → spec or issue
930app.route("/", voiceRoutes);
931
3122762Claude932// Blog / Devlog — public posts, no DB
933app.route("/", blogRoutes);
934
cd4f63bTest User935// Block Q3 — Anonymous playground (`/play`, `/play/claim`). Mounted
936// before the web catch-all so the bare `/play` literal wins over the
937// `/:owner` user-profile route.
938app.route("/", playgroundRoutes);
939
891efbeClaude940// Shareable AI hours-saved OG image card + landing page.
941// /share/hours-saved?user=:username → 1200×630 SVG (og:image)
942// /share/:username → HTML page with og:image meta + Twitter share
943// Mounted BEFORE webRoutes so /share/* doesn't fall through to the /:owner profile route.
944app.route("/", shareRoutes);
945
4abf6f1ccantynz-alt946// Machine surfaces must fail in the format their clients parse. An
947// unmatched /api/* path used to fall through to the HTML 404 page, so a
948// REST/MCP/registry client asking for JSON got a full HTML document and
949// blew up on JSON.parse instead of seeing a readable error. Decided by
950// path root (these mounts are JSON-only by contract) or by an Accept
951// header that asks for JSON and not HTML.
952const JSON_ROOTS = [
953 "/api",
954 "/mcp",
955 "/graphql",
956 "/v2", // OCI registry — the spec mandates a JSON error envelope
957 "/npm",
958 "/scim",
959 "/.well-known",
960];
961
962function wantsJson(c: {
963 req: { path: string; header: (n: string) => string | undefined };
964}) {
965 const path = c.req.path;
966 // Match the root exactly or as a path segment — "/mcp" and "/mcp/x" are
967 // machine surfaces, "/mcpanything" is not.
968 if (JSON_ROOTS.some((r) => path === r || path.startsWith(r + "/"))) return true;
969 const accept = c.req.header("accept") ?? "";
970 return accept.includes("application/json") && !accept.includes("text/html");
971}
972
973function jsonNotFound(c: Context) {
974 return c.json(
975 { error: "Not found", path: c.req.path, method: c.req.method },
976 404
977 );
978}
979
980// Machine-surface 404 fallback — MUST be registered before webRoutes.
981// webRoutes owns the `/:owner/:repo` catch-all, so an unmatched two-segment
982// path like `/api/nope` was being read as owner="api", repo="nope" and
983// answered with the HTML "repository not found" page. REST/MCP/OCI clients
984// then choked on HTML where they expected a JSON envelope. Terminating the
985// machine roots here keeps them JSON-only by contract.
986for (const root of JSON_ROOTS) {
987 app.all(root, (c) => jsonNotFound(c));
988 app.all(`${root}/*`, (c) => jsonNotFound(c));
989}
990
79136bbClaude991// Web UI (catch-all, must be last)
992app.route("/", webRoutes);
993
c63b860Claude994// Global 404 — BLOCK O2 routes the shared `NotFoundPage` view so
995// the markup stays consistent with /500 and the admin /403 page.
79136bbClaude996app.notFound((c) => {
4abf6f1ccantynz-alt997 if (wantsJson(c)) {
998 return c.json(
999 { error: "Not found", path: c.req.path, method: c.req.method },
1000 404
1001 );
1002 }
36cc17aClaude1003 const user = c.get("user") ?? null;
79136bbClaude1004 return c.html(
c63b860Claude1005 <NotFoundPage user={user} method={c.req.method} path={c.req.path} />,
79136bbClaude1006 404
1007 );
1008});
1009
c63b860Claude1010// Global error handler — BLOCK O2 uses the shared `ServerErrorPage`
1011// view. Trace block only shown outside production.
79136bbClaude1012app.onError((err, c) => {
80bed05Claude1013 reportError(err, {
1014 requestId: c.get("requestId"),
1015 path: c.req.path,
1016 method: c.req.method,
1017 });
c63b860Claude1018 // Prefer the inbound `x-request-id` header (LB-supplied) and fall
1019 // back to the context value set by request-context middleware.
1020 const requestId =
1021 c.req.header("x-request-id") ||
1022 ((c.get("requestId" as never) as string | undefined) ?? undefined);
36cc17aClaude1023 const user = c.get("user") ?? null;
c63b860Claude1024 const trace =
1025 process.env.NODE_ENV !== "production" && err && err.message
1026 ? err.message
1027 : undefined;
4abf6f1ccantynz-alt1028 // Same reasoning as the 404 above: an API/MCP client must get a JSON
1029 // envelope it can parse, not the HTML error page.
1030 if (wantsJson(c)) {
1031 return c.json(
1032 { error: "Internal server error", requestId, ...(trace ? { trace } : {}) },
1033 500
1034 );
1035 }
79136bbClaude1036 return c.html(
c63b860Claude1037 <ServerErrorPage user={user} requestId={requestId} trace={trace} />,
79136bbClaude1038 500
1039 );
1040});
1041
1042export default app;