Skip to content

refactor: split main.go and session.go into focused files#434

Merged
tomasz-tomczyk merged 1 commit intomainfrom
refactor/split-main-and-session
May 2, 2026
Merged

refactor: split main.go and session.go into focused files#434
tomasz-tomczyk merged 1 commit intomainfrom
refactor/split-main-and-session

Conversation

@tomasz-tomczyk
Copy link
Copy Markdown
Owner

Summary

Pure file moves, no logic changes. Splits main.go and session.go into focused files within package main to reduce per-file LOC and group related code.

New files (all package main, no API changes)

  • cli_dispatch.gocommandDispatch map, printHelp, printConfigHelp, printVersion
  • cli_serve.gorunServe + serverConfig + flag parsing + bindListener + runIdleTimeoutChecker + applySessionOverrides (the daemon-boot path)
  • cli_install.gorunInstall + installIntegration + integrationMap + destFor / installOneFile / printUniqueHints / globalDestKind helpers
  • session_focus.goFocus / FocusKind / DiffScope types + visibleInFocus + stampWithFocus + SetFocus + scoped-view computation (cachedAvailableScopes, GetSessionInfoScoped, GetFileDiffSnapshotScoped, loadScopedFileState, computeScopedDiffHunks)
  • session_write.goWriteFiles + scheduleWrite debounce + snapshotForWrite + buildCritJSON + merge* helpers + handleExternalDeletion + clearAllCommentData + critJSONIsEmpty + mergeExternalCritJSON

Before / after LOC

File Before After
main.go 3151 2150
session.go 3189 1932
cli_dispatch.go 167
cli_serve.go 573
cli_install.go 290
session_focus.go 797
session_write.go 479

Net +48 LOC across the seven files (five new package main + import headers).

Review

  • No + lines added in main.go / session.go — pure deletions, all additions land in new files
  • No duplicate funcs / types / vars across files
  • Imports hand-curated to match each new file's actual usage
  • go build, go vet, go test -race -count=1, gofmt -l, golangci-lint all clean

Test plan

  • mise exec -- go build ./...
  • mise exec -- go vet ./...
  • mise exec -- go test -race -count=1 ./... (53s, all pass)
  • mise exec -- gofmt -l .
  • mise exec -- golangci-lint run ./... (0 issues)

Followups (out of scope here)

  • main.go is still 2150 LOC — the spec only enumerated three new cli_*.go files; the remaining subcommands (runShare, runFetch, runPull, runPush, runComment, runPlan, runReview, runStop, runStatus, runCleanup, etc.) could be peeled off in a follow-up if a sub-1000 target is desired.
  • session.go is still 1932 LOC. Comment CRUD methods (AddComment through UnresolvedCommentCount, ~510 LOC) are a coherent block that could move to session_comments.go. ChangeBaseBranch (~100 LOC) is a candidate too. Skipped here to honor the spec's enumeration.

🤖 Generated with Claude Code

Pure file moves, no logic changes. Splits within package main:

- cli_dispatch.go: commandDispatch map, printHelp, printConfigHelp, printVersion
- cli_serve.go: runServe + serverConfig + flag parsing + bindListener +
  runIdleTimeoutChecker + applySessionOverrides + the daemon-boot path
- cli_install.go: runInstall + installIntegration + integrationMap +
  destFor / installOneFile / printUniqueHints / globalDestKind helpers
- session_focus.go: Focus / FocusKind / DiffScope types + visibleInFocus +
  stampWithFocus + SetFocus + scoped-view computation
  (cachedAvailableScopes, GetSessionInfoScoped, GetFileDiffSnapshotScoped,
  loadScopedFileState, computeScopedDiffHunks)
- session_write.go: WriteFiles + scheduleWrite debounce + snapshotForWrite +
  buildCritJSON + merge* helpers + handleExternalDeletion +
  clearAllCommentData + critJSONIsEmpty + mergeExternalCritJSON

main.go drops from 3151 -> 2150 LOC. session.go drops from 3189 -> 1932 LOC.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tomasz-tomczyk tomasz-tomczyk merged commit 0a958f5 into main May 2, 2026
6 checks passed
@tomasz-tomczyk tomasz-tomczyk deleted the refactor/split-main-and-session branch May 2, 2026 12:55
@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

❌ Patch coverage is 70.62193% with 359 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.39%. Comparing base (41a8795) to head (5fd0ccf).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cli_dispatch.go 0.00% 115 Missing ⚠️
cli_serve.go 72.87% 53 Missing and 30 partials ⚠️
cli_install.go 44.00% 64 Missing and 6 partials ⚠️
session_focus.go 84.07% 43 Missing and 21 partials ⚠️
session_write.go 90.14% 16 Missing and 11 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #434      +/-   ##
==========================================
+ Coverage   67.36%   67.39%   +0.03%     
==========================================
  Files          30       35       +5     
  Lines        9820     9820              
==========================================
+ Hits         6615     6618       +3     
+ Misses       2689     2687       -2     
+ Partials      516      515       -1     
Flag Coverage Δ
e2e 34.08% <55.72%> (ø)
unit 63.65% <58.83%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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