mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Revert "Make glob tool support abortSignal" (#996)
This commit is contained in:
@@ -6,16 +6,16 @@
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { glob } from 'glob';
|
||||
import fg from 'fast-glob';
|
||||
import { SchemaValidator } from '../utils/schemaValidator.js';
|
||||
import { BaseTool, ToolResult } from './tools.js';
|
||||
import { shortenPath, makeRelative } from '../utils/paths.js';
|
||||
import { Config } from '../config/config.js';
|
||||
|
||||
// Subset of 'Path' interface provided by 'glob' that we can implement for testing
|
||||
export interface GlobPath {
|
||||
fullpath(): string;
|
||||
mtimeMs?: number;
|
||||
// Type definition for file entries returned by fast-glob with stats: true
|
||||
export interface GlobFileEntry {
|
||||
path: string;
|
||||
stats?: fs.Stats;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,14 +24,14 @@ export interface GlobPath {
|
||||
* Older files are listed after recent ones, sorted alphabetically by path.
|
||||
*/
|
||||
export function sortFileEntries(
|
||||
entries: GlobPath[],
|
||||
entries: GlobFileEntry[],
|
||||
nowTimestamp: number,
|
||||
recencyThresholdMs: number,
|
||||
): GlobPath[] {
|
||||
): GlobFileEntry[] {
|
||||
const sortedEntries = [...entries];
|
||||
sortedEntries.sort((a, b) => {
|
||||
const mtimeA = a.mtimeMs ?? 0;
|
||||
const mtimeB = b.mtimeMs ?? 0;
|
||||
const mtimeA = a.stats?.mtime?.getTime() ?? 0;
|
||||
const mtimeB = b.stats?.mtime?.getTime() ?? 0;
|
||||
const aIsRecent = nowTimestamp - mtimeA < recencyThresholdMs;
|
||||
const bIsRecent = nowTimestamp - mtimeB < recencyThresholdMs;
|
||||
|
||||
@@ -42,7 +42,7 @@ export function sortFileEntries(
|
||||
} else if (bIsRecent) {
|
||||
return 1;
|
||||
} else {
|
||||
return a.fullpath().localeCompare(b.fullpath());
|
||||
return a.path.localeCompare(b.path);
|
||||
}
|
||||
});
|
||||
return sortedEntries;
|
||||
@@ -201,7 +201,7 @@ export class GlobTool extends BaseTool<GlobToolParams, ToolResult> {
|
||||
*/
|
||||
async execute(
|
||||
params: GlobToolParams,
|
||||
signal: AbortSignal,
|
||||
_signal: AbortSignal,
|
||||
): Promise<ToolResult> {
|
||||
const validationError = this.validateToolParams(params);
|
||||
if (validationError) {
|
||||
@@ -223,25 +223,26 @@ export class GlobTool extends BaseTool<GlobToolParams, ToolResult> {
|
||||
this.config.getFileFilteringRespectGitIgnore();
|
||||
const fileDiscovery = await this.config.getFileService();
|
||||
|
||||
const entries = (await glob(params.pattern, {
|
||||
const entries = await fg(params.pattern, {
|
||||
cwd: searchDirAbsolute,
|
||||
withFileTypes: true,
|
||||
nodir: true,
|
||||
stat: true,
|
||||
nocase: !params.case_sensitive,
|
||||
absolute: true,
|
||||
onlyFiles: true,
|
||||
stats: true,
|
||||
dot: true,
|
||||
caseSensitiveMatch: params.case_sensitive ?? false,
|
||||
ignore: ['**/node_modules/**', '**/.git/**'],
|
||||
follow: false,
|
||||
signal,
|
||||
})) as GlobPath[];
|
||||
followSymbolicLinks: false,
|
||||
suppressErrors: true,
|
||||
});
|
||||
|
||||
// Apply git-aware filtering if enabled and in git repository
|
||||
let filteredEntries = entries;
|
||||
let gitIgnoredCount = 0;
|
||||
|
||||
if (respectGitIgnore && fileDiscovery.isGitRepository()) {
|
||||
const relativePaths = entries.map((p) =>
|
||||
path.relative(this.rootDirectory, p.fullpath()),
|
||||
const allPaths = entries.map((entry) => entry.path);
|
||||
const relativePaths = allPaths.map((p) =>
|
||||
path.relative(this.rootDirectory, p),
|
||||
);
|
||||
const filteredRelativePaths = fileDiscovery.filterFiles(relativePaths, {
|
||||
respectGitIgnore,
|
||||
@@ -251,7 +252,7 @@ export class GlobTool extends BaseTool<GlobToolParams, ToolResult> {
|
||||
);
|
||||
|
||||
filteredEntries = entries.filter((entry) =>
|
||||
filteredAbsolutePaths.has(entry.fullpath()),
|
||||
filteredAbsolutePaths.has(entry.path),
|
||||
);
|
||||
gitIgnoredCount = entries.length - filteredEntries.length;
|
||||
}
|
||||
@@ -273,14 +274,12 @@ export class GlobTool extends BaseTool<GlobToolParams, ToolResult> {
|
||||
|
||||
// Sort the filtered entries using the new helper function
|
||||
const sortedEntries = sortFileEntries(
|
||||
filteredEntries,
|
||||
filteredEntries as GlobFileEntry[], // Cast because fast-glob's Entry type is generic
|
||||
nowTimestamp,
|
||||
oneDayInMs,
|
||||
);
|
||||
|
||||
const sortedAbsolutePaths = sortedEntries.map((entry) =>
|
||||
entry.fullpath(),
|
||||
);
|
||||
const sortedAbsolutePaths = sortedEntries.map((entry) => entry.path);
|
||||
const fileListDescription = sortedAbsolutePaths.join('\n');
|
||||
const fileCount = sortedAbsolutePaths.length;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user