@j0hanz/filesystem-context-mcp 1.2.4 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/file-operations/list-directory-helpers.d.ts +28 -0
- package/dist/lib/file-operations/list-directory-helpers.d.ts.map +1 -0
- package/dist/lib/file-operations/list-directory-helpers.js +159 -0
- package/dist/lib/file-operations/list-directory-helpers.js.map +1 -0
- package/dist/lib/file-operations/list-directory.d.ts.map +1 -1
- package/dist/lib/file-operations/list-directory.js +3 -157
- package/dist/lib/file-operations/list-directory.js.map +1 -1
- package/dist/lib/file-operations/search/engine.d.ts +17 -25
- package/dist/lib/file-operations/search/engine.d.ts.map +1 -1
- package/dist/lib/file-operations/search/engine.js +161 -165
- package/dist/lib/file-operations/search/engine.js.map +1 -1
- package/dist/lib/file-operations/search/file-processor.d.ts +2 -14
- package/dist/lib/file-operations/search/file-processor.d.ts.map +1 -1
- package/dist/lib/file-operations/search/file-processor.js +93 -102
- package/dist/lib/file-operations/search/file-processor.js.map +1 -1
- package/dist/lib/file-operations/search/match-strategy.d.ts +3 -21
- package/dist/lib/file-operations/search/match-strategy.d.ts.map +1 -1
- package/dist/lib/file-operations/search/match-strategy.js +36 -50
- package/dist/lib/file-operations/search/match-strategy.js.map +1 -1
- package/dist/lib/file-operations/search-content.d.ts.map +1 -1
- package/dist/lib/file-operations/search-content.js +2 -3
- package/dist/lib/file-operations/search-content.js.map +1 -1
- package/dist/tools/search-content.d.ts.map +1 -1
- package/dist/tools/search-content.js +1 -111
- package/dist/tools/search-content.js.map +1 -1
- package/dist/tools/shared/search-formatting.d.ts +8 -0
- package/dist/tools/shared/search-formatting.d.ts.map +1 -0
- package/dist/tools/shared/search-formatting.js +112 -0
- package/dist/tools/shared/search-formatting.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DirectoryEntry } from '../../config/types.js';
|
|
2
|
+
export interface ListDirectoryState {
|
|
3
|
+
entries: DirectoryEntry[];
|
|
4
|
+
totalFiles: number;
|
|
5
|
+
totalDirectories: number;
|
|
6
|
+
maxDepthReached: number;
|
|
7
|
+
truncated: boolean;
|
|
8
|
+
skippedInaccessible: number;
|
|
9
|
+
symlinksNotFollowed: number;
|
|
10
|
+
}
|
|
11
|
+
export interface ListDirectoryConfig {
|
|
12
|
+
basePath: string;
|
|
13
|
+
recursive: boolean;
|
|
14
|
+
includeHidden: boolean;
|
|
15
|
+
maxDepth: number;
|
|
16
|
+
maxEntries?: number;
|
|
17
|
+
includeSymlinkTargets: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function initListState(): ListDirectoryState;
|
|
20
|
+
export declare function createStopChecker(maxEntries: number | undefined, state: ListDirectoryState): () => boolean;
|
|
21
|
+
export declare function handleDirectory(params: {
|
|
22
|
+
currentPath: string;
|
|
23
|
+
depth: number;
|
|
24
|
+
}, enqueue: (entry: {
|
|
25
|
+
currentPath: string;
|
|
26
|
+
depth: number;
|
|
27
|
+
}) => void, config: ListDirectoryConfig, state: ListDirectoryState, shouldStop: () => boolean): Promise<void>;
|
|
28
|
+
//# sourceMappingURL=list-directory-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-directory-helpers.d.ts","sourceRoot":"","sources":["../../../src/lib/file-operations/list-directory-helpers.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAK5D,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAED,wBAAgB,aAAa,IAAI,kBAAkB,CAUlD;AA0JD,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,KAAK,EAAE,kBAAkB,GACxB,MAAM,OAAO,CAQf;AAyCD,wBAAsB,eAAe,CACnC,MAAM,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAC9C,OAAO,EAAE,CAAC,KAAK,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,KAAK,IAAI,EAChE,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,kBAAkB,EACzB,UAAU,EAAE,MAAM,OAAO,GACxB,OAAO,CAAC,IAAI,CAAC,CA6Bf"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { PARALLEL_CONCURRENCY } from '../constants.js';
|
|
4
|
+
import { isHidden, processInParallel } from '../fs-helpers.js';
|
|
5
|
+
import { validateExistingPath } from '../path-validation.js';
|
|
6
|
+
export function initListState() {
|
|
7
|
+
return {
|
|
8
|
+
entries: [],
|
|
9
|
+
totalFiles: 0,
|
|
10
|
+
totalDirectories: 0,
|
|
11
|
+
maxDepthReached: 0,
|
|
12
|
+
truncated: false,
|
|
13
|
+
skippedInaccessible: 0,
|
|
14
|
+
symlinksNotFollowed: 0,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function buildEntryBase(item, fullPath, relativePath, type) {
|
|
18
|
+
return {
|
|
19
|
+
name: item.name,
|
|
20
|
+
path: fullPath,
|
|
21
|
+
relativePath,
|
|
22
|
+
type,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function resolveEntryType(item, stats) {
|
|
26
|
+
if (item.isDirectory())
|
|
27
|
+
return 'directory';
|
|
28
|
+
if (item.isFile())
|
|
29
|
+
return 'file';
|
|
30
|
+
return stats.isSymbolicLink() ? 'symlink' : 'other';
|
|
31
|
+
}
|
|
32
|
+
async function buildSymlinkResult(item, fullPath, relativePath, includeSymlinkTargets) {
|
|
33
|
+
const stats = await fs.lstat(fullPath);
|
|
34
|
+
let symlinkTarget;
|
|
35
|
+
if (includeSymlinkTargets) {
|
|
36
|
+
try {
|
|
37
|
+
symlinkTarget = await fs.readlink(fullPath);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
symlinkTarget = undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const entry = {
|
|
44
|
+
name: item.name,
|
|
45
|
+
path: fullPath,
|
|
46
|
+
relativePath,
|
|
47
|
+
type: 'symlink',
|
|
48
|
+
size: stats.size,
|
|
49
|
+
modified: stats.mtime,
|
|
50
|
+
symlinkTarget,
|
|
51
|
+
};
|
|
52
|
+
return { entry, symlinkNotFollowed: true };
|
|
53
|
+
}
|
|
54
|
+
async function buildEnqueueDir(fullPath, depth, maxDepth, recursive) {
|
|
55
|
+
if (!recursive || depth + 1 > maxDepth)
|
|
56
|
+
return undefined;
|
|
57
|
+
return {
|
|
58
|
+
currentPath: await validateExistingPath(fullPath),
|
|
59
|
+
depth: depth + 1,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async function buildRegularResult(item, fullPath, relativePath, options) {
|
|
63
|
+
const stats = await fs.stat(fullPath);
|
|
64
|
+
const type = resolveEntryType(item, stats);
|
|
65
|
+
const entry = {
|
|
66
|
+
...buildEntryBase(item, fullPath, relativePath, type),
|
|
67
|
+
size: type === 'file' ? stats.size : undefined,
|
|
68
|
+
modified: stats.mtime,
|
|
69
|
+
};
|
|
70
|
+
const enqueueDir = await buildEnqueueDir(fullPath, options.depth, options.maxDepth, options.recursive);
|
|
71
|
+
return { entry, enqueueDir };
|
|
72
|
+
}
|
|
73
|
+
function buildFallbackEntry(item, fullPath, relativePath) {
|
|
74
|
+
const type = item.isDirectory()
|
|
75
|
+
? 'directory'
|
|
76
|
+
: item.isFile()
|
|
77
|
+
? 'file'
|
|
78
|
+
: 'other';
|
|
79
|
+
return {
|
|
80
|
+
entry: buildEntryBase(item, fullPath, relativePath, type),
|
|
81
|
+
skippedInaccessible: true,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async function buildDirectoryItemResult(item, currentPath, basePath, options) {
|
|
85
|
+
const fullPath = path.join(currentPath, item.name);
|
|
86
|
+
const relativePath = path.relative(basePath, fullPath) || item.name;
|
|
87
|
+
try {
|
|
88
|
+
if (item.isSymbolicLink()) {
|
|
89
|
+
return await buildSymlinkResult(item, fullPath, relativePath, options.includeSymlinkTargets);
|
|
90
|
+
}
|
|
91
|
+
return await buildRegularResult(item, fullPath, relativePath, {
|
|
92
|
+
...options,
|
|
93
|
+
basePath,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return buildFallbackEntry(item, fullPath, relativePath);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export function createStopChecker(maxEntries, state) {
|
|
101
|
+
return () => {
|
|
102
|
+
if (maxEntries !== undefined && state.entries.length >= maxEntries) {
|
|
103
|
+
state.truncated = true;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async function readVisibleItems(currentPath, includeHidden) {
|
|
110
|
+
try {
|
|
111
|
+
const items = await fs.readdir(currentPath, { withFileTypes: true });
|
|
112
|
+
return includeHidden ? items : items.filter((item) => !isHidden(item.name));
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function applyDirectoryItemResult(result, state, enqueue) {
|
|
119
|
+
const { entry, enqueueDir, skippedInaccessible, symlinkNotFollowed } = result;
|
|
120
|
+
state.entries.push(entry);
|
|
121
|
+
if (entry.type === 'directory')
|
|
122
|
+
state.totalDirectories++;
|
|
123
|
+
if (entry.type === 'file')
|
|
124
|
+
state.totalFiles++;
|
|
125
|
+
if (enqueueDir)
|
|
126
|
+
enqueue(enqueueDir);
|
|
127
|
+
if (skippedInaccessible)
|
|
128
|
+
state.skippedInaccessible++;
|
|
129
|
+
if (symlinkNotFollowed)
|
|
130
|
+
state.symlinksNotFollowed++;
|
|
131
|
+
}
|
|
132
|
+
function processResults(results, state, enqueue, shouldStop) {
|
|
133
|
+
for (const result of results) {
|
|
134
|
+
if (shouldStop())
|
|
135
|
+
break;
|
|
136
|
+
applyDirectoryItemResult(result, state, enqueue);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export async function handleDirectory(params, enqueue, config, state, shouldStop) {
|
|
140
|
+
if (params.depth > config.maxDepth)
|
|
141
|
+
return;
|
|
142
|
+
if (shouldStop())
|
|
143
|
+
return;
|
|
144
|
+
state.maxDepthReached = Math.max(state.maxDepthReached, params.depth);
|
|
145
|
+
const items = await readVisibleItems(params.currentPath, config.includeHidden);
|
|
146
|
+
if (!items) {
|
|
147
|
+
state.skippedInaccessible++;
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const { results, errors } = await processInParallel(items, async (item) => buildDirectoryItemResult(item, params.currentPath, config.basePath, {
|
|
151
|
+
includeSymlinkTargets: config.includeSymlinkTargets,
|
|
152
|
+
recursive: config.recursive,
|
|
153
|
+
depth: params.depth,
|
|
154
|
+
maxDepth: config.maxDepth,
|
|
155
|
+
}), PARALLEL_CONCURRENCY);
|
|
156
|
+
state.skippedInaccessible += errors.length;
|
|
157
|
+
processResults(results, state, enqueue, shouldStop);
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=list-directory-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-directory-helpers.js","sourceRoot":"","sources":["../../../src/lib/file-operations/list-directory-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAIlC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAqB7D,MAAM,UAAU,aAAa;IAC3B,OAAO;QACL,OAAO,EAAE,EAAE;QACX,UAAU,EAAE,CAAC;QACb,gBAAgB,EAAE,CAAC;QACnB,eAAe,EAAE,CAAC;QAClB,SAAS,EAAE,KAAK;QAChB,mBAAmB,EAAE,CAAC;QACtB,mBAAmB,EAAE,CAAC;KACvB,CAAC;AACJ,CAAC;AASD,SAAS,cAAc,CACrB,IAAY,EACZ,QAAgB,EAChB,YAAoB,EACpB,IAA4B;IAE5B,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,IAAI,EAAE,QAAQ;QACd,YAAY;QACZ,IAAI;KACL,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY,EAAE,KAAY;IAClD,IAAI,IAAI,CAAC,WAAW,EAAE;QAAE,OAAO,WAAW,CAAC;IAC3C,IAAI,IAAI,CAAC,MAAM,EAAE;QAAE,OAAO,MAAM,CAAC;IACjC,OAAO,KAAK,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AACtD,CAAC;AAED,KAAK,UAAU,kBAAkB,CAC/B,IAAY,EACZ,QAAgB,EAChB,YAAoB,EACpB,qBAA8B;IAE9B,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACvC,IAAI,aAAiC,CAAC;IAEtC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AC,mBAAmB,IAAI,MAAM,CAAC,MAAM,CAAC;IAC3C,cAAc,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-directory.d.ts","sourceRoot":"","sources":["../../../src/lib/file-operations/list-directory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"list-directory.d.ts","sourceRoot":"","sources":["../../../src/lib/file-operations/list-directory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAYjE,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IACP,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;IAC/C,qBAAqB,CAAC,EAAE,OAAO,CAAC;CAC5B,GACL,OAAO,CAAC,mBAAmB,CAAC,CA4C9B"}
|
|
@@ -1,162 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { DEFAULT_MAX_DEPTH, DIR_TRAVERSAL_CONCURRENCY, PARALLEL_CONCURRENCY, } from '../constants.js';
|
|
4
|
-
import { isHidden, processInParallel, runWorkQueue } from '../fs-helpers.js';
|
|
1
|
+
import { DEFAULT_MAX_DEPTH, DIR_TRAVERSAL_CONCURRENCY } from '../constants.js';
|
|
2
|
+
import { runWorkQueue } from '../fs-helpers.js';
|
|
5
3
|
import { validateExistingPath } from '../path-validation.js';
|
|
4
|
+
import { createStopChecker, handleDirectory, initListState, } from './list-directory-helpers.js';
|
|
6
5
|
import { sortByField } from './sorting.js';
|
|
7
|
-
function initListState() {
|
|
8
|
-
return {
|
|
9
|
-
entries: [],
|
|
10
|
-
totalFiles: 0,
|
|
11
|
-
totalDirectories: 0,
|
|
12
|
-
maxDepthReached: 0,
|
|
13
|
-
truncated: false,
|
|
14
|
-
skippedInaccessible: 0,
|
|
15
|
-
symlinksNotFollowed: 0,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function buildEntryBase(item, fullPath, relativePath, type) {
|
|
19
|
-
return {
|
|
20
|
-
name: item.name,
|
|
21
|
-
path: fullPath,
|
|
22
|
-
relativePath,
|
|
23
|
-
type,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function resolveEntryType(item, stats) {
|
|
27
|
-
if (item.isDirectory())
|
|
28
|
-
return 'directory';
|
|
29
|
-
if (item.isFile())
|
|
30
|
-
return 'file';
|
|
31
|
-
return stats.isSymbolicLink() ? 'symlink' : 'other';
|
|
32
|
-
}
|
|
33
|
-
async function buildSymlinkResult(item, fullPath, relativePath, includeSymlinkTargets) {
|
|
34
|
-
const stats = await fs.lstat(fullPath);
|
|
35
|
-
let symlinkTarget;
|
|
36
|
-
if (includeSymlinkTargets) {
|
|
37
|
-
try {
|
|
38
|
-
symlinkTarget = await fs.readlink(fullPath);
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
symlinkTarget = undefined;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const entry = {
|
|
45
|
-
name: item.name,
|
|
46
|
-
path: fullPath,
|
|
47
|
-
relativePath,
|
|
48
|
-
type: 'symlink',
|
|
49
|
-
size: stats.size,
|
|
50
|
-
modified: stats.mtime,
|
|
51
|
-
symlinkTarget,
|
|
52
|
-
};
|
|
53
|
-
return { entry, symlinkNotFollowed: true };
|
|
54
|
-
}
|
|
55
|
-
async function buildEnqueueDir(fullPath, depth, maxDepth, recursive) {
|
|
56
|
-
if (!recursive || depth + 1 > maxDepth)
|
|
57
|
-
return undefined;
|
|
58
|
-
return {
|
|
59
|
-
currentPath: await validateExistingPath(fullPath),
|
|
60
|
-
depth: depth + 1,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
async function buildRegularResult(item, fullPath, relativePath, options) {
|
|
64
|
-
const stats = await fs.stat(fullPath);
|
|
65
|
-
const type = resolveEntryType(item, stats);
|
|
66
|
-
const entry = {
|
|
67
|
-
...buildEntryBase(item, fullPath, relativePath, type),
|
|
68
|
-
size: type === 'file' ? stats.size : undefined,
|
|
69
|
-
modified: stats.mtime,
|
|
70
|
-
};
|
|
71
|
-
const enqueueDir = await buildEnqueueDir(fullPath, options.depth, options.maxDepth, options.recursive);
|
|
72
|
-
return { entry, enqueueDir };
|
|
73
|
-
}
|
|
74
|
-
function buildFallbackEntry(item, fullPath, relativePath) {
|
|
75
|
-
const type = item.isDirectory()
|
|
76
|
-
? 'directory'
|
|
77
|
-
: item.isFile()
|
|
78
|
-
? 'file'
|
|
79
|
-
: 'other';
|
|
80
|
-
return {
|
|
81
|
-
entry: buildEntryBase(item, fullPath, relativePath, type),
|
|
82
|
-
skippedInaccessible: true,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
async function buildDirectoryItemResult(item, currentPath, basePath, options) {
|
|
86
|
-
const fullPath = path.join(currentPath, item.name);
|
|
87
|
-
const relativePath = path.relative(basePath, fullPath) || item.name;
|
|
88
|
-
try {
|
|
89
|
-
if (item.isSymbolicLink()) {
|
|
90
|
-
return await buildSymlinkResult(item, fullPath, relativePath, options.includeSymlinkTargets);
|
|
91
|
-
}
|
|
92
|
-
return await buildRegularResult(item, fullPath, relativePath, {
|
|
93
|
-
...options,
|
|
94
|
-
basePath,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
return buildFallbackEntry(item, fullPath, relativePath);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
function createStopChecker(maxEntries, state) {
|
|
102
|
-
return () => {
|
|
103
|
-
if (maxEntries !== undefined && state.entries.length >= maxEntries) {
|
|
104
|
-
state.truncated = true;
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
async function readVisibleItems(currentPath, includeHidden) {
|
|
111
|
-
try {
|
|
112
|
-
const items = await fs.readdir(currentPath, { withFileTypes: true });
|
|
113
|
-
return includeHidden ? items : items.filter((item) => !isHidden(item.name));
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function applyDirectoryItemResult(result, state, enqueue) {
|
|
120
|
-
const { entry, enqueueDir, skippedInaccessible, symlinkNotFollowed } = result;
|
|
121
|
-
state.entries.push(entry);
|
|
122
|
-
if (entry.type === 'directory')
|
|
123
|
-
state.totalDirectories++;
|
|
124
|
-
if (entry.type === 'file')
|
|
125
|
-
state.totalFiles++;
|
|
126
|
-
if (enqueueDir)
|
|
127
|
-
enqueue(enqueueDir);
|
|
128
|
-
if (skippedInaccessible)
|
|
129
|
-
state.skippedInaccessible++;
|
|
130
|
-
if (symlinkNotFollowed)
|
|
131
|
-
state.symlinksNotFollowed++;
|
|
132
|
-
}
|
|
133
|
-
function processResults(results, state, enqueue, shouldStop) {
|
|
134
|
-
for (const result of results) {
|
|
135
|
-
if (shouldStop())
|
|
136
|
-
break;
|
|
137
|
-
applyDirectoryItemResult(result, state, enqueue);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
async function handleDirectory(params, enqueue, config, state, shouldStop) {
|
|
141
|
-
if (params.depth > config.maxDepth)
|
|
142
|
-
return;
|
|
143
|
-
if (shouldStop())
|
|
144
|
-
return;
|
|
145
|
-
state.maxDepthReached = Math.max(state.maxDepthReached, params.depth);
|
|
146
|
-
const items = await readVisibleItems(params.currentPath, config.includeHidden);
|
|
147
|
-
if (!items) {
|
|
148
|
-
state.skippedInaccessible++;
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const { results, errors } = await processInParallel(items, async (item) => buildDirectoryItemResult(item, params.currentPath, config.basePath, {
|
|
152
|
-
includeSymlinkTargets: config.includeSymlinkTargets,
|
|
153
|
-
recursive: config.recursive,
|
|
154
|
-
depth: params.depth,
|
|
155
|
-
maxDepth: config.maxDepth,
|
|
156
|
-
}), PARALLEL_CONCURRENCY);
|
|
157
|
-
state.skippedInaccessible += errors.length;
|
|
158
|
-
processResults(results, state, enqueue, shouldStop);
|
|
159
|
-
}
|
|
160
6
|
export async function listDirectory(dirPath, options = {}) {
|
|
161
7
|
const { recursive = false, includeHidden = false, maxDepth = DEFAULT_MAX_DEPTH, maxEntries, sortBy = 'name', includeSymlinkTargets = false, } = options;
|
|
162
8
|
const basePath = await validateExistingPath(dirPath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-directory.js","sourceRoot":"","sources":["../../../src/lib/file-operations/list-directory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"list-directory.js","sourceRoot":"","sources":["../../../src/lib/file-operations/list-directory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,aAAa,GAEd,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAe,EACf,UAOI,EAAE;IAEN,MAAM,EACJ,SAAS,GAAG,KAAK,EACjB,aAAa,GAAG,KAAK,EACrB,QAAQ,GAAG,iBAAiB,EAC5B,UAAU,EACV,MAAM,GAAG,MAAM,EACf,qBAAqB,GAAG,KAAK,GAC9B,GAAG,OAAO,CAAC;IAEZ,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,OAAO,CAAC,CAAC;IACrD,MAAM,KA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ensitiveFileMatch: boolean;
|
|
20
|
-
}>);
|
|
21
|
-
search(searchPattern: string): Promise<SearchContentResult>;
|
|
22
|
-
private createInitialState;
|
|
23
|
-
private createStream;
|
|
24
|
-
private shouldStop;
|
|
25
|
-
private updateState;
|
|
26
|
-
private buildResult;
|
|
2
|
+
interface SearchOptions {
|
|
3
|
+
filePattern: string;
|
|
4
|
+
excludePatterns: string[];
|
|
5
|
+
caseSensitive: boolean;
|
|
6
|
+
maxResults: number;
|
|
7
|
+
maxFileSize: number;
|
|
8
|
+
maxFilesScanned: number;
|
|
9
|
+
timeoutMs: number;
|
|
10
|
+
skipBinary: boolean;
|
|
11
|
+
contextLines: number;
|
|
12
|
+
wholeWord: boolean;
|
|
13
|
+
isLiteral: boolean;
|
|
14
|
+
includeHidden: boolean;
|
|
15
|
+
baseNameMatch: boolean;
|
|
16
|
+
caseSensitiveFileMatch: boolean;
|
|
27
17
|
}
|
|
18
|
+
export declare function executeSearch(basePath: string, searchPattern: string, partialOptions: Partial<SearchOptions>): Promise<SearchContentResult>;
|
|
19
|
+
export {};
|
|
28
20
|
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../../src/lib/file-operations/search/engine.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAepE,
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../../src/lib/file-operations/search/engine.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAepE,UAAU,aAAa;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,sBAAsB,EAAE,OAAO,CAAC;CACjC;AAyGD,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,OAAO,CAAC,aAAa,CAAC,GACrC,OAAO,CAAC,mBAAmB,CAAC,CAuF9B"}
|