style(deps): migrated from Prettier to Biome and updated formatting rules
- Removed Prettier configuration files (.prettierignore and .prettierrc) and migrated formatting to Biome. - Updated Biome configuration from version 2.3.11 to 2.3.12 and changed arrowParentheses rule from 'always' to 'asNeeded'. - Pinned @biomejs/biome dependency to exact version 2.3.12 in package.json and bun.lock. - Applied consistent arrow function formatting across 489 files by removing unnecessary parentheses around single parameters. - Removed blank lines after comment blocks and reorganized imports for consistency across the codebase.
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
* Applies parsed diff hunks to file content using fuzzy matching
|
||||
* for robust handling of whitespace and formatting differences.
|
||||
*/
|
||||
|
||||
import * as fs from "node:fs/promises";
|
||||
import * as path from "node:path";
|
||||
import { resolveToCwd } from "../tools/path-utils";
|
||||
@@ -204,14 +203,14 @@ function adjustLinesIndentation(patternLines: string[], actualLines: string[], n
|
||||
deltas.push(aIndent - pIndent);
|
||||
}
|
||||
|
||||
if (deltas.length > 0 && deltas.every((value) => value === deltas[0])) {
|
||||
if (deltas.length > 0 && deltas.every(value => value === deltas[0])) {
|
||||
delta = deltas[0];
|
||||
}
|
||||
|
||||
// Track which actual lines we've used to handle duplicate content correctly
|
||||
const usedActualLines = new Map<string, number>(); // trimmed content -> count used
|
||||
|
||||
return newLines.map((newLine) => {
|
||||
return newLines.map(newLine => {
|
||||
if (newLine.trim().length === 0) {
|
||||
return newLine;
|
||||
}
|
||||
@@ -277,7 +276,7 @@ function trimCommonContext(oldLines: string[], newLines: string[]): HunkVariant
|
||||
}
|
||||
|
||||
function collapseConsecutiveSharedLines(oldLines: string[], newLines: string[]): HunkVariant | undefined {
|
||||
const shared = new Set(oldLines.filter((line) => newLines.includes(line)));
|
||||
const shared = new Set(oldLines.filter(line => newLines.includes(line)));
|
||||
const collapse = (lines: string[]): string[] => {
|
||||
const out: string[] = [];
|
||||
let i = 0;
|
||||
@@ -302,7 +301,7 @@ function collapseConsecutiveSharedLines(oldLines: string[], newLines: string[]):
|
||||
}
|
||||
|
||||
function collapseRepeatedBlocks(oldLines: string[], newLines: string[]): HunkVariant | undefined {
|
||||
const shared = new Set(oldLines.filter((line) => newLines.includes(line)));
|
||||
const shared = new Set(oldLines.filter(line => newLines.includes(line)));
|
||||
const collapse = (lines: string[]): string[] => {
|
||||
const output = [...lines];
|
||||
let changed = false;
|
||||
@@ -313,7 +312,7 @@ function collapseRepeatedBlocks(oldLines: string[], newLines: string[]): HunkVar
|
||||
const first = output.slice(i, i + size);
|
||||
const second = output.slice(i + size, i + size * 2);
|
||||
if (first.length !== second.length || first.length === 0) continue;
|
||||
if (!first.every((line) => shared.has(line))) continue;
|
||||
if (!first.every(line => shared.has(line))) continue;
|
||||
let same = true;
|
||||
for (let idx = 0; idx < size; idx++) {
|
||||
if (first[idx] !== second[idx]) {
|
||||
@@ -379,7 +378,7 @@ function buildFallbackVariants(hunk: DiffHunk): HunkVariant[] {
|
||||
if (singleLine) variants.push(singleLine);
|
||||
|
||||
const seen = new Set<string>();
|
||||
return variants.filter((variant) => {
|
||||
return variants.filter(variant => {
|
||||
if (variant.oldLines.length === 0 && variant.newLines.length === 0) return false;
|
||||
const key = `${variant.oldLines.join("\n")}||${variant.newLines.join("\n")}`;
|
||||
if (seen.has(key)) return false;
|
||||
@@ -443,8 +442,8 @@ function findHierarchicalContext(
|
||||
if (context.includes("\n")) {
|
||||
const parts = context
|
||||
.split("\n")
|
||||
.map((p) => p.trim())
|
||||
.filter((p) => p.length > 0);
|
||||
.map(p => p.trim())
|
||||
.filter(p => p.length > 0);
|
||||
let currentStart = startFrom;
|
||||
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
@@ -488,7 +487,7 @@ function findHierarchicalContext(
|
||||
}
|
||||
|
||||
// Try literal context first
|
||||
const spaceParts = context.split(/\s+/).filter((p) => p.length > 0);
|
||||
const spaceParts = context.split(/\s+/).filter(p => p.length > 0);
|
||||
const hasSignatureChars = /[(){}[\]]/.test(context);
|
||||
if (!hasSignatureChars && spaceParts.length > 2) {
|
||||
const outer = spaceParts.slice(0, -1).join(" ");
|
||||
@@ -899,7 +898,7 @@ function computeReplacements(
|
||||
for (const variant of buildFallbackVariants(hunk)) {
|
||||
if (variant.oldLines.length !== 1 || variant.newLines.length !== 1) continue;
|
||||
const removedLine = variant.oldLines[0];
|
||||
const hasSharedDuplicate = hunk.newLines.some((line) => line.trim() === removedLine.trim());
|
||||
const hasSharedDuplicate = hunk.newLines.some(line => line.trim() === removedLine.trim());
|
||||
const adjacentIndex = findContextRelativeMatch(
|
||||
originalLines,
|
||||
removedLine,
|
||||
@@ -922,7 +921,7 @@ function computeReplacements(
|
||||
if (line.trim() === trimmed) occurrenceCount++;
|
||||
}
|
||||
if (occurrenceCount > 1) {
|
||||
const hasSharedDuplicate = hunk.newLines.some((line) => line.trim() === trimmed);
|
||||
const hasSharedDuplicate = hunk.newLines.some(line => line.trim() === trimmed);
|
||||
const contextMatch = findContextRelativeMatch(originalLines, pattern[0], contextIndex, hasSharedDuplicate);
|
||||
if (contextMatch !== undefined) {
|
||||
searchResult = { index: contextMatch, confidence: searchResult.confidence ?? 0.95 };
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* Provides diff string generation and the replace-mode edit logic
|
||||
* used when not in patch mode.
|
||||
*/
|
||||
|
||||
import * as Diff from "diff";
|
||||
import { resolveToCwd } from "../tools/path-utils";
|
||||
import { previewPatch } from "./applicator";
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* Provides both character-level and line-level fuzzy matching with progressive
|
||||
* fallback strategies for finding text in files.
|
||||
*/
|
||||
|
||||
import { countLeadingWhitespace, normalizeForFuzzy, normalizeUnicode } from "./normalize";
|
||||
import type { ContextLineResult, FuzzyMatch, MatchOutcome, SequenceSearchResult } from "./types";
|
||||
|
||||
@@ -89,7 +88,7 @@ function computeRelativeIndentDepths(lines: string[]): number[] {
|
||||
}
|
||||
}
|
||||
const minIndent = nonEmptyIndents.length > 0 ? Math.min(...nonEmptyIndents) : 0;
|
||||
const indentSteps = nonEmptyIndents.map((indent) => indent - minIndent).filter((step) => step > 0);
|
||||
const indentSteps = nonEmptyIndents.map(indent => indent - minIndent).filter(step => step > 0);
|
||||
const indentUnit = indentSteps.length > 0 ? Math.min(...indentSteps) : 1;
|
||||
|
||||
return lines.map((line, index) => {
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
*
|
||||
* The mode is determined by the `edit.patchMode` setting.
|
||||
*/
|
||||
|
||||
import * as fs from "node:fs/promises";
|
||||
import type { AgentTool, AgentToolContext, AgentToolResult, AgentToolUpdateCallback } from "@oh-my-pi/pi-agent-core";
|
||||
import { StringEnum } from "@oh-my-pi/pi-ai";
|
||||
|
||||
@@ -189,7 +189,7 @@ export function convertLeadingTabsToSpaces(text: string, spacesPerTab: number):
|
||||
if (spacesPerTab <= 0) return text;
|
||||
return text
|
||||
.split("\n")
|
||||
.map((line) => {
|
||||
.map(line => {
|
||||
const trimmed = line.trimStart();
|
||||
if (trimmed.length === 0) return line;
|
||||
const leading = getLeadingWhitespace(line);
|
||||
@@ -212,7 +212,7 @@ export function normalizeUnicode(s: string): string {
|
||||
return s
|
||||
.trim()
|
||||
.split("")
|
||||
.map((c) => {
|
||||
.map(c => {
|
||||
const code = c.charCodeAt(0);
|
||||
|
||||
// Various dash/hyphen code-points → ASCII '-'
|
||||
@@ -367,7 +367,7 @@ export function adjustIndentation(oldText: string, actualText: string, newText:
|
||||
}
|
||||
|
||||
const delta = deltas[0];
|
||||
if (!deltas.every((value) => value === delta)) {
|
||||
if (!deltas.every(value => value === delta)) {
|
||||
return newText;
|
||||
}
|
||||
|
||||
@@ -380,7 +380,7 @@ export function adjustIndentation(oldText: string, actualText: string, newText:
|
||||
}
|
||||
|
||||
const indentChar = actualProfile.char ?? oldProfile.char ?? detectIndentChar(actualText);
|
||||
const adjusted = newText.split("\n").map((line) => {
|
||||
const adjusted = newText.split("\n").map(line => {
|
||||
if (line.trim().length === 0) {
|
||||
return line;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* Normalize applied patch output into a canonical edit tool payload.
|
||||
*/
|
||||
|
||||
import { generateUnifiedDiffString } from "./diff";
|
||||
import { normalizeToLF, stripBom } from "./normalize";
|
||||
import { parseHunks } from "./parser";
|
||||
@@ -37,7 +36,7 @@ function applyAnchors(diff: string, anchors: Array<string | undefined> | undefin
|
||||
|
||||
function deriveAnchors(diff: string): Array<string | undefined> {
|
||||
const hunks = parseHunks(diff);
|
||||
return hunks.map((hunk) => {
|
||||
return hunks.map(hunk => {
|
||||
if (hunk.oldLines.length === 0 || hunk.newLines.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
* - Unified diff format (@@ -X,Y +A,B @@)
|
||||
* - Codex-style wrapped patches (*** Begin Patch / *** End Patch)
|
||||
*/
|
||||
|
||||
import type { DiffHunk } from "./types";
|
||||
import { ApplyPatchError, ParseError } from "./types";
|
||||
|
||||
@@ -90,7 +89,7 @@ export function normalizeDiff(diff: string): string {
|
||||
// Layer 2: Strip Codex-style file operation markers and unified diff metadata
|
||||
// NOTE: Do NOT strip "*** End of File" - that's a valid marker within hunks, not a wrapper
|
||||
// IMPORTANT: Only strip actual metadata lines, NOT diff content lines (starting with space, +, or -)
|
||||
lines = lines.filter((line) => {
|
||||
lines = lines.filter(line => {
|
||||
// Preserve diff content lines even if their content looks like metadata
|
||||
// Note: `--- ` and `+++ ` are metadata, not content lines
|
||||
if (isDiffContentLine(line)) {
|
||||
@@ -130,12 +129,12 @@ export function normalizeDiff(diff: string): string {
|
||||
*/
|
||||
export function normalizeCreateContent(content: string): string {
|
||||
const lines = content.split("\n");
|
||||
const nonEmptyLines = lines.filter((l) => l.length > 0);
|
||||
const nonEmptyLines = lines.filter(l => l.length > 0);
|
||||
|
||||
// Check if all non-empty lines start with "+ " or "+"
|
||||
if (nonEmptyLines.length > 0 && nonEmptyLines.every((l) => l.startsWith("+ ") || l.startsWith("+"))) {
|
||||
if (nonEmptyLines.length > 0 && nonEmptyLines.every(l => l.startsWith("+ ") || l.startsWith("+"))) {
|
||||
return lines
|
||||
.map((l) => {
|
||||
.map(l => {
|
||||
if (l.startsWith("+ ")) return l.slice(2);
|
||||
if (l.startsWith("+")) return l.slice(1);
|
||||
return l;
|
||||
@@ -390,18 +389,18 @@ function parseOneHunk(lines: string[], lineNumber: number, allowMissingContext:
|
||||
}
|
||||
|
||||
function stripLineNumberPrefixes(hunk: DiffHunk): void {
|
||||
const allLines = [...hunk.oldLines, ...hunk.newLines].filter((line) => line.trim().length > 0);
|
||||
const allLines = [...hunk.oldLines, ...hunk.newLines].filter(line => line.trim().length > 0);
|
||||
if (allLines.length < 2) return;
|
||||
|
||||
const numberMatches = allLines
|
||||
.map((line) => line.match(/^\s*(\d{1,6})\s+(.+)$/u))
|
||||
.map(line => line.match(/^\s*(\d{1,6})\s+(.+)$/u))
|
||||
.filter((match): match is RegExpMatchArray => match !== null);
|
||||
|
||||
if (numberMatches.length < Math.max(2, Math.ceil(allLines.length * 0.6))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const numbers = numberMatches.map((match) => Number(match[1]));
|
||||
const numbers = numberMatches.map(match => Number(match[1]));
|
||||
let sequential = 0;
|
||||
for (let i = 1; i < numbers.length; i++) {
|
||||
if (numbers[i] === numbers[i - 1] + 1) {
|
||||
@@ -515,7 +514,7 @@ export function parseHunks(diff: string): DiffHunk[] {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (trimmed.startsWith("@@") && lines.slice(i + 1).every((l) => l.trim() === "")) {
|
||||
if (trimmed.startsWith("@@") && lines.slice(i + 1).every(l => l.trim() === "")) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* Shared utilities for edit tool TUI rendering.
|
||||
*/
|
||||
|
||||
import type { ToolCallContext } from "@oh-my-pi/pi-agent-core";
|
||||
import type { Component } from "@oh-my-pi/pi-tui";
|
||||
import { Text } from "@oh-my-pi/pi-tui";
|
||||
@@ -38,7 +37,7 @@ export function getLspBatchRequest(toolCall: ToolCallContext | undefined): { id:
|
||||
if (!hasOtherWrites) {
|
||||
return undefined;
|
||||
}
|
||||
const hasLaterWrites = toolCall.toolCalls.slice(toolCall.index + 1).some((call) => LSP_BATCH_TOOLS.has(call.name));
|
||||
const hasLaterWrites = toolCall.toolCalls.slice(toolCall.index + 1).some(call => LSP_BATCH_TOOLS.has(call.name));
|
||||
return { id: toolCall.batchId, flush: !hasLaterWrites };
|
||||
}
|
||||
|
||||
@@ -259,7 +258,7 @@ export const editToolRenderer = {
|
||||
|
||||
if (result.isError) {
|
||||
// Show error from result
|
||||
const errorText = result.content?.find((c) => c.type === "text")?.text ?? "";
|
||||
const errorText = result.content?.find(c => c.type === "text")?.text ?? "";
|
||||
if (errorText) {
|
||||
text += `\n\n${uiTheme.fg("error", errorText)}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user