refactor: remove dead code and deduplicate shared utilities#8
Merged
Conversation
Dead code removed: - src/config/index.ts (CliOptions + resolveCliConfig, never imported) - Dead fallback loop in getToolInputPreview (all tool types covered above) Duplication eliminated: - normalizeLineEndings: was duplicated in stdout-writer.ts and tool-display.ts, now lives once in src/ui/utils.ts - Shell persistence commands: switch(shell) blocks in printNoApiKeyMessage and printNoWebSearchKeyHint were identical — extracted into formatPersistCommand() in src/shell.ts alongside detectShell() - applyFg/applyColor: render-diff.ts had its own copy of syntax-highlight's applyColor; now imports the exported version - formatDuration/formatTaskDuration: merged into one configurable function in utils.ts with precision and compact options - Boolean arg parsing: parseBooleanArg() replaces the same on/off/true/false/enable chains in handleThinkingToggle and handlePlanToggle New files: - src/shell.ts: detectShell() + formatPersistCommand() - src/ui/utils.ts: normalizeLineEndings(), parseBooleanArg(), formatDuration(), getToolLabel(), getToolInputPreview(), getToolResultSummary(), formatReadGroupSummary(), isCollapsibleReadOnlyTool() tool-display.ts is now a thin re-export barrel for backward compatibility. Net: -470 lines, tsc clean, 33/33 tests pass.
The unified formatDuration defaults to precision=1, but the task summary line previously used Math.floor(ms/1000) — `30s`, not `30.0s`. Pass precision: 0 explicitly so the merged helper matches the old output.
Without a `prepare` script, `pnpm install` never invokes the husky CLI, so `core.hooksPath` stays unset and `.husky/pre-commit` (lint-staged) plus `.husky/commit-msg` (commitlint) are silently dead. Adding the script means a fresh checkout + install enables both hooks.
The previous PR moved every helper out of tool-display.ts into utils.ts and left the file as a re-export shim "for backward compatibility." There are no external consumers of @x-code-cli/cli, so the only effect was two import paths into the same set of functions and a guaranteed drift point. Migrate the two remaining importers (use-agent, ChatInput) to utils directly and delete the barrel.
Six focused cleanups, all behavior-preserving (typecheck + 356 tests unchanged): - Drop unused export RIGHT_MARGIN_SAFETY from terminal-glyphs (no importers anywhere). - Replace ChatInput's private formatTokens with utils.formatTokenCount (bodies were identical; promote the latter to an export). - Hoist RESULT_INDENT into utils so render-diff and stdout-writer share one definition instead of two const declarations carrying the same 6-space literal. - Collapse addInfoMessage/addUserMessage in use-agent onto a shared addMessage(role, content) core; keep the named wrappers so callers still document intent. - Replace four near-identical keyword-classification branches in syntax-highlight's paint() (python/go/rust/shell) with a KEYWORD_RULES table + single dispatch. - Merge EXT_TO_LANG and FENCE_LANG_TO_LANG into one LANG_LOOKUP table keyed by both file extensions and fence-language aliases; both detect* functions now read the same source. Net: -54 lines, no API surface change for external consumers.
- app.tsx: remove unused React import (jsx: react-jsx — no runtime reference needed). - ChatInput.tsx: remove cursorAnchor; the variable was assigned at two call sites but never read. The accompanying comment claimed it was kept for "future revival of the visible cursor" — speculative future- proofing per project convention. Stale comments referring to it have been updated. - sub-agents/runner.ts: drop the unused `aborted` local (return values use `aborted: true|false` literals directly), prefix the unused onToolCall callback param to match the existing onToolProgress pattern, and remove the unused `toolName` parameter from the private previewInput helper. Found by `tsc --noEmit --noUnusedLocals --noUnusedParameters`. ESLint's no-unused-vars is configured at warn-level so these slipped past CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dead code removed:
Duplication eliminated:
New files:
tool-display.ts is now a thin re-export barrel for backward compatibility.
Net: -470 lines, tsc clean, 33/33 tests pass.