oricore 1.0.0
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/LICENSE +21 -0
- package/README.md +199 -0
- package/dist/agent/agent/agentManager.d.ts +38 -0
- package/dist/agent/agent/builtin/common.d.ts +5 -0
- package/dist/agent/agent/builtin/explore.d.ts +5 -0
- package/dist/agent/agent/builtin/general-purpose.d.ts +5 -0
- package/dist/agent/agent/builtin/index.d.ts +5 -0
- package/dist/agent/agent/executor.d.ts +2 -0
- package/dist/agent/agent/types.d.ts +98 -0
- package/dist/api/engine.d.ts +213 -0
- package/dist/communication/index.d.ts +4 -0
- package/dist/communication/messageBus.d.ts +71 -0
- package/dist/core/at.d.ts +26 -0
- package/dist/core/backgroundTaskManager.d.ts +27 -0
- package/dist/core/compact.d.ts +9 -0
- package/dist/core/config.d.ts +103 -0
- package/dist/core/constants.d.ts +32 -0
- package/dist/core/context.d.ts +57 -0
- package/dist/core/globalData.d.ts +21 -0
- package/dist/core/history.d.ts +24 -0
- package/dist/core/ide.d.ts +103 -0
- package/dist/core/jsonl.d.ts +37 -0
- package/dist/core/llmsContext.d.ts +14 -0
- package/dist/core/loop.d.ts +82 -0
- package/dist/core/message.d.ts +132 -0
- package/dist/core/model.d.ts +79 -0
- package/dist/core/output-style/builtin/default.d.ts +2 -0
- package/dist/core/output-style/builtin/explanatory.d.ts +2 -0
- package/dist/core/output-style/builtin/index.d.ts +6 -0
- package/dist/core/output-style/builtin/miao.d.ts +2 -0
- package/dist/core/output-style/builtin/minimal.d.ts +2 -0
- package/dist/core/output-style/types.d.ts +6 -0
- package/dist/core/outputFormat.d.ts +29 -0
- package/dist/core/outputStyle.d.ts +43 -0
- package/dist/core/paths.d.ts +20 -0
- package/dist/core/planSystemPrompt.d.ts +5 -0
- package/dist/core/plugin.d.ts +138 -0
- package/dist/core/project.d.ts +64 -0
- package/dist/core/promptCache.d.ts +3 -0
- package/dist/core/query.d.ts +14 -0
- package/dist/core/rules.d.ts +8 -0
- package/dist/core/systemPrompt.d.ts +9 -0
- package/dist/core/thinking-config.d.ts +3 -0
- package/dist/core/usage.d.ts +14 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +144432 -0
- package/dist/mcp/mcp.d.ts +49 -0
- package/dist/modes/builtin.d.ts +34 -0
- package/dist/modes/index.d.ts +8 -0
- package/dist/modes/registry.d.ts +18 -0
- package/dist/modes/types.d.ts +51 -0
- package/dist/platform/index.d.ts +5 -0
- package/dist/platform/node.d.ts +28 -0
- package/dist/platform/types.d.ts +41 -0
- package/dist/session/session.d.ts +43 -0
- package/dist/skill/skill.d.ts +79 -0
- package/dist/tools/tool.d.ts +119 -0
- package/dist/tools/tools/askUserQuestion.d.ts +48 -0
- package/dist/tools/tools/bash.d.ts +43 -0
- package/dist/tools/tools/edit.d.ts +9 -0
- package/dist/tools/tools/fetch.d.ts +9 -0
- package/dist/tools/tools/glob.d.ts +7 -0
- package/dist/tools/tools/grep.d.ts +22 -0
- package/dist/tools/tools/ls.d.ts +6 -0
- package/dist/tools/tools/read.d.ts +9 -0
- package/dist/tools/tools/skill.d.ts +7 -0
- package/dist/tools/tools/task.d.ts +14 -0
- package/dist/tools/tools/todo.d.ts +37 -0
- package/dist/tools/tools/write.d.ts +7 -0
- package/dist/utils/apiKeyRotation.d.ts +2 -0
- package/dist/utils/applyEdit.d.ts +17 -0
- package/dist/utils/background-detection.d.ts +2 -0
- package/dist/utils/dotenv.d.ts +9 -0
- package/dist/utils/env.d.ts +6 -0
- package/dist/utils/error.d.ts +11 -0
- package/dist/utils/execFileNoThrow.d.ts +8 -0
- package/dist/utils/files.d.ts +10 -0
- package/dist/utils/git.d.ts +163 -0
- package/dist/utils/ide.d.ts +27 -0
- package/dist/utils/ignore.d.ts +6 -0
- package/dist/utils/isLocal.d.ts +1 -0
- package/dist/utils/language.d.ts +9 -0
- package/dist/utils/list.d.ts +20 -0
- package/dist/utils/mergeSystemMessagesMiddleware.d.ts +2 -0
- package/dist/utils/messageNormalization.d.ts +22 -0
- package/dist/utils/path.d.ts +34 -0
- package/dist/utils/prependSystemMessageMiddleware.d.ts +2 -0
- package/dist/utils/project.d.ts +1 -0
- package/dist/utils/proxy.d.ts +18 -0
- package/dist/utils/randomUUID.d.ts +5 -0
- package/dist/utils/renderSessionMarkdown.d.ts +10 -0
- package/dist/utils/ripgrep.d.ts +16 -0
- package/dist/utils/safeFrontMatter.d.ts +11 -0
- package/dist/utils/safeParseJson.d.ts +1 -0
- package/dist/utils/safeStringify.d.ts +1 -0
- package/dist/utils/sanitizeAIResponse.d.ts +30 -0
- package/dist/utils/setTerminalTitle.d.ts +1 -0
- package/dist/utils/shell-execution.d.ts +44 -0
- package/dist/utils/string.d.ts +8 -0
- package/dist/utils/symbols.d.ts +14 -0
- package/dist/utils/system-encoding.d.ts +40 -0
- package/dist/utils/tokenCounter.d.ts +8 -0
- package/dist/utils/username.d.ts +1 -0
- package/package.json +106 -0
- package/src/agent/agent/agentManager.test.ts +124 -0
- package/src/agent/agent/agentManager.ts +372 -0
- package/src/agent/agent/builtin/common.ts +20 -0
- package/src/agent/agent/builtin/explore.ts +53 -0
- package/src/agent/agent/builtin/general-purpose.ts +38 -0
- package/src/agent/agent/builtin/index.ts +13 -0
- package/src/agent/agent/executor.test.ts +339 -0
- package/src/agent/agent/executor.ts +224 -0
- package/src/agent/agent/types.ts +119 -0
- package/src/api/engine.ts +466 -0
- package/src/communication/index.ts +18 -0
- package/src/communication/messageBus.ts +393 -0
- package/src/core/at.ts +315 -0
- package/src/core/backgroundTaskManager.ts +129 -0
- package/src/core/compact.ts +95 -0
- package/src/core/config.ts +441 -0
- package/src/core/constants.ts +82 -0
- package/src/core/context.ts +214 -0
- package/src/core/globalData.ts +77 -0
- package/src/core/history.ts +323 -0
- package/src/core/ide.ts +325 -0
- package/src/core/jsonl.ts +100 -0
- package/src/core/llmsContext.ts +117 -0
- package/src/core/loop.ts +638 -0
- package/src/core/message.ts +304 -0
- package/src/core/model.ts +2198 -0
- package/src/core/output-style/builtin/default.ts +9 -0
- package/src/core/output-style/builtin/explanatory.ts +22 -0
- package/src/core/output-style/builtin/index.ts +19 -0
- package/src/core/output-style/builtin/miao.ts +22 -0
- package/src/core/output-style/builtin/minimal.ts +8 -0
- package/src/core/output-style/types.ts +6 -0
- package/src/core/outputFormat.ts +93 -0
- package/src/core/outputStyle.ts +255 -0
- package/src/core/paths.ts +161 -0
- package/src/core/planSystemPrompt.ts +46 -0
- package/src/core/plugin.ts +299 -0
- package/src/core/project.ts +492 -0
- package/src/core/promptCache.ts +32 -0
- package/src/core/query.ts +46 -0
- package/src/core/rules.ts +56 -0
- package/src/core/systemPrompt.ts +176 -0
- package/src/core/thinking-config.ts +98 -0
- package/src/core/usage.ts +68 -0
- package/src/index.ts +39 -0
- package/src/mcp/mcp.ts +637 -0
- package/src/modes/builtin.ts +305 -0
- package/src/modes/index.ts +22 -0
- package/src/modes/registry.ts +39 -0
- package/src/modes/types.ts +56 -0
- package/src/platform/index.ts +6 -0
- package/src/platform/node.ts +108 -0
- package/src/platform/types.ts +54 -0
- package/src/plugins/index.ts +15 -0
- package/src/session/session.ts +187 -0
- package/src/skill/skill.ts +702 -0
- package/src/tools/tool.ts +378 -0
- package/src/tools/tools/askUserQuestion.ts +134 -0
- package/src/tools/tools/bash.test.ts +425 -0
- package/src/tools/tools/bash.ts +999 -0
- package/src/tools/tools/edit.ts +86 -0
- package/src/tools/tools/fetch.ts +129 -0
- package/src/tools/tools/glob.ts +69 -0
- package/src/tools/tools/grep.test.ts +194 -0
- package/src/tools/tools/grep.ts +358 -0
- package/src/tools/tools/ls.ts +51 -0
- package/src/tools/tools/read.test.ts +169 -0
- package/src/tools/tools/read.ts +284 -0
- package/src/tools/tools/skill.ts +73 -0
- package/src/tools/tools/task.test.ts +262 -0
- package/src/tools/tools/task.ts +284 -0
- package/src/tools/tools/todo.ts +269 -0
- package/src/tools/tools/write.ts +71 -0
- package/src/types.d.ts +18 -0
- package/src/utils/apiKeyRotation.test.ts +70 -0
- package/src/utils/apiKeyRotation.ts +24 -0
- package/src/utils/applyEdit.test.ts +388 -0
- package/src/utils/applyEdit.ts +547 -0
- package/src/utils/background-detection.test.ts +61 -0
- package/src/utils/background-detection.ts +58 -0
- package/src/utils/dotenv.ts +26 -0
- package/src/utils/env.ts +90 -0
- package/src/utils/error.ts +38 -0
- package/src/utils/execFileNoThrow.ts +49 -0
- package/src/utils/files.ts +93 -0
- package/src/utils/git.ts +1152 -0
- package/src/utils/ide.ts +279 -0
- package/src/utils/ignore.ts +275 -0
- package/src/utils/isLocal.ts +6 -0
- package/src/utils/language.ts +33 -0
- package/src/utils/list.ts +200 -0
- package/src/utils/mergeSystemMessagesMiddleware.ts +32 -0
- package/src/utils/messageNormalization.test.ts +401 -0
- package/src/utils/messageNormalization.ts +168 -0
- package/src/utils/path.ts +98 -0
- package/src/utils/prependSystemMessageMiddleware.ts +16 -0
- package/src/utils/project.ts +32 -0
- package/src/utils/proxy.ts +102 -0
- package/src/utils/randomUUID.ts +11 -0
- package/src/utils/renderSessionMarkdown.ts +175 -0
- package/src/utils/ripgrep.ts +189 -0
- package/src/utils/safeFrontMatter.test.ts +118 -0
- package/src/utils/safeFrontMatter.ts +68 -0
- package/src/utils/safeParseJson.ts +7 -0
- package/src/utils/safeStringify.ts +10 -0
- package/src/utils/sanitizeAIResponse.test.ts +135 -0
- package/src/utils/sanitizeAIResponse.ts +55 -0
- package/src/utils/setTerminalTitle.ts +7 -0
- package/src/utils/shell-execution.test.ts +237 -0
- package/src/utils/shell-execution.ts +279 -0
- package/src/utils/string.ts +13 -0
- package/src/utils/symbols.ts +18 -0
- package/src/utils/system-encoding.test.ts +164 -0
- package/src/utils/system-encoding.ts +296 -0
- package/src/utils/tokenCounter.test.ts +38 -0
- package/src/utils/tokenCounter.ts +19 -0
- package/src/utils/username.ts +21 -0
package/src/utils/env.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
function getTerminal() {
|
|
2
|
+
if (process.env.CURSOR_TRACE_ID) return 'cursor';
|
|
3
|
+
if (process.env.VSCODE_GIT_ASKPASS_MAIN?.includes('/.cursor-server/bin/'))
|
|
4
|
+
return 'cursor';
|
|
5
|
+
if (process.env.VSCODE_GIT_ASKPASS_MAIN?.includes('/.windsurf-server/bin/'))
|
|
6
|
+
return 'windsurf';
|
|
7
|
+
const A = process.env.__CFBundleIdentifier?.toLowerCase();
|
|
8
|
+
if (A?.includes('vscodium')) return 'codium';
|
|
9
|
+
if (A?.includes('windsurf')) return 'windsurf';
|
|
10
|
+
if (A?.includes('pycharm')) return 'pycharm';
|
|
11
|
+
if (A?.includes('intellij')) return 'intellij';
|
|
12
|
+
if (A?.includes('webstorm')) return 'webstorm';
|
|
13
|
+
if (A?.includes('phpstorm')) return 'phpstorm';
|
|
14
|
+
if (A?.includes('rubymine')) return 'rubymine';
|
|
15
|
+
if (A?.includes('clion')) return 'clion';
|
|
16
|
+
if (A?.includes('goland')) return 'goland';
|
|
17
|
+
if (A?.includes('rider')) return 'rider';
|
|
18
|
+
if (A?.includes('datagrip')) return 'datagrip';
|
|
19
|
+
if (A?.includes('appcode')) return 'appcode';
|
|
20
|
+
if (A?.includes('dataspell')) return 'dataspell';
|
|
21
|
+
if (A?.includes('aqua')) return 'aqua';
|
|
22
|
+
if (A?.includes('gateway')) return 'gateway';
|
|
23
|
+
if (A?.includes('fleet')) return 'fleet';
|
|
24
|
+
if (A?.includes('com.google.android.studio')) return 'androidstudio';
|
|
25
|
+
if (process.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm') return 'pycharm';
|
|
26
|
+
if (process.env.TERM === 'xterm-ghostty') return 'ghostty';
|
|
27
|
+
if (process.env.TERM?.includes('kitty')) return 'kitty';
|
|
28
|
+
if (process.env.TERM_PROGRAM) return process.env.TERM_PROGRAM;
|
|
29
|
+
if (process.env.TMUX) return 'tmux';
|
|
30
|
+
if (process.env.STY) return 'screen';
|
|
31
|
+
if (process.env.KONSOLE_VERSION) return 'konsole';
|
|
32
|
+
if (process.env.GNOME_TERMINAL_SERVICE) return 'gnome-terminal';
|
|
33
|
+
if (process.env.XTERM_VERSION) return 'xterm';
|
|
34
|
+
if (process.env.VTE_VERSION) return 'vte-based';
|
|
35
|
+
if (process.env.TERMINATOR_UUID) return 'terminator';
|
|
36
|
+
if (process.env.KITTY_WINDOW_ID) return 'kitty';
|
|
37
|
+
if (process.env.ALACRITTY_LOG) return 'alacritty';
|
|
38
|
+
if (process.env.TILIX_ID) return 'tilix';
|
|
39
|
+
if (process.env.WT_SESSION) return 'windows-terminal';
|
|
40
|
+
if (process.env.SESSIONNAME && process.env.TERM === 'cygwin') return 'cygwin';
|
|
41
|
+
if (process.env.MSYSTEM) return process.env.MSYSTEM.toLowerCase();
|
|
42
|
+
if (process.env.ConEmuTask) return 'conemu';
|
|
43
|
+
if (process.env.WSL_DISTRO_NAME) return `wsl-${process.env.WSL_DISTRO_NAME}`;
|
|
44
|
+
if (
|
|
45
|
+
process.env.SSH_CONNECTION ||
|
|
46
|
+
process.env.SSH_CLIENT ||
|
|
47
|
+
process.env.SSH_TTY
|
|
48
|
+
)
|
|
49
|
+
return 'ssh-session';
|
|
50
|
+
if (process.env.TERM) {
|
|
51
|
+
const B = process.env.TERM;
|
|
52
|
+
if (B.includes('alacritty')) return 'alacritty';
|
|
53
|
+
if (B.includes('rxvt')) return 'rxvt';
|
|
54
|
+
if (B.includes('termite')) return 'termite';
|
|
55
|
+
return process.env.TERM;
|
|
56
|
+
}
|
|
57
|
+
if (!process.stdout.isTTY) return 'non-interactive';
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function getHasInternetAccess() {
|
|
62
|
+
try {
|
|
63
|
+
const abort = new AbortController(),
|
|
64
|
+
timer = setTimeout(() => abort.abort(), 1000);
|
|
65
|
+
return (
|
|
66
|
+
await fetch('http://1.1.1.1', {
|
|
67
|
+
method: 'HEAD',
|
|
68
|
+
signal: abort.signal,
|
|
69
|
+
}),
|
|
70
|
+
clearTimeout(timer),
|
|
71
|
+
true
|
|
72
|
+
);
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function getEnv() {
|
|
79
|
+
return {
|
|
80
|
+
hasInternetAccess: await getHasInternetAccess(),
|
|
81
|
+
platform:
|
|
82
|
+
process.platform === 'win32'
|
|
83
|
+
? 'windows'
|
|
84
|
+
: process.platform === 'darwin'
|
|
85
|
+
? 'macos'
|
|
86
|
+
: 'linux',
|
|
87
|
+
nodeVersion: process.version,
|
|
88
|
+
terminal: getTerminal(),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { TOOL_NAMES } from '../core/constants';
|
|
2
|
+
|
|
3
|
+
export function getErrorMessage(error: unknown): string {
|
|
4
|
+
if (error instanceof Error) {
|
|
5
|
+
return error.message;
|
|
6
|
+
}
|
|
7
|
+
try {
|
|
8
|
+
return String(error);
|
|
9
|
+
} catch {
|
|
10
|
+
return 'Failed to get error details';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class MaxFileReadLengthExceededError extends Error {
|
|
15
|
+
public readonly maxFileLength: number;
|
|
16
|
+
public readonly fileLength: number;
|
|
17
|
+
constructor(fileLength: number, maxFileLength: number) {
|
|
18
|
+
super(
|
|
19
|
+
`File content (${fileLength} characters) exceeds maximum allowed length (${maxFileLength} characters). Please use offset and limit parameters to read specific portions of the file, or use the ${TOOL_NAMES.GREP} tool to search for specific content.`,
|
|
20
|
+
);
|
|
21
|
+
this.name = 'MaxFileReadLengthExceededError';
|
|
22
|
+
this.maxFileLength = maxFileLength;
|
|
23
|
+
this.fileLength = fileLength;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class MaxFileReadTokenExceededError extends Error {
|
|
28
|
+
public readonly maxTokens: number;
|
|
29
|
+
public readonly tokenCount: number;
|
|
30
|
+
constructor(tokenCount: number, maxTokens: number) {
|
|
31
|
+
super(
|
|
32
|
+
`File content (${tokenCount} tokens) exceeds maximum allowed tokens (${maxTokens}). Please use offset and limit parameters to read specific portions of the file, or use the ${TOOL_NAMES.GREP} tool to search for specific content.`,
|
|
33
|
+
);
|
|
34
|
+
this.name = 'MaxFileReadTokenExceededError';
|
|
35
|
+
this.maxTokens = maxTokens;
|
|
36
|
+
this.tokenCount = tokenCount;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { execFile } from 'child_process';
|
|
2
|
+
|
|
3
|
+
const MS_IN_SECOND = 1000;
|
|
4
|
+
const SECONDS_IN_MINUTE = 60;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* execFile, but always resolves (never throws)
|
|
8
|
+
*/
|
|
9
|
+
export function execFileNoThrow(
|
|
10
|
+
cwd: string,
|
|
11
|
+
file: string,
|
|
12
|
+
args: string[],
|
|
13
|
+
abortSignal?: AbortSignal,
|
|
14
|
+
timeout = 10 * SECONDS_IN_MINUTE * MS_IN_SECOND,
|
|
15
|
+
preserveOutputOnError = true,
|
|
16
|
+
): Promise<{ stdout: string; stderr: string; code: number }> {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
try {
|
|
19
|
+
execFile(
|
|
20
|
+
file,
|
|
21
|
+
args,
|
|
22
|
+
{
|
|
23
|
+
maxBuffer: 1_000_000,
|
|
24
|
+
signal: abortSignal,
|
|
25
|
+
timeout,
|
|
26
|
+
cwd,
|
|
27
|
+
},
|
|
28
|
+
(error, stdout, stderr) => {
|
|
29
|
+
if (error) {
|
|
30
|
+
if (preserveOutputOnError) {
|
|
31
|
+
const errorCode = typeof error.code === 'number' ? error.code : 1;
|
|
32
|
+
resolve({
|
|
33
|
+
stdout: stdout || '',
|
|
34
|
+
stderr: stderr || '',
|
|
35
|
+
code: errorCode,
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
resolve({ stdout: '', stderr: '', code: 1 });
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
resolve({ stdout, stderr, code: 0 });
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
resolve({ stdout: '', stderr: '', code: 1 });
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import path from 'pathe';
|
|
2
|
+
import { execFileNoThrow } from './execFileNoThrow';
|
|
3
|
+
import { listDirectory } from './list';
|
|
4
|
+
|
|
5
|
+
export interface FileItem {
|
|
6
|
+
path: string;
|
|
7
|
+
type: 'file' | 'directory';
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function getGitStatusItems(cwd: string, query?: string) {
|
|
12
|
+
const gitStatus = await (async () => {
|
|
13
|
+
// won't throw error
|
|
14
|
+
const { stdout } = await execFileNoThrow(
|
|
15
|
+
cwd,
|
|
16
|
+
'git',
|
|
17
|
+
['status', '--short'],
|
|
18
|
+
undefined,
|
|
19
|
+
undefined,
|
|
20
|
+
false,
|
|
21
|
+
);
|
|
22
|
+
// DO NOT USE TRIM HERE, it will make the result inconsistent
|
|
23
|
+
return stdout;
|
|
24
|
+
})();
|
|
25
|
+
|
|
26
|
+
const files = gitStatus
|
|
27
|
+
.split('\n')
|
|
28
|
+
.filter((line) => line.trim().length > 0)
|
|
29
|
+
.filter(
|
|
30
|
+
(line) =>
|
|
31
|
+
!line.startsWith('D') &&
|
|
32
|
+
!line.startsWith('??') &&
|
|
33
|
+
!line.startsWith('R'),
|
|
34
|
+
)
|
|
35
|
+
.map((line) => line.slice(3))
|
|
36
|
+
.filter(
|
|
37
|
+
(path) => !query || path.toLowerCase().includes(query.toLowerCase()),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return Promise.all(
|
|
41
|
+
files.map(async (file) => {
|
|
42
|
+
const relativePath = path.join(cwd, file);
|
|
43
|
+
const name = path.basename(file);
|
|
44
|
+
const item = await createFileItem(relativePath, name, 'file');
|
|
45
|
+
return item;
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function getFiles(opts: {
|
|
51
|
+
cwd: string;
|
|
52
|
+
maxSize: number;
|
|
53
|
+
query: string;
|
|
54
|
+
}) {
|
|
55
|
+
const { cwd, query, maxSize } = opts;
|
|
56
|
+
let items = await getGitStatusItems(cwd, query);
|
|
57
|
+
if (items.length < maxSize) {
|
|
58
|
+
const remainingSize = maxSize - items.length;
|
|
59
|
+
const result = listDirectory(cwd, cwd, 6000).filter(
|
|
60
|
+
(item) => !query || item.toLowerCase().includes(query.toLowerCase()),
|
|
61
|
+
);
|
|
62
|
+
const remainingItems = result
|
|
63
|
+
.slice(0, remainingSize)
|
|
64
|
+
.map((item) => {
|
|
65
|
+
const isDir = item.endsWith(path.sep);
|
|
66
|
+
const name = path.basename(item) + (isDir ? path.sep : '');
|
|
67
|
+
const type: 'file' | 'directory' = isDir ? 'directory' : 'file';
|
|
68
|
+
return createFileItem(item, name, type);
|
|
69
|
+
})
|
|
70
|
+
.sort((a, b) => {
|
|
71
|
+
if (a.type !== b.type) {
|
|
72
|
+
return a.type === 'directory' ? -1 : 1;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return a.path.localeCompare(b.path);
|
|
76
|
+
});
|
|
77
|
+
items = [...items, ...remainingItems];
|
|
78
|
+
}
|
|
79
|
+
return items;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function createFileItem(
|
|
83
|
+
relativePath: string,
|
|
84
|
+
name: string,
|
|
85
|
+
type: 'file' | 'directory',
|
|
86
|
+
): FileItem {
|
|
87
|
+
const fileItem: FileItem = {
|
|
88
|
+
path: relativePath,
|
|
89
|
+
type,
|
|
90
|
+
name,
|
|
91
|
+
};
|
|
92
|
+
return fileItem;
|
|
93
|
+
}
|