Fix: fixing imports on the utils folder
This commit is contained in:
@@ -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<HookEventType, string> = {
|
||||
* Hook event type descriptions
|
||||
*/
|
||||
export const HOOK_EVENT_DESCRIPTIONS: Record<HookEventType, string> = {
|
||||
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.",
|
||||
|
||||
6
src/interfaces/ProgressBar.ts
Normal file
6
src/interfaces/ProgressBar.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export interface ProgressBarOptions {
|
||||
width?: number;
|
||||
filledChar?: string;
|
||||
emptyChar?: string;
|
||||
showPercentage?: boolean;
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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<string, { validation: EditValidation; edit: EditItem }>();
|
||||
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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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({
|
||||
)}
|
||||
|
||||
<Box marginTop={1}>
|
||||
<Text dimColor>
|
||||
Enter • @ files • Ctrl+M mode • Ctrl+I image
|
||||
</Text>
|
||||
<Text dimColor>Enter • @ files • Ctrl+M mode • Ctrl+I image</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
): {
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
/**
|
||||
* Longest Common Subsequence computation
|
||||
*/
|
||||
|
||||
/**
|
||||
* Simple line-based diff using Longest Common Subsequence
|
||||
*/
|
||||
export const computeLCS = (
|
||||
oldLines: string[],
|
||||
newLines: string[],
|
||||
|
||||
@@ -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[],
|
||||
|
||||
@@ -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<ProgressBarOptions> = {
|
||||
width: DEFAULT_BAR_WIDTH,
|
||||
|
||||
@@ -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";
|
||||
@@ -1,7 +1,3 @@
|
||||
/**
|
||||
* Language detection utilities
|
||||
*/
|
||||
|
||||
import { supportsLanguage } from "cli-highlight";
|
||||
import {
|
||||
EXTENSION_TO_LANGUAGE,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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";
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<AppMode> = new Set([
|
||||
"thinking",
|
||||
"tool_execution",
|
||||
@@ -14,7 +7,6 @@ const LOCKED_MODES: ReadonlySet<AppMode> = new Set([
|
||||
"learning_prompt",
|
||||
]);
|
||||
|
||||
// Commands that open their own modal
|
||||
const MODAL_COMMANDS: ReadonlySet<string> = new Set([
|
||||
"model",
|
||||
"models",
|
||||
|
||||
Reference in New Issue
Block a user