Split server.ts into route modules with a typed service container#110
Closed
Split server.ts into route modules with a typed service container#110
Conversation
Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
…lities, workflows, skills, preview Extract 8 route modules from server.ts handleApiRoute(): - health.ts: /api/health, /api/setup-status, /api/shutdown + isSetupComplete() - auth.ts: /api/ca-cert, /api/connection-info, /api/oauth/* - preferences.ts: /api/preferences, /api/project-config, /api/config/cwd - models.ts: /api/models - personalities.ts: /api/personalities CRUD - workflows.ts: /api/workflows CRUD + clone + delete - skills.ts: /api/slash-skills, /api/slash-skills/details - preview.ts: /api/preview GET/POST Each module exports handle(ctx, url, req, res) => Promise<boolean>. All use AppContext from app-context.ts and json/readBody from utils.ts. Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
…els, personalities, workflows, skills, preview) Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
…bobbit into goal/split-serv-04e6c40c
… and github-service Extract route handlers from server.ts handleApiRoute() into dedicated modules: - routes/teams.ts: /api/goals/:id/team/* and /api/goals/:id/swarm/* (start, spawn, dismiss, steer, abort, prompt, agents, complete, teardown) - routes/gates.ts: /api/goals/:id/gates/* (list, detail, signal, signals, content, workflow-context, active verifications) - routes/aigw.ts: /api/aigw/*, /api/custom-providers/*, /api/provider-keys/* - routes/staff.ts: /api/staff/* (CRUD, wake, sessions) - routes/mcp.ts: /api/mcp-servers/*, /api/internal/mcp-call - routes/git.ts: /api/sessions/:id/git-*, /api/goals/:id/pr-* - services/github-service.ts: PR/git cache helpers (getViewerIsAdmin, getCachedPrStatus, execGit, execGitSafe, bustPrCache) Each module exports handle(ctx, url, req, res) => Promise<boolean>. All use AppContext from app-context.ts and readBody/json from routes/utils.ts. Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
…ask-batch-d-routes
…, git) + github-service Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
…bobbit into goal/split-serv-04e6c40c
…, tools Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
… tools) Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
…bobbit into goal/split-serv-04e6c40c
- Import AppContext/GatewayConfig from app-context.ts, re-export for compat - Build AppContext in createGateway() with all services - Replace handleApiRoute(21 params) with routeApiRequest(ctx, url, req, res) - Delete handleApiRoute, git helpers, readBody, hasTransitiveDep, isSetupComplete - Remove (sessionManager as any).bgProcessManager cast - Add missing draft/bg-process/file-content/prompt-sections routes to sessions.ts - server.ts: 363 lines (down from 3207). All 315 E2E tests pass. Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
- Add /api/config prefix to router for /api/config/cwd endpoint - Add GET /api/pr-status-cache endpoint to git.ts route module - Add GET /api/goals/:id/cost/breakdown and /cost endpoints to goals.ts - Add GET /api/tasks/:id/cost endpoint to tasks.ts - Replace local execGit/execGitSafe in goals.ts with imports from github-service - Rename _fetchPrStatus to fetchPrStatus in github-service.ts - Fix unused import warnings in aigw.ts, mcp.ts, preview.ts Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
…to 'totals') Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
- Replace 'Edit server.ts handleApiRoute()' with route module guidance - Add 'Server route architecture' section documenting AppContext, routes/, and github-service - Update goal and tool doc references from server.ts to specific route modules Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
…ons and GET /api/goals Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
…use readBody in mcp.ts Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
…o gates.ts Co-Authored-By: Bobbit (Claude Opus 4 6 (anthropic)) <noreply@bobbit.dev>
8974cfb to
4e4347a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Splits the 3,207-line
server.tsmonolith into 19 domain-grouped route modules with a typedAppContextservice container.Changes
src/server/app-context.ts—AppContextinterface (typed service container replacing 21 loose parameters)src/server/routes/index.ts— Router dispatching to 19 route modulessrc/server/routes/*.ts— health, sessions, goals, teams, gates, tasks, roles, tools, aigw, models, preferences, personalities, workflows, auth, skills, staff, mcp, git, previewsrc/server/routes/utils.ts— Shared utilities (readBody, json, hasTransitiveDep)src/server/services/github-service.ts— PR/git caching helpers extractedsrc/server/server.ts— Reduced from 3,207 to 363 linesAcceptance Criteria
AppContextinterface is the sole parameter to route handlersserver.tsunder 400 lines (363)npm run checkpassesas anycasts for service wiring