chore: remove dead code — unused exports, components, and files#641
Conversation
Removes dead code identified by knip and manual audit across app and ui
packages. Changes fall into three categories:
1. Deleted entire files with zero references:
- dialog-manage-models.tsx (unused component)
- custom-elements.d.ts (unused type declarations)
2. Removed unused exported symbols (zero external imports):
- ConstrainDragXAxis (solid-dnd)
- WorkspaceDragOverlay, SortableWorkspace, LocalWorkspace (sidebar)
- useHighlights (highlights context)
- getSessionKey (session helpers)
- currentSession (session-link)
- diff, code (storybook fixtures)
3. Demoted over-exported internals (used only within same module):
- agentColor → local function
- soundSrc, playSound → local functions
- stripFileProtocol, decodeFilePath → local functions
- getAvatarColors → local function
- MAX_TITLEBAR_HISTORY, pushPath, trimHistory → local constants/functions
- patchFile → local function
- enterWorktreeOwnerProject, enterWorktreeTarget,
exitWorktreeProjectName, exitWorktreePreviousLabel,
agentTitle → local functions (still used by exported siblings)
Test results:
- packages/app: 1071 pass / 0 fail
- packages/ui: 418 pass / 3 fail (pre-existing CSS test failures unrelated to this change)
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (15)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Suggested priority: P2 (includes user-path files (packages/app/src/components/dialog-manage-models.tsx, packages/app/src/components/titlebar-history.ts, packages/app/src/context/file/path.ts, packages/app/src/context/highlights.tsx, packages/app/src/context/layout.tsx, packages/app/src/custom-elements.d.ts, packages/app/src/pages/layout/sidebar-workspace.tsx, packages/app/src/pages/session/helpers.ts, packages/app/src/utils/agent.ts, packages/app/src/utils/solid-dnd.tsx, packages/app/src/utils/sound.ts)).
P1/P0 are reserved for maintainer confirmation. Please relabel manually if this is a release blocker, security issue, data-loss risk, or updater/runtime failure.
There was a problem hiding this comment.
Code Review
This pull request focuses on code cleanup by removing unused exports, components, and constants across multiple packages. Significant changes include internalizing previously exported functions and deleting several UI components and helpers. Feedback highlights a critical issue in packages/ui/src/components/tool-info.ts where duplicate function definitions were introduced, which will likely cause a build error. Additionally, the reviewer suggests further cleanup in sidebar-workspace.tsx to remove helper components that have become dead code following the removal of their consumers.
I am having trouble creating individual review comments. Click here to see my feedback.
packages/ui/src/components/tool-info.ts (34-50)
This block introduces duplicate definitions for enterWorktreeOwnerProject and enterWorktreeTarget, which are already defined and exported at lines 16 and 21. This will cause a redeclaration error and break the build.
To demote these functions to local scope as intended (consistent with how you handled exitWorktreeProjectName in this file), you should remove the export keyword from the existing definitions at lines 16 and 21 and remove this redundant block.
References
- Before suggesting to add a function, ensure it is not already defined within the same file or module.
packages/app/src/pages/layout/sidebar-workspace.tsx (278-462)
With the removal of SortableWorkspace and LocalWorkspace, the helper components WorkspaceHeader, WorkspaceActions, and WorkspaceSessionList (defined in lines 54-249) no longer have any consumers in this file and are not exported. They should also be removed to complete the dead code cleanup.
Two typecheck failures from the dead-code cleanup: - session-link.ts: currentSession was removed but taskSession still calls it; restore as a module-local function (drops only the export). - tool-info.ts: enterWorktreeOwnerProject / enterWorktreeTarget were duplicated — the original exports were kept and local copies added underneath. Remove the duplicates and drop the export on the originals. Also finishes the cleanup in sidebar-workspace.tsx: with WorkspaceDragOverlay / SortableWorkspace / LocalWorkspace gone, the internal WorkspaceHeader / WorkspaceActions / WorkspaceSessionList helpers no longer have any callers. Reduce the file to the WorkspaceSidebarContext type that layout.tsx still imports. Verified: - bun --cwd packages/ui run typecheck: clean - bun --cwd packages/app run typecheck: clean - packages/app test: 1071 pass / 0 fail - packages/ui test: 418 pass / 3 fail (pre-existing CSS snapshots)
|
Pushed a fixup commit (
Verified locally:
Feel free to amend or rewrite however you'd like; happy to revert if you'd rather take a different cut. CI should re-run on the push. |
|
Merged 🎉 — thanks for the cleanup! One small followup: GitHub doesn't let me delete |
…dit (#646) Fixes identified during full-stack bug hunt. Refs #643 #644 #645. ## app - terminal.tsx: use strict equality (===) for the Enter key check; add .catch() to document.fonts.ready so a font-loading rejection cannot become unhandled. - layout.tsx: add .catch() handlers to the three dynamic imports (provider, server, directory dialogs) so a chunk-load failure does not surface as an unhandled rejection. - global-sync.tsx: add .catch() to the projectInit promise; guard the requestAnimationFrame callback with `if (!active) return` so it cannot schedule work after cleanup tore the owner down. - sync.tsx: call clearOptimistic(directory, sessionID) when dropping sessions, so the optimistic Map no longer leaks entries for sessions that disappear. ## opencode - tool/agent.ts: add a default case to the part.status switch so a new status value cannot leave header and body undefined. - control-plane/workspace.ts: wrap the parseSSE call in try/catch so a malformed SSE event does not terminate the workspace sync loop. - tool/apply_patch.ts: replace `(error as any)` in notFound() with a proper `Record<string, unknown>` narrowing. ## Rescue rebase notes The PR originally bundled three additional commits that did not survive review and were dropped or partially reverted on rebase: - A dead-code cleanup commit that was equivalently merged via #641 (with reviewer fixups for tool-info.ts and session-link.ts). Keeping it here would have re-introduced four TS2393 duplicate-definition errors on the worktree helpers; dropping the commit cleared them. - A separate input-validation commit (SQL prefix allowlist, http(s) URL guard, config-path scoping, parseInt radix/NaN fallback). The DB connection is already readonly, fetch() already rejects non-http(s) schemes, downstream code already tolerates NaN, and the config-path rule is a user-visible behavioral break with no concrete threat model — dropped, can revisit any item individually in a follow-up. - One line of the original race/error commit removed an `as any[]` cast in provider/transform.ts on the assumption that Array.isArray narrowed sufficiently. It does not: TS narrows the system-message branch union to `never`, so the cast is still required. Restored. ## Verification - packages/ui typecheck clean. - packages/app typecheck clean. - packages/opencode typecheck clean. - CI green across typecheck, unit-app, unit-desktop, unit-opencode, smoke-macos-arm64, e2e-artifacts, perf-probe-baseline, lint, analyze-js-ts, CodeQL. - Both bot review threads resolved (Gemini manual, CodeRabbit auto-detected).
Summary
Removes dead code identified by
knipand manual verification. See #640 for the full audit.What Changed
Deleted entire files (zero references)
packages/app/src/components/dialog-manage-models.tsx— unused componentpackages/app/src/custom-elements.d.ts— unused type declarationsRemoved unused exported symbols
ConstrainDragXAxisapp/src/utils/solid-dnd.tsxWorkspaceDragOverlayapp/src/pages/layout/sidebar-workspace.tsxSortableWorkspaceapp/src/pages/layout/sidebar-workspace.tsxLocalWorkspaceapp/src/pages/layout/sidebar-workspace.tsxuseHighlightsapp/src/context/highlights.tsxgetSessionKeyapp/src/pages/session/helpers.tscurrentSessionui/src/components/message-part/session-link.tsdiffui/src/storybook/fixtures.tscodeui/src/storybook/fixtures.tsDemoted over-exported internals to local scope
These functions/constants are still used inside their own module but have no external importers. Removing
exportprevents accidental coupling and makes the public API surface honest.agentColor→ local (utils/agent.ts)soundSrc,playSound→ local (utils/sound.ts)stripFileProtocol,decodeFilePath→ local (context/file/path.ts)getAvatarColors→ local (context/layout.tsx)MAX_TITLEBAR_HISTORY,pushPath,trimHistory→ local (components/titlebar-history.ts)patchFile→ local (ui/components/apply-patch-file.ts)enterWorktreeOwnerProject,enterWorktreeTarget,exitWorktreeProjectName,exitWorktreePreviousLabel,agentTitle→ local (ui/components/tool-info.ts)Test Results
packages/apppackages/uidevwithout these changes)Stats
Related Issue
Closes #640