wave-code 0.0.6 → 0.0.8
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/README.md +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/components/App.d.ts +1 -0
- package/dist/components/App.d.ts.map +1 -1
- package/dist/components/App.js +4 -4
- package/dist/components/BashHistorySelector.d.ts.map +1 -1
- package/dist/components/BashHistorySelector.js +17 -3
- package/dist/components/ChatInterface.d.ts.map +1 -1
- package/dist/components/ChatInterface.js +4 -2
- package/dist/components/Confirmation.d.ts +11 -0
- package/dist/components/Confirmation.d.ts.map +1 -0
- package/dist/components/Confirmation.js +148 -0
- package/dist/components/DiffDisplay.d.ts +8 -0
- package/dist/components/DiffDisplay.d.ts.map +1 -0
- package/dist/components/DiffDisplay.js +168 -0
- package/dist/components/FileSelector.d.ts +2 -4
- package/dist/components/FileSelector.d.ts.map +1 -1
- package/dist/components/InputBox.d.ts.map +1 -1
- package/dist/components/InputBox.js +10 -1
- package/dist/components/MemoryDisplay.js +1 -1
- package/dist/components/MessageItem.d.ts +1 -2
- package/dist/components/MessageItem.d.ts.map +1 -1
- package/dist/components/MessageItem.js +3 -3
- package/dist/components/MessageList.d.ts.map +1 -1
- package/dist/components/MessageList.js +2 -2
- package/dist/components/ReasoningDisplay.d.ts +8 -0
- package/dist/components/ReasoningDisplay.d.ts.map +1 -0
- package/dist/components/ReasoningDisplay.js +10 -0
- package/dist/components/ToolResultDisplay.d.ts.map +1 -1
- package/dist/components/ToolResultDisplay.js +2 -1
- package/dist/contexts/useChat.d.ts +13 -1
- package/dist/contexts/useChat.d.ts.map +1 -1
- package/dist/contexts/useChat.js +117 -15
- package/dist/hooks/useInputManager.d.ts +3 -0
- package/dist/hooks/useInputManager.d.ts.map +1 -1
- package/dist/hooks/useInputManager.js +17 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -4
- package/dist/managers/InputManager.d.ts +8 -0
- package/dist/managers/InputManager.d.ts.map +1 -1
- package/dist/managers/InputManager.js +33 -2
- package/dist/print-cli.d.ts +1 -0
- package/dist/print-cli.d.ts.map +1 -1
- package/dist/print-cli.js +36 -3
- package/dist/utils/toolParameterTransforms.d.ts +23 -0
- package/dist/utils/toolParameterTransforms.d.ts.map +1 -0
- package/dist/utils/toolParameterTransforms.js +77 -0
- package/package.json +6 -5
- package/src/cli.tsx +3 -1
- package/src/components/App.tsx +7 -3
- package/src/components/BashHistorySelector.tsx +26 -3
- package/src/components/ChatInterface.tsx +29 -15
- package/src/components/Confirmation.tsx +253 -0
- package/src/components/DiffDisplay.tsx +300 -0
- package/src/components/FileSelector.tsx +2 -4
- package/src/components/InputBox.tsx +37 -14
- package/src/components/MemoryDisplay.tsx +1 -1
- package/src/components/MessageItem.tsx +4 -12
- package/src/components/MessageList.tsx +0 -2
- package/src/components/ReasoningDisplay.tsx +33 -0
- package/src/components/ToolResultDisplay.tsx +4 -0
- package/src/contexts/useChat.tsx +178 -14
- package/src/hooks/useInputManager.ts +19 -0
- package/src/index.ts +34 -4
- package/src/managers/InputManager.ts +46 -2
- package/src/print-cli.ts +42 -2
- package/src/utils/toolParameterTransforms.ts +104 -0
- package/dist/components/DiffViewer.d.ts +0 -9
- package/dist/components/DiffViewer.d.ts.map +0 -1
- package/dist/components/DiffViewer.js +0 -221
- package/dist/utils/fileSearch.d.ts +0 -20
- package/dist/utils/fileSearch.d.ts.map +0 -1
- package/dist/utils/fileSearch.js +0 -102
- package/src/components/DiffViewer.tsx +0 -323
- package/src/utils/fileSearch.ts +0 -133
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import React, { useMemo } from "react";
|
|
2
|
-
import { Text, Box } from "ink";
|
|
3
|
-
import { diffWords } from "diff";
|
|
4
|
-
import type { DiffBlock } from "wave-agent-sdk";
|
|
5
|
-
|
|
6
|
-
interface DiffViewerProps {
|
|
7
|
-
block: DiffBlock;
|
|
8
|
-
isStatic?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Render word-level diff
|
|
12
|
-
const renderWordLevelDiff = (removedLine: string, addedLine: string) => {
|
|
13
|
-
const changes = diffWords(removedLine, addedLine);
|
|
14
|
-
|
|
15
|
-
const removedParts: React.ReactNode[] = [];
|
|
16
|
-
const addedParts: React.ReactNode[] = [];
|
|
17
|
-
|
|
18
|
-
changes.forEach((part, index) => {
|
|
19
|
-
if (part.removed) {
|
|
20
|
-
removedParts.push(
|
|
21
|
-
<Text key={`removed-${index}`} color="black" backgroundColor="red">
|
|
22
|
-
{part.value}
|
|
23
|
-
</Text>,
|
|
24
|
-
);
|
|
25
|
-
} else if (part.added) {
|
|
26
|
-
addedParts.push(
|
|
27
|
-
<Text key={`added-${index}`} color="black" backgroundColor="green">
|
|
28
|
-
{part.value}
|
|
29
|
-
</Text>,
|
|
30
|
-
);
|
|
31
|
-
} else {
|
|
32
|
-
// Unchanged parts, need to display on both sides
|
|
33
|
-
removedParts.push(
|
|
34
|
-
<Text key={`removed-unchanged-${index}`} color="red">
|
|
35
|
-
{part.value}
|
|
36
|
-
</Text>,
|
|
37
|
-
);
|
|
38
|
-
addedParts.push(
|
|
39
|
-
<Text key={`added-unchanged-${index}`} color="green">
|
|
40
|
-
{part.value}
|
|
41
|
-
</Text>,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
return { removedParts, addedParts };
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const DiffViewer: React.FC<DiffViewerProps> = ({
|
|
50
|
-
block,
|
|
51
|
-
isStatic = true,
|
|
52
|
-
}) => {
|
|
53
|
-
const { diffResult } = block;
|
|
54
|
-
|
|
55
|
-
const diffLines = useMemo(() => {
|
|
56
|
-
if (!diffResult) return [];
|
|
57
|
-
|
|
58
|
-
const lines: Array<{
|
|
59
|
-
content: string;
|
|
60
|
-
type: "added" | "removed" | "unchanged" | "separator";
|
|
61
|
-
lineNumber?: number;
|
|
62
|
-
rawContent?: string; // Store original content for word-level comparison
|
|
63
|
-
wordDiff?: {
|
|
64
|
-
removedParts: React.ReactNode[];
|
|
65
|
-
addedParts: React.ReactNode[];
|
|
66
|
-
};
|
|
67
|
-
}> = [];
|
|
68
|
-
|
|
69
|
-
let originalLineNum = 1;
|
|
70
|
-
let modifiedLineNum = 1;
|
|
71
|
-
const maxContext = 3; // Show at most 3 lines of context
|
|
72
|
-
|
|
73
|
-
// Buffer for storing context
|
|
74
|
-
let contextBuffer: Array<{
|
|
75
|
-
content: string;
|
|
76
|
-
type: "unchanged";
|
|
77
|
-
lineNumber: number;
|
|
78
|
-
}> = [];
|
|
79
|
-
|
|
80
|
-
let hasAnyChanges = false;
|
|
81
|
-
let afterChangeContext = 0;
|
|
82
|
-
|
|
83
|
-
// Temporarily store adjacent deleted and added lines for word-level comparison
|
|
84
|
-
let pendingRemovedLines: Array<{
|
|
85
|
-
content: string;
|
|
86
|
-
rawContent: string;
|
|
87
|
-
lineNumber: number;
|
|
88
|
-
}> = [];
|
|
89
|
-
|
|
90
|
-
const flushPendingLines = () => {
|
|
91
|
-
pendingRemovedLines.forEach((line) => {
|
|
92
|
-
lines.push({
|
|
93
|
-
content: line.content,
|
|
94
|
-
type: "removed",
|
|
95
|
-
lineNumber: line.lineNumber,
|
|
96
|
-
rawContent: line.rawContent,
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
pendingRemovedLines = [];
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
diffResult.forEach(
|
|
103
|
-
(part: { value: string; added?: boolean; removed?: boolean }) => {
|
|
104
|
-
const partLines = part.value.split("\n");
|
|
105
|
-
// Remove the last empty line (produced by split)
|
|
106
|
-
if (partLines[partLines.length - 1] === "") {
|
|
107
|
-
partLines.pop();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (part.removed) {
|
|
111
|
-
// If this is the first change encountered, add preceding context
|
|
112
|
-
if (!hasAnyChanges) {
|
|
113
|
-
// Take the last few lines from the buffer as preceding context
|
|
114
|
-
const preContext = contextBuffer.slice(-maxContext);
|
|
115
|
-
if (contextBuffer.length > maxContext) {
|
|
116
|
-
lines.push({
|
|
117
|
-
content: "...",
|
|
118
|
-
type: "separator",
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
lines.push(...preContext);
|
|
122
|
-
} else if (afterChangeContext > maxContext) {
|
|
123
|
-
// If there's too much context after the previous change, add a separator
|
|
124
|
-
lines.push({
|
|
125
|
-
content: "...",
|
|
126
|
-
type: "separator",
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Temporarily store deleted lines, waiting for possible added lines for word-level comparison
|
|
131
|
-
partLines.forEach((line: string) => {
|
|
132
|
-
pendingRemovedLines.push({
|
|
133
|
-
content: `- ${line}`,
|
|
134
|
-
rawContent: line,
|
|
135
|
-
lineNumber: originalLineNum++,
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
hasAnyChanges = true;
|
|
140
|
-
afterChangeContext = 0;
|
|
141
|
-
contextBuffer = []; // Clear buffer
|
|
142
|
-
} else if (part.added) {
|
|
143
|
-
// If this is the first change encountered, add preceding context
|
|
144
|
-
if (!hasAnyChanges) {
|
|
145
|
-
const preContext = contextBuffer.slice(-maxContext);
|
|
146
|
-
if (contextBuffer.length > maxContext) {
|
|
147
|
-
lines.push({
|
|
148
|
-
content: "...",
|
|
149
|
-
type: "separator",
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
lines.push(...preContext);
|
|
153
|
-
} else if (afterChangeContext > maxContext) {
|
|
154
|
-
lines.push({
|
|
155
|
-
content: "...",
|
|
156
|
-
type: "separator",
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Process added lines, try to do word-level comparison with pending deleted lines
|
|
161
|
-
partLines.forEach((line: string, index: number) => {
|
|
162
|
-
if (index < pendingRemovedLines.length) {
|
|
163
|
-
// Has corresponding deleted line, perform word-level comparison
|
|
164
|
-
const removedLine = pendingRemovedLines[index];
|
|
165
|
-
const wordDiff = renderWordLevelDiff(
|
|
166
|
-
removedLine.rawContent,
|
|
167
|
-
line,
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
// Add deleted line (with word-level highlighting)
|
|
171
|
-
lines.push({
|
|
172
|
-
content: `- ${removedLine.rawContent}`,
|
|
173
|
-
type: "removed",
|
|
174
|
-
lineNumber: removedLine.lineNumber,
|
|
175
|
-
rawContent: removedLine.rawContent,
|
|
176
|
-
wordDiff: {
|
|
177
|
-
removedParts: wordDiff.removedParts,
|
|
178
|
-
addedParts: [],
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
// Add added line (with word-level highlighting)
|
|
183
|
-
lines.push({
|
|
184
|
-
content: `+ ${line}`,
|
|
185
|
-
type: "added",
|
|
186
|
-
lineNumber: modifiedLineNum++,
|
|
187
|
-
rawContent: line,
|
|
188
|
-
wordDiff: { removedParts: [], addedParts: wordDiff.addedParts },
|
|
189
|
-
});
|
|
190
|
-
} else {
|
|
191
|
-
// No corresponding deleted line, directly add the added line
|
|
192
|
-
lines.push({
|
|
193
|
-
content: `+ ${line}`,
|
|
194
|
-
type: "added",
|
|
195
|
-
lineNumber: modifiedLineNum++,
|
|
196
|
-
rawContent: line,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// If there are more deleted lines than added lines, add remaining deleted lines
|
|
202
|
-
for (let i = partLines.length; i < pendingRemovedLines.length; i++) {
|
|
203
|
-
const removedLine = pendingRemovedLines[i];
|
|
204
|
-
lines.push({
|
|
205
|
-
content: removedLine.content,
|
|
206
|
-
type: "removed",
|
|
207
|
-
lineNumber: removedLine.lineNumber,
|
|
208
|
-
rawContent: removedLine.rawContent,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
pendingRemovedLines = []; // Clear pending deleted lines
|
|
213
|
-
hasAnyChanges = true;
|
|
214
|
-
afterChangeContext = 0;
|
|
215
|
-
contextBuffer = [];
|
|
216
|
-
} else {
|
|
217
|
-
// Before processing unchanged lines, first clear pending deleted lines
|
|
218
|
-
flushPendingLines();
|
|
219
|
-
|
|
220
|
-
// Process unchanged lines
|
|
221
|
-
partLines.forEach((line: string) => {
|
|
222
|
-
const contextLine = {
|
|
223
|
-
content: ` ${line}`,
|
|
224
|
-
type: "unchanged" as const,
|
|
225
|
-
lineNumber: originalLineNum,
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
if (hasAnyChanges) {
|
|
229
|
-
// If there are already changes, these are post-change context
|
|
230
|
-
if (afterChangeContext < maxContext) {
|
|
231
|
-
lines.push(contextLine);
|
|
232
|
-
afterChangeContext++;
|
|
233
|
-
}
|
|
234
|
-
} else {
|
|
235
|
-
// If no changes yet, add to buffer
|
|
236
|
-
contextBuffer.push(contextLine);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
originalLineNum++;
|
|
240
|
-
modifiedLineNum++;
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
// Handle remaining deleted lines at the end
|
|
247
|
-
flushPendingLines();
|
|
248
|
-
|
|
249
|
-
return lines;
|
|
250
|
-
}, [diffResult]);
|
|
251
|
-
|
|
252
|
-
// Truncate to last 10 lines for non-static items
|
|
253
|
-
const displayLines = useMemo(() => {
|
|
254
|
-
if (isStatic) {
|
|
255
|
-
return diffLines;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const MAX_LINES = 10;
|
|
259
|
-
if (diffLines.length <= MAX_LINES) {
|
|
260
|
-
return diffLines;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return diffLines.slice(-MAX_LINES);
|
|
264
|
-
}, [diffLines, isStatic]);
|
|
265
|
-
|
|
266
|
-
if (!diffResult || diffResult.length === 0) {
|
|
267
|
-
return (
|
|
268
|
-
<Box flexDirection="column">
|
|
269
|
-
<Text color="gray">No changes detected</Text>
|
|
270
|
-
</Box>
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Show traditional diff view
|
|
275
|
-
return (
|
|
276
|
-
<Box flexDirection="column">
|
|
277
|
-
<Box flexDirection="column">
|
|
278
|
-
<Box flexDirection="column">
|
|
279
|
-
{displayLines.map((line, index) => {
|
|
280
|
-
// If has word-level diff, render special effects
|
|
281
|
-
if (line.wordDiff) {
|
|
282
|
-
const prefix = line.type === "removed" ? "- " : "+ ";
|
|
283
|
-
const parts =
|
|
284
|
-
line.type === "removed"
|
|
285
|
-
? line.wordDiff.removedParts
|
|
286
|
-
: line.wordDiff.addedParts;
|
|
287
|
-
|
|
288
|
-
return (
|
|
289
|
-
<Box key={index} flexDirection="row">
|
|
290
|
-
<Text color={line.type === "removed" ? "red" : "green"}>
|
|
291
|
-
{prefix}
|
|
292
|
-
</Text>
|
|
293
|
-
<Box flexDirection="row" flexWrap="wrap">
|
|
294
|
-
{parts}
|
|
295
|
-
</Box>
|
|
296
|
-
</Box>
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// Normal rendering
|
|
301
|
-
return (
|
|
302
|
-
<Text
|
|
303
|
-
key={index}
|
|
304
|
-
color={
|
|
305
|
-
line.type === "added"
|
|
306
|
-
? "green"
|
|
307
|
-
: line.type === "removed"
|
|
308
|
-
? "red"
|
|
309
|
-
: line.type === "separator"
|
|
310
|
-
? "gray"
|
|
311
|
-
: "white"
|
|
312
|
-
}
|
|
313
|
-
dimColor={line.type === "separator"}
|
|
314
|
-
>
|
|
315
|
-
{line.content}
|
|
316
|
-
</Text>
|
|
317
|
-
);
|
|
318
|
-
})}
|
|
319
|
-
</Box>
|
|
320
|
-
</Box>
|
|
321
|
-
</Box>
|
|
322
|
-
);
|
|
323
|
-
};
|
package/src/utils/fileSearch.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { glob } from "glob";
|
|
2
|
-
import { getGlobIgnorePatterns } from "wave-agent-sdk";
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import * as path from "path";
|
|
5
|
-
|
|
6
|
-
export interface FileItem {
|
|
7
|
-
path: string;
|
|
8
|
-
type: "file" | "directory";
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Check if path is a directory
|
|
13
|
-
*/
|
|
14
|
-
export const isDirectory = (filePath: string): boolean => {
|
|
15
|
-
try {
|
|
16
|
-
const fullPath = path.isAbsolute(filePath)
|
|
17
|
-
? filePath
|
|
18
|
-
: path.join(process.cwd(), filePath);
|
|
19
|
-
return fs.statSync(fullPath).isDirectory();
|
|
20
|
-
} catch {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Convert string paths to FileItem objects
|
|
27
|
-
*/
|
|
28
|
-
export const convertToFileItems = (paths: string[]): FileItem[] => {
|
|
29
|
-
return paths.map((filePath) => ({
|
|
30
|
-
path: filePath,
|
|
31
|
-
type: isDirectory(filePath) ? "directory" : "file",
|
|
32
|
-
}));
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Search files and directories using glob patterns
|
|
37
|
-
*/
|
|
38
|
-
export const searchFiles = async (
|
|
39
|
-
query: string,
|
|
40
|
-
options?: {
|
|
41
|
-
maxResults?: number;
|
|
42
|
-
workingDirectory?: string;
|
|
43
|
-
},
|
|
44
|
-
): Promise<FileItem[]> => {
|
|
45
|
-
const { maxResults = 10, workingDirectory = process.cwd() } = options || {};
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
let files: string[] = [];
|
|
49
|
-
let directories: string[] = [];
|
|
50
|
-
|
|
51
|
-
const globOptions = {
|
|
52
|
-
ignore: getGlobIgnorePatterns(workingDirectory),
|
|
53
|
-
maxDepth: 10,
|
|
54
|
-
nocase: true, // Case insensitive
|
|
55
|
-
dot: true, // Include hidden files and directories
|
|
56
|
-
cwd: workingDirectory, // Specify search root directory
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
if (!query.trim()) {
|
|
60
|
-
// When query is empty, show some common file types and directories
|
|
61
|
-
const commonPatterns = [
|
|
62
|
-
"**/*.ts",
|
|
63
|
-
"**/*.tsx",
|
|
64
|
-
"**/*.js",
|
|
65
|
-
"**/*.jsx",
|
|
66
|
-
"**/*.json",
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
// Search files
|
|
70
|
-
const filePromises = commonPatterns.map((pattern) =>
|
|
71
|
-
glob(pattern, { ...globOptions, nodir: true }),
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
// Search directories (only search first level to avoid too many results)
|
|
75
|
-
const dirPromises = [glob("*/", { ...globOptions, maxDepth: 1 })];
|
|
76
|
-
|
|
77
|
-
const fileResults = await Promise.all(filePromises);
|
|
78
|
-
const dirResults = await Promise.all(dirPromises);
|
|
79
|
-
|
|
80
|
-
files = fileResults.flat();
|
|
81
|
-
directories = dirResults.flat().map((dir) => {
|
|
82
|
-
// glob returns string type paths, remove trailing slash
|
|
83
|
-
return String(dir).replace(/\/$/, "");
|
|
84
|
-
});
|
|
85
|
-
} else {
|
|
86
|
-
// Build multiple glob patterns to support more flexible search
|
|
87
|
-
const filePatterns = [
|
|
88
|
-
// Match files with filenames containing query
|
|
89
|
-
`**/*${query}*`,
|
|
90
|
-
// Match files with query in path (match directory names)
|
|
91
|
-
`**/${query}*/**/*`,
|
|
92
|
-
];
|
|
93
|
-
|
|
94
|
-
const dirPatterns = [
|
|
95
|
-
// Match directory names containing query
|
|
96
|
-
`**/*${query}*/`,
|
|
97
|
-
// Match directories containing query in path
|
|
98
|
-
`**/${query}*/`,
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
// Search files
|
|
102
|
-
const filePromises = filePatterns.map((pattern) =>
|
|
103
|
-
glob(pattern, { ...globOptions, nodir: true }),
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// Search directories
|
|
107
|
-
const dirPromises = dirPatterns.map((pattern) =>
|
|
108
|
-
glob(pattern, { ...globOptions, nodir: false }),
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
const fileResults = await Promise.all(filePromises);
|
|
112
|
-
const dirResults = await Promise.all(dirPromises);
|
|
113
|
-
|
|
114
|
-
files = fileResults.flat();
|
|
115
|
-
directories = dirResults.flat().map((dir) => {
|
|
116
|
-
// glob returns string type paths, remove trailing slash
|
|
117
|
-
return String(dir).replace(/\/$/, "");
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Deduplicate and merge files and directories
|
|
122
|
-
const uniqueFiles = Array.from(new Set(files));
|
|
123
|
-
const uniqueDirectories = Array.from(new Set(directories));
|
|
124
|
-
const allPaths = [...uniqueDirectories, ...uniqueFiles]; // Directories first
|
|
125
|
-
|
|
126
|
-
// Limit to maximum results and convert to FileItem
|
|
127
|
-
const fileItems = convertToFileItems(allPaths.slice(0, maxResults));
|
|
128
|
-
return fileItems;
|
|
129
|
-
} catch (error) {
|
|
130
|
-
console.error("Glob search error:", error);
|
|
131
|
-
return [];
|
|
132
|
-
}
|
|
133
|
-
};
|