From 5c2d79c8020b69dd0ddbbf0f954705886aa52902 Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez Date: Wed, 4 Feb 2026 00:35:00 -0500 Subject: [PATCH] Fix: fixing imports on the utils folder --- src/constants/hooks.ts | 8 +++- src/interfaces/ProgressBar.ts | 6 +++ src/tools/edit/execute.ts | 3 +- src/tools/multi-edit/execute.ts | 44 +++++++++++++++---- src/tools/write/execute.ts | 3 +- src/tui-solid/components/log-entry.tsx | 2 +- src/tui/App.tsx | 26 ++++++----- src/tui/components/diff-view/index.tsx | 2 +- .../components/diff-view/line-renderers.tsx | 2 +- src/utils/diff.ts | 13 ------ src/utils/diff/hunks.ts | 7 --- src/utils/diff/index.ts | 13 ------ src/utils/diff/lcs.ts | 7 --- src/utils/diff/lines.ts | 7 --- src/utils/progress-bar.ts | 11 +---- src/utils/syntax-highlight.ts | 18 -------- src/utils/syntax-highlight/detect.ts | 4 -- src/utils/syntax-highlight/highlight.ts | 27 ------------ src/utils/tui-app/index.ts | 33 -------------- src/utils/tui-app/input-utils.ts | 13 ------ src/utils/tui-app/mode-utils.ts | 8 ---- 21 files changed, 73 insertions(+), 184 deletions(-) create mode 100644 src/interfaces/ProgressBar.ts delete mode 100644 src/utils/diff.ts delete mode 100644 src/utils/syntax-highlight.ts delete mode 100644 src/utils/tui-app/index.ts diff --git a/src/constants/hooks.ts b/src/constants/hooks.ts index 9cc7eef..1b45f29 100644 --- a/src/constants/hooks.ts +++ b/src/constants/hooks.ts @@ -16,6 +16,11 @@ export const HOOKS_CONFIG_FILE = "hooks.json"; */ export const DEFAULT_HOOK_TIMEOUT = 30000; +/** + * Default progress bar width + * */ +export const DEFAULT_BAR_WIDTH = 40; + /** * Hook exit codes and their meanings */ @@ -44,7 +49,8 @@ export const HOOK_EVENT_LABELS: Record = { * Hook event type descriptions */ export const HOOK_EVENT_DESCRIPTIONS: Record = { - PreToolUse: "Runs before a tool is executed. Can modify args or block execution.", + PreToolUse: + "Runs before a tool is executed. Can modify args or block execution.", PostToolUse: "Runs after a tool completes. For notifications or logging.", SessionStart: "Runs when a new session begins.", SessionEnd: "Runs when a session ends.", diff --git a/src/interfaces/ProgressBar.ts b/src/interfaces/ProgressBar.ts new file mode 100644 index 0000000..fa11832 --- /dev/null +++ b/src/interfaces/ProgressBar.ts @@ -0,0 +1,6 @@ +export interface ProgressBarOptions { + width?: number; + filledChar?: string; + emptyChar?: string; + showPercentage?: boolean; +} diff --git a/src/tools/edit/execute.ts b/src/tools/edit/execute.ts index f40a871..e0fd20f 100644 --- a/src/tools/edit/execute.ts +++ b/src/tools/edit/execute.ts @@ -7,7 +7,8 @@ import path from "path"; import { EDIT_MESSAGES, EDIT_TITLES, EDIT_DESCRIPTION } from "@constants/edit"; import { isFileOpAllowed, promptFilePermission } from "@services/permissions"; -import { formatDiff, generateDiff } from "@utils/diff"; +import { formatDiff } from "@utils/diff/format"; +import { generateDiff } from "@utils/diff/generate"; import { editParams } from "@tools/edit/params"; import { validateTextExists, diff --git a/src/tools/multi-edit/execute.ts b/src/tools/multi-edit/execute.ts index e9a9a33..ce32ad6 100644 --- a/src/tools/multi-edit/execute.ts +++ b/src/tools/multi-edit/execute.ts @@ -14,7 +14,8 @@ import { MULTI_EDIT_DESCRIPTION, } from "@constants/multi-edit"; import { isFileOpAllowed, promptFilePermission } from "@services/permissions"; -import { formatDiff, generateDiff } from "@utils/diff"; +import { formatDiff } from "@utils/diff/format"; +import { generateDiff } from "@utils/diff/generate"; import { multiEditParams } from "@tools/multi-edit/params"; import type { ToolDefinition, ToolContext, ToolResult } from "@/types/tools"; import type { EditItem, MultiEditParams } from "@tools/multi-edit/params"; @@ -57,8 +58,14 @@ const createSuccessResult = ( .map((r) => `## ${path.basename(r.path)}\n\n${r.diff}`) .join("\n\n---\n\n"); - const totalAdditions = successful.reduce((sum, r) => sum + (r.additions ?? 0), 0); - const totalDeletions = successful.reduce((sum, r) => sum + (r.deletions ?? 0), 0); + const totalAdditions = successful.reduce( + (sum, r) => sum + (r.additions ?? 0), + 0, + ); + const totalDeletions = successful.reduce( + (sum, r) => sum + (r.deletions ?? 0), + 0, + ); const title = failed.length > 0 @@ -104,7 +111,10 @@ const validateEdit = async ( } if (stat.size > MULTI_EDIT_DEFAULTS.MAX_FILE_SIZE) { - return { valid: false, error: MULTI_EDIT_MESSAGES.FILE_TOO_LARGE(edit.file_path) }; + return { + valid: false, + error: MULTI_EDIT_MESSAGES.FILE_TOO_LARGE(edit.file_path), + }; } const content = await fs.readFile(fullPath, "utf-8"); @@ -114,7 +124,10 @@ const validateEdit = async ( const preview = edit.old_string.slice(0, 50); return { valid: false, - error: MULTI_EDIT_MESSAGES.OLD_STRING_NOT_FOUND(edit.file_path, preview), + error: MULTI_EDIT_MESSAGES.OLD_STRING_NOT_FOUND( + edit.file_path, + preview, + ), }; } @@ -123,14 +136,20 @@ const validateEdit = async ( if (occurrences > 1) { return { valid: false, - error: MULTI_EDIT_MESSAGES.OLD_STRING_NOT_UNIQUE(edit.file_path, occurrences), + error: MULTI_EDIT_MESSAGES.OLD_STRING_NOT_UNIQUE( + edit.file_path, + occurrences, + ), }; } return { valid: true, fileContent: content }; } catch (error) { if ((error as NodeJS.ErrnoException).code === "ENOENT") { - return { valid: false, error: MULTI_EDIT_MESSAGES.FILE_NOT_FOUND(edit.file_path) }; + return { + valid: false, + error: MULTI_EDIT_MESSAGES.FILE_NOT_FOUND(edit.file_path), + }; } const message = error instanceof Error ? error.message : String(error); return { valid: false, error: message }; @@ -243,7 +262,10 @@ export const executeMultiEdit = async ( }); // Phase 1: Validate all edits - const validations = new Map(); + const validations = new Map< + string, + { validation: EditValidation; edit: EditItem } + >(); const errors: string[] = []; for (const edit of edits) { @@ -300,7 +322,11 @@ export const executeMultiEdit = async ( }); // Apply edit - const result = await applyEdit(edit, ctx.workingDir, data.validation.fileContent); + const result = await applyEdit( + edit, + ctx.workingDir, + data.validation.fileContent, + ); results.push(result); if (!result.success) { diff --git a/src/tools/write/execute.ts b/src/tools/write/execute.ts index 538912b..fdce4a2 100644 --- a/src/tools/write/execute.ts +++ b/src/tools/write/execute.ts @@ -11,7 +11,8 @@ import { WRITE_DESCRIPTION, } from "@constants/write"; import { isFileOpAllowed, promptFilePermission } from "@services/permissions"; -import { formatDiff, generateDiff } from "@utils/diff"; +import { formatDiff } from "@utils/diff/format"; +import { generateDiff } from "@utils/diff/generate"; import { writeParams } from "@tools/write/params"; import type { ToolDefinition, diff --git a/src/tui-solid/components/log-entry.tsx b/src/tui-solid/components/log-entry.tsx index 457ad89..4c36dff 100644 --- a/src/tui-solid/components/log-entry.tsx +++ b/src/tui-solid/components/log-entry.tsx @@ -8,7 +8,7 @@ import { } from "@constants/tui-components"; import { DiffView } from "@tui-solid/components/diff-view"; import { StreamingMessage } from "@tui-solid/components/streaming-message"; -import { parseDiffOutput, isDiffContent } from "@/utils/diff"; +import { parseDiffOutput, isDiffContent } from "@utils/diff/index"; interface LogEntryDisplayProps { entry: LogEntry; diff --git a/src/tui/App.tsx b/src/tui/App.tsx index 139215c..2bf6889 100644 --- a/src/tui/App.tsx +++ b/src/tui/App.tsx @@ -38,17 +38,24 @@ import { insertAtCursor, deleteBeforeCursor, calculateCursorPosition, +} from "@utils/tui-app/input-utils"; + +import { isInputLocked, isModalCommand, isMainInputActive as checkMainInputActive, isProcessing, +} from "@utils/tui-app/mode-utils"; + +import { shouldSummarizePaste, addPastedBlock, updatePastedBlocksAfterDelete, expandPastedContent, normalizeLineEndings, clearPastedBlocks, -} from "@utils/tui-app/index"; +} from "@utils/tui-app/paste-utils"; + import { PAGE_SCROLL_LINES, MOUSE_SCROLL_LINES } from "@constants/auto-scroll"; import { useMouseScroll } from "@tui/hooks"; import type { PasteState } from "@interfaces/PastedContent"; @@ -71,7 +78,6 @@ export function App({ onModelSelect, onAgentSelect, onThemeSelect, - showBanner = true, }: AppProps): React.ReactElement { const { exit } = useApp(); const setSessionInfo = useAppStore((state) => state.setSessionInfo); @@ -87,7 +93,9 @@ export function App({ const exitPending = useAppStore((state) => state.exitPending); const setExitPending = useAppStore((state) => state.setExitPending); const toggleTodos = useAppStore((state) => state.toggleTodos); - const toggleInteractionMode = useAppStore((state) => state.toggleInteractionMode); + const toggleInteractionMode = useAppStore( + (state) => state.toggleInteractionMode, + ); const interactionMode = useAppStore((state) => state.interactionMode); const startThinking = useAppStore((state) => state.startThinking); const stopThinking = useAppStore((state) => state.stopThinking); @@ -97,7 +105,6 @@ export function App({ const scrollToBottom = useAppStore((state) => state.scrollToBottom); const screenMode = useAppStore((state) => state.screenMode); const setScreenMode = useAppStore((state) => state.setScreenMode); - const logs = useAppStore((state) => state.logs); const sessionStats = useAppStore((state) => state.sessionStats); const brain = useAppStore((state) => state.brain); const dismissBrainBanner = useAppStore((state) => state.dismissBrainBanner); @@ -179,9 +186,10 @@ export function App({ ); // Capture images before clearing - const images = pasteState.pastedImages.length > 0 - ? [...pasteState.pastedImages] - : undefined; + const images = + pasteState.pastedImages.length > 0 + ? [...pasteState.pastedImages] + : undefined; // Clear paste state after expanding setPasteState(clearPastedBlocks()); @@ -840,9 +848,7 @@ export function App({ )} - - Enter • @ files • Ctrl+M mode • Ctrl+I image - + Enter • @ files • Ctrl+M mode • Ctrl+I image diff --git a/src/tui/components/diff-view/index.tsx b/src/tui/components/diff-view/index.tsx index 0d5036f..a19cb4d 100644 --- a/src/tui/components/diff-view/index.tsx +++ b/src/tui/components/diff-view/index.tsx @@ -16,7 +16,7 @@ import type { DiffViewProps } from "@/types/tui"; import { detectLanguage, getLanguageDisplayName, -} from "@utils/syntax-highlight"; +} from "@utils/syntax-highlight/detect"; import { DiffLine } from "@tui/components/diff-view/line-renderers"; export function DiffView({ diff --git a/src/tui/components/diff-view/line-renderers.tsx b/src/tui/components/diff-view/line-renderers.tsx index c535bd8..eb0d0c7 100644 --- a/src/tui/components/diff-view/line-renderers.tsx +++ b/src/tui/components/diff-view/line-renderers.tsx @@ -7,7 +7,7 @@ import React from "react"; import { Box, Text, Transform } from "ink"; import type { DiffLineData, DiffLineProps, DiffLineType } from "@/types/tui"; -import { highlightLine } from "@utils/syntax-highlight"; +import { highlightLine } from "@utils/syntax-highlight/highlight"; // ============================================================================ // Utility Components diff --git a/src/utils/diff.ts b/src/utils/diff.ts deleted file mode 100644 index 99ba4bd..0000000 --- a/src/utils/diff.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Diff utility for generating colored git-style diff output - */ - -export type { - DiffLine, - DiffHunk, - DiffResult, - DiffLineType, -} from "@/types/diff"; -export { generateDiff } from "@utils/diff/generate"; -export { formatDiff, formatCompactDiff } from "@utils/diff/format"; -export { parseDiffOutput, isDiffContent, stripAnsi } from "@utils/diff/index"; diff --git a/src/utils/diff/hunks.ts b/src/utils/diff/hunks.ts index e0211ff..4a28437 100644 --- a/src/utils/diff/hunks.ts +++ b/src/utils/diff/hunks.ts @@ -1,13 +1,6 @@ -/** - * Diff hunk grouping utilities - */ - import { DIFF_CONTEXT_LINES } from "@constants/diff"; import type { DiffLine, DiffHunk } from "@/types/diff"; -/** - * Group diff lines into hunks with context - */ export const groupIntoHunks = ( lines: DiffLine[], contextLines = DIFF_CONTEXT_LINES, diff --git a/src/utils/diff/index.ts b/src/utils/diff/index.ts index 4a543ce..6e04cbe 100644 --- a/src/utils/diff/index.ts +++ b/src/utils/diff/index.ts @@ -1,19 +1,9 @@ -/** - * Diff View Utility Functions - */ - import type { DiffLineData } from "@/types/tui"; -/** - * Strip ANSI escape codes from a string - */ export const stripAnsi = (str: string): string => { return str.replace(/\x1b\[[0-9;]*m/g, ""); }; -/** - * Check if content looks like a diff output - */ export const isDiffContent = (content: string): boolean => { // Strip ANSI codes for pattern matching const cleanContent = stripAnsi(content); @@ -28,9 +18,6 @@ export const isDiffContent = (content: string): boolean => { return diffPatterns.some((pattern) => pattern.test(cleanContent)); }; -/** - * Parse raw diff output into structured DiffLineData - */ export const parseDiffOutput = ( diffOutput: string, ): { diff --git a/src/utils/diff/lcs.ts b/src/utils/diff/lcs.ts index 9e157cc..c826d48 100644 --- a/src/utils/diff/lcs.ts +++ b/src/utils/diff/lcs.ts @@ -1,10 +1,3 @@ -/** - * Longest Common Subsequence computation - */ - -/** - * Simple line-based diff using Longest Common Subsequence - */ export const computeLCS = ( oldLines: string[], newLines: string[], diff --git a/src/utils/diff/lines.ts b/src/utils/diff/lines.ts index 4d6d21b..7233fcd 100644 --- a/src/utils/diff/lines.ts +++ b/src/utils/diff/lines.ts @@ -1,12 +1,5 @@ -/** - * Diff line generation utilities - */ - import type { DiffLine, DiffOperation } from "@/types/diff"; -/** - * Generate diff lines from LCS matrix - */ export const generateDiffLines = ( oldLines: string[], newLines: string[], diff --git a/src/utils/progress-bar.ts b/src/utils/progress-bar.ts index 0fc88f0..b90a838 100644 --- a/src/utils/progress-bar.ts +++ b/src/utils/progress-bar.ts @@ -3,15 +3,8 @@ */ import chalk from "chalk"; - -const DEFAULT_BAR_WIDTH = 40; - -interface ProgressBarOptions { - width?: number; - filledChar?: string; - emptyChar?: string; - showPercentage?: boolean; -} +import { DEFAULT_BAR_WIDTH } from "@constants/hooks.js"; +import type { ProgressBarOptions } from "@interfactes/ProgressBar"; const defaultOptions: Required = { width: DEFAULT_BAR_WIDTH, diff --git a/src/utils/syntax-highlight.ts b/src/utils/syntax-highlight.ts deleted file mode 100644 index faff469..0000000 --- a/src/utils/syntax-highlight.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Syntax Highlighting Utility - * - * Provides terminal-friendly syntax highlighting for code - * using cli-highlight with language auto-detection. - */ - -export { - detectLanguage, - isLanguageSupported, - getLanguageDisplayName, -} from "@utils/syntax-highlight/detect"; - -export { - highlightLine, - highlightCode, - highlightLines, -} from "@utils/syntax-highlight/highlight"; diff --git a/src/utils/syntax-highlight/detect.ts b/src/utils/syntax-highlight/detect.ts index 7c87640..f088ee9 100644 --- a/src/utils/syntax-highlight/detect.ts +++ b/src/utils/syntax-highlight/detect.ts @@ -1,7 +1,3 @@ -/** - * Language detection utilities - */ - import { supportsLanguage } from "cli-highlight"; import { EXTENSION_TO_LANGUAGE, diff --git a/src/utils/syntax-highlight/highlight.ts b/src/utils/syntax-highlight/highlight.ts index 171a7ce..ecdbc02 100644 --- a/src/utils/syntax-highlight/highlight.ts +++ b/src/utils/syntax-highlight/highlight.ts @@ -1,17 +1,6 @@ -/** - * Code highlighting utilities - */ - import { highlight } from "cli-highlight"; import { detectLanguage } from "@utils/syntax-highlight/detect"; -/** - * Highlight a single line of code - * - * @param line - The code line to highlight - * @param language - The programming language - * @returns Highlighted line with ANSI codes - */ export const highlightLine = (line: string, language?: string): string => { if (!language || !line.trim()) { return line; @@ -30,14 +19,6 @@ export const highlightLine = (line: string, language?: string): string => { } }; -/** - * Highlight a block of code - * - * @param code - The code to highlight - * @param language - The programming language (auto-detected if not provided) - * @param filePath - Optional file path for language detection - * @returns Highlighted code with ANSI codes - */ export const highlightCode = ( code: string, language?: string, @@ -59,14 +40,6 @@ export const highlightCode = ( } }; -/** - * Highlight multiple lines while preserving line structure - * Useful for diff views where each line needs individual highlighting - * - * @param lines - Array of code lines - * @param language - The programming language - * @returns Array of highlighted lines - */ export const highlightLines = ( lines: string[], language?: string, diff --git a/src/utils/tui-app/index.ts b/src/utils/tui-app/index.ts deleted file mode 100644 index 0d59265..0000000 --- a/src/utils/tui-app/index.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * TUI App Utilities - Exports - */ - -export { - isMouseEscapeSequence, - cleanInput, - insertAtCursor, - deleteBeforeCursor, - calculateCursorPosition, -} from "@utils/tui-app/input-utils"; - -export { - isInputLocked, - isModalCommand, - isMainInputActive, - isProcessing, -} from "@utils/tui-app/mode-utils"; - -export { - countLines, - shouldSummarizePaste, - generatePlaceholder, - createPastedContent, - generatePasteId, - addPastedBlock, - updatePastedBlockPositions, - updatePastedBlocksAfterDelete, - expandPastedContent, - getDisplayBuffer, - normalizeLineEndings, - clearPastedBlocks, -} from "@utils/tui-app/paste-utils"; diff --git a/src/utils/tui-app/input-utils.ts b/src/utils/tui-app/input-utils.ts index 2799518..b04cb7c 100644 --- a/src/utils/tui-app/input-utils.ts +++ b/src/utils/tui-app/input-utils.ts @@ -1,11 +1,3 @@ -/** - * TUI App Input Utilities - * - * Helper functions for input handling in the TUI App - */ - -// Mouse escape sequence patterns for filtering -// Note: Patterns for replacement use 'g' flag, patterns for testing don't const MOUSE_PATTERNS = { // Full escape sequences (for replacement) SGR_FULL: /\x1b\[<\d+;\d+;\d+[Mm]/g, @@ -23,16 +15,11 @@ const MOUSE_PATTERNS = { BRACKET_SGR_PREFIX: "[<", } as const; -// Control character patterns for cleaning input const CONTROL_PATTERNS = { CONTROL_CHARS: /[\x00-\x1f\x7f]/g, ESCAPE_SEQUENCES: /\x1b\[.*?[a-zA-Z]/g, } as const; -/** - * Check if input is a mouse escape sequence - * Handles both full sequences and partial sequences where ESC was stripped - */ export const isMouseEscapeSequence = (input: string): boolean => { if (!input) return false; diff --git a/src/utils/tui-app/mode-utils.ts b/src/utils/tui-app/mode-utils.ts index 48e4509..6bd2870 100644 --- a/src/utils/tui-app/mode-utils.ts +++ b/src/utils/tui-app/mode-utils.ts @@ -1,12 +1,5 @@ -/** - * TUI App Mode Utilities - * - * Helper functions for mode checking in the TUI App - */ - import type { AppMode } from "@/types/tui"; -// Modes that lock the input const LOCKED_MODES: ReadonlySet = new Set([ "thinking", "tool_execution", @@ -14,7 +7,6 @@ const LOCKED_MODES: ReadonlySet = new Set([ "learning_prompt", ]); -// Commands that open their own modal const MODAL_COMMANDS: ReadonlySet = new Set([ "model", "models",