Skip to content

refactor: extract shared server handlers#211

Closed
backnotprop wants to merge 9 commits intomainfrom
qa-updates
Closed

refactor: extract shared server handlers#211
backnotprop wants to merge 9 commits intomainfrom
qa-updates

Conversation

@backnotprop
Copy link
Owner

Summary

  • Extract duplicated /api/image, /api/upload, /api/agents handlers into shared-handlers.ts (were copy-pasted across all 3 server files)
  • Extract /api/doc, /api/reference/obsidian/files, /api/reference/obsidian/doc + buildFileTree into reference-handlers.ts
  • Unify 3 identical handleServerReady functions into one shared export

Closes #210

Result

File Before After
index.ts 705 451
review.ts 323 256
annotate.ts 258 207
shared-handlers.ts 105
reference-handlers.ts 217

No behavior changes. All closure-dependent handlers (approve, deny, versions, vscode-diff) remain inline.

Test plan

  • bun run build:hook compiles cleanly
  • Plan review: approve/deny flow works
  • Image upload in annotations
  • /plannotator-review code review mode
  • Vault browser file tree + doc viewing

🤖 Generated with Claude Code

backnotprop and others added 8 commits March 3, 2026 16:00
Extract duplicated image/upload/agents handlers into shared-handlers.ts
and doc/vault reference endpoints into reference-handlers.ts. Unifies
the three identical handleServerReady functions. Closes #210.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract ~100 lines of duplicated theme variables, base styles, and
global utilities into packages/ui/base.css, imported by both editor
and review-editor CSS files.

Move formatTimestamp() from AnnotationPanel and ReviewPanel into
packages/ui/utils/format.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Delete unimplemented S3 paste store stub
- Un-export internal helpers in ImageAnnotator/utils.ts
- Un-export extractDoneSteps in pi-extension/utils.ts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Install @biomejs/biome with recommended rules
- Configure formatting to match existing conventions (2 spaces, single quotes, trailing commas)
- Enable Tailwind CSS directive parsing
- Downgrade noisy rules to warnings (a11y, exhaustive-deps, explicit-any, etc.)
- Add lint/format/check scripts to root package.json
- Add CI workflow that runs biome ci on PRs to main

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Formatting: normalize all source files to biome conventions
(2-space indent, single quotes, trailing commas, 100 char width,
sorted imports).

Lint fixes:
- Remove unused import (corsHeaders in paste-service handler)
- Remove unused variables (sharedGlobalAttachments, validateAgent,
  availableAgents, DEFAULT_SETTINGS)
- Remove unused catch parameters
- Add node: protocol to Node.js builtin imports
- Replace @ts-ignore with @ts-expect-error
- Suppress intentional document.cookie usage in storage utility

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add TODO to re-enable a11y rules once findings are addressed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reverts unsafe biome lint --write --unsafe changes that modified React
hook dependency arrays, potentially introducing stale closures and
infinite re-render bugs. Promotes useExhaustiveDependencies,
noAssignInExpressions, and noInvalidUseBeforeDeclaration from off/warn
to error with targeted inline suppressions. Reverts _onUpdate rename
in pi-extension.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
sidebar.open/close (useCallback []), vaultBrowser.setActiveFile
(useState setter), and handleCopyDiff (useCallback [diffData]) are
genuinely stable — add them to dep arrays instead of suppressing.
Fix misleading ImageAnnotator comment (handleAccept is a plain
function, not useCallback).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@backnotprop backnotprop marked this pull request as ready for review March 4, 2026 02:53
@backnotprop
Copy link
Owner Author

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

handleObsidianChange (Settings.tsx) and handleCopyDiff
(review-editor/App.tsx) were in dep arrays but defined later
in the component — const is not hoisted, so React hit
"Cannot access before initialization" at runtime.

Also updates CLAUDE.md project structure to reflect the
server handler extraction from PR #211.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@backnotprop
Copy link
Owner Author

Closing this PR. The biome integration (bunx biome lint --write --unsafe) introduced regressions that multiple fix passes failed to fully catch:

  1. TDZ crasheshandleObsidianChange and handleCopyDiff were added to dependency arrays before their const declarations, causing "Cannot access before initialization" at runtime
  2. Broken text selectioncreateAnnotationFromSource (a plain function, not useCallback) was added to the highlighter useEffect dep array, causing it to re-run every render and destroy the Highlighter instance

The non-biome work in this branch (server handler extraction, dead code removal, CSS theme extraction) was solid but is now entangled with 59 files of lint changes. Will cherry-pick the good commits into clean PRs separately.

Lessons learned documented in a new issue.

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.

Refactor: Extract shared route handlers and modularize plan server

1 participant