Skip to content

Refactor: split src/index.ts (4637 lines) into routes, server, and client modules - #39

Merged
tpaulshippy merged 4 commits into
mainfrom
refactor/split-index
Oct 20, 2026
Merged

tpaulshippy merged 4 commits into
mainfrom
refactor/split-index

Conversation

@tpaulshippy

@tpaulshippy tpaulshippy commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Pure move, no behavior change. src/index.ts goes from 4637 lines to 53 (Env, AppSession re-export, thin fetch dispatcher).

  • src/server/auth.ts — cookies, session, CORS, gates (requireAccess/requireLogin), turnConflict, resolveAuth/resolveSid, sessionJson, RouteCtx
  • src/routes/*.ts (8 files) — each exports one handle*(req, ctx): Response | null; fetch tries them in order, 404 fallthrough preserved
  • src/server/page.ts — appDoc + page() assembly
  • src/client/*.ts (11 files) — head, core helpers, and feature chunks (state, transcript, history, pane, settings-a/b, attachments, agent, tabs)

Verification:

  • served / HTML is byte-identical before/after (diffed 124,699 bytes)
  • npm run lint clean, 353/353 tests pass, check-inline-js OK (104,595 chars, 1 block)
  • no import cycles: routes import runtime only from server/auth + domain modules; index is only imported as import type

Summary by cubic

Splits the 4,637-line src/index.ts into route, server, and client modules. src/index.ts drops to 53 lines (Env type, AppSession re-export, thin fetch dispatcher), and behavior is unchanged.

Refactors

  • src/routes/*.ts (8 files) export one handle*(req, ctx) each; the dispatcher tries them in order, preserving the 404 fallthrough. /api/github/branches lives in github-repos.ts since it is a GitHub API call, not a just-git one.
  • src/server/ holds auth, session, and page-assembly helpers; the 11 src/client/*.ts chunks replace the inline template literal, assembled in a documented order by page.ts.
  • / HTML is byte-identical before/after; lint clean, 353/353 tests pass, and no import cycles were introduced.

Written for commit 24e0bc6. Summary will update on new commits.

View guided diff Turn on auto-fix

- Page head, core helpers, and 10 feature chunks (state, transcript,
  history, pane, settings-a/b, attachments, agent, tabs) move out of
  the inline template literal; page() concatenates them with the
  interpolated gateway consts and serialized helpers
- Served HTML is byte-identical (verified by diff); inline-script
  syntax check, tsc, and all 353 tests pass

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 22 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread src/routes/github-repos.ts Resolved
Comment thread src/routes/github-repos.ts Resolved
Comment thread src/client/settings-a.ts Resolved
Comment thread src/routes/share.ts Resolved
Comment thread src/client/attachments.ts Resolved
Comment thread src/routes/apps.ts Resolved
Comment thread src/routes/github-repos.ts Resolved
Comment thread src/client/core.ts Resolved
Comment thread src/client/history.ts Resolved
Comment thread src/server/auth.ts Resolved
- Move /api/github/branches to github-repos.ts (GitHub API, not just-git)
- Rename CORE_A/B to CLIENT_PRELUDE_JS/MARKDOWN_SHIM_JS and document
  the assembly ordering invariant in page.ts
- Correct resolveSid comment: legacy sids resolve directly, callers
  check the token
@tpaulshippy
tpaulshippy merged commit 856d3cc into main Oct 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant