feat(core): extract read handlers (doctor, query)#165
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Add doctorHandler and queryHandler as transport-agnostic handlers that return Result<T, E> and receive HandlerContext. doctorHandler: - Runs 6 diagnostic checks (GitHub API, auth, config, cache, repo, Graphite) - Wired into CLI doctor command (270 lines → 101 lines) - Wired into MCP handleDoctor queryHandler: - Validates input, builds QueryOptions, runs queryEntries - Applies client-side filters (PR list, types, authors, perspective) - Optionally builds worklist summary - Not yet wired into CLI/MCP query flows (requires sync untangling) View and list handlers deferred — their heavy transport-specific logic (stack handling, formatting) would push this PR beyond the 300 LOC budget. 🤘🏻 In-collaboration-with: [Claude Code](https://claude.com/claude-code)
dbcaf82 to
f07a741
Compare
289ae13 to
e353d4e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e353d4ecb8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const login = loginResult.isOk() ? loginResult.value : "unknown"; | ||
| return { | ||
| name: "Auth valid", | ||
| ok: true, | ||
| message: `${login} via ${auth.value.source}`, |
There was a problem hiding this comment.
Treat viewer lookup failures as auth check failures
fetchViewerLogin() returns a Result, but this branch maps an Err to "unknown" and still reports ok: true; with an expired or invalid token, doctor will incorrectly claim auth is valid. This makes diagnostics unreliable for real auth outages because the failing API call is swallowed instead of surfaced as a failed check.
Useful? React with 👍 / 👎.
| if (!username) { | ||
| return entries; | ||
| } |
There was a problem hiding this comment.
Reject mine/reviews filtering when username is missing
When mine or reviews is requested but no configured username is available, this returns all entries unchanged, so callers get silently unfiltered results while believing the perspective filter was applied. Existing query flows treat missing user.github_username as an error, so this behavior introduces incorrect query results rather than a clear failure.
Useful? React with 👍 / 👎.

Summary
doctorHandlerandqueryHandlertopackages/core/src/handlers/Result<T, E>with typed inputs/outputsTest plan
bun run checkpassesbun testpasses (288 tests)🤘🏻 In-collaboration-with: Claude Code
Greptile Summary
Extracts
doctorHandlerandqueryHandlertopackages/core/src/handlers/, implementing the handler contract pattern. Both CLI and MCP surfaces now call the same core handlers with typedResult<T, E>return values. Shared query logic (bot filters, sync scopes, state resolution) has been consolidated into the handlers as planned in FIRE-5.Key changes:
packages/core/src/handlers/doctor.tswith diagnostic checkspackages/core/src/handlers/query.tswith query logic consolidationapps/cli/src/commands/doctor.tsto usedoctorHandler(removed 165 lines)apps/mcp/src/index.tsto usedoctorHandlerwith formatting helpers (removed 72 lines)The refactoring successfully eliminates duplication while maintaining the same functionality across both surfaces.
Confidence Score: 5/5
Important Files Changed
doctorHandlerfrom core, removed 165 lines of duplicated logicdoctorHandler, simplified with formatting helpers, removed 72 linesFlowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD CLI[CLI doctor command] --> DH[doctorHandler] MCP[MCP fw_doctor tool] --> DH DH --> CH1[checkGithubReachable] DH --> CH2[checkAuth] DH --> CH3[checkConfigParse] DH --> CH4[checkCacheWritable] DH --> CH5[checkRepoDetection] DH --> CH6[checkGraphiteCli] DH --> GI[getGraphiteStackInfo] DH --> DO[DoctorOutput] DO --> |Result<T, E>| CLI DO --> |Result<T, E>| MCP CLI2[CLI query command] -.future.-> QH[queryHandler] MCP2[MCP fw_query tool] -.future.-> QH QH -.-> QE[queryEntries] QH -.-> CSF[applyClientSideFilters] QH -.-> BW[buildWorklist] QH -.-> QO[QueryOutput] style DH fill:#a8dadc style QH fill:#a8dadc style DO fill:#f1faee style QO fill:#f1faeeLast reviewed commit: e353d4e