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.
Files changed (221) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +199 -0
  3. package/dist/agent/agent/agentManager.d.ts +38 -0
  4. package/dist/agent/agent/builtin/common.d.ts +5 -0
  5. package/dist/agent/agent/builtin/explore.d.ts +5 -0
  6. package/dist/agent/agent/builtin/general-purpose.d.ts +5 -0
  7. package/dist/agent/agent/builtin/index.d.ts +5 -0
  8. package/dist/agent/agent/executor.d.ts +2 -0
  9. package/dist/agent/agent/types.d.ts +98 -0
  10. package/dist/api/engine.d.ts +213 -0
  11. package/dist/communication/index.d.ts +4 -0
  12. package/dist/communication/messageBus.d.ts +71 -0
  13. package/dist/core/at.d.ts +26 -0
  14. package/dist/core/backgroundTaskManager.d.ts +27 -0
  15. package/dist/core/compact.d.ts +9 -0
  16. package/dist/core/config.d.ts +103 -0
  17. package/dist/core/constants.d.ts +32 -0
  18. package/dist/core/context.d.ts +57 -0
  19. package/dist/core/globalData.d.ts +21 -0
  20. package/dist/core/history.d.ts +24 -0
  21. package/dist/core/ide.d.ts +103 -0
  22. package/dist/core/jsonl.d.ts +37 -0
  23. package/dist/core/llmsContext.d.ts +14 -0
  24. package/dist/core/loop.d.ts +82 -0
  25. package/dist/core/message.d.ts +132 -0
  26. package/dist/core/model.d.ts +79 -0
  27. package/dist/core/output-style/builtin/default.d.ts +2 -0
  28. package/dist/core/output-style/builtin/explanatory.d.ts +2 -0
  29. package/dist/core/output-style/builtin/index.d.ts +6 -0
  30. package/dist/core/output-style/builtin/miao.d.ts +2 -0
  31. package/dist/core/output-style/builtin/minimal.d.ts +2 -0
  32. package/dist/core/output-style/types.d.ts +6 -0
  33. package/dist/core/outputFormat.d.ts +29 -0
  34. package/dist/core/outputStyle.d.ts +43 -0
  35. package/dist/core/paths.d.ts +20 -0
  36. package/dist/core/planSystemPrompt.d.ts +5 -0
  37. package/dist/core/plugin.d.ts +138 -0
  38. package/dist/core/project.d.ts +64 -0
  39. package/dist/core/promptCache.d.ts +3 -0
  40. package/dist/core/query.d.ts +14 -0
  41. package/dist/core/rules.d.ts +8 -0
  42. package/dist/core/systemPrompt.d.ts +9 -0
  43. package/dist/core/thinking-config.d.ts +3 -0
  44. package/dist/core/usage.d.ts +14 -0
  45. package/dist/index.d.ts +16 -0
  46. package/dist/index.js +144432 -0
  47. package/dist/mcp/mcp.d.ts +49 -0
  48. package/dist/modes/builtin.d.ts +34 -0
  49. package/dist/modes/index.d.ts +8 -0
  50. package/dist/modes/registry.d.ts +18 -0
  51. package/dist/modes/types.d.ts +51 -0
  52. package/dist/platform/index.d.ts +5 -0
  53. package/dist/platform/node.d.ts +28 -0
  54. package/dist/platform/types.d.ts +41 -0
  55. package/dist/session/session.d.ts +43 -0
  56. package/dist/skill/skill.d.ts +79 -0
  57. package/dist/tools/tool.d.ts +119 -0
  58. package/dist/tools/tools/askUserQuestion.d.ts +48 -0
  59. package/dist/tools/tools/bash.d.ts +43 -0
  60. package/dist/tools/tools/edit.d.ts +9 -0
  61. package/dist/tools/tools/fetch.d.ts +9 -0
  62. package/dist/tools/tools/glob.d.ts +7 -0
  63. package/dist/tools/tools/grep.d.ts +22 -0
  64. package/dist/tools/tools/ls.d.ts +6 -0
  65. package/dist/tools/tools/read.d.ts +9 -0
  66. package/dist/tools/tools/skill.d.ts +7 -0
  67. package/dist/tools/tools/task.d.ts +14 -0
  68. package/dist/tools/tools/todo.d.ts +37 -0
  69. package/dist/tools/tools/write.d.ts +7 -0
  70. package/dist/utils/apiKeyRotation.d.ts +2 -0
  71. package/dist/utils/applyEdit.d.ts +17 -0
  72. package/dist/utils/background-detection.d.ts +2 -0
  73. package/dist/utils/dotenv.d.ts +9 -0
  74. package/dist/utils/env.d.ts +6 -0
  75. package/dist/utils/error.d.ts +11 -0
  76. package/dist/utils/execFileNoThrow.d.ts +8 -0
  77. package/dist/utils/files.d.ts +10 -0
  78. package/dist/utils/git.d.ts +163 -0
  79. package/dist/utils/ide.d.ts +27 -0
  80. package/dist/utils/ignore.d.ts +6 -0
  81. package/dist/utils/isLocal.d.ts +1 -0
  82. package/dist/utils/language.d.ts +9 -0
  83. package/dist/utils/list.d.ts +20 -0
  84. package/dist/utils/mergeSystemMessagesMiddleware.d.ts +2 -0
  85. package/dist/utils/messageNormalization.d.ts +22 -0
  86. package/dist/utils/path.d.ts +34 -0
  87. package/dist/utils/prependSystemMessageMiddleware.d.ts +2 -0
  88. package/dist/utils/project.d.ts +1 -0
  89. package/dist/utils/proxy.d.ts +18 -0
  90. package/dist/utils/randomUUID.d.ts +5 -0
  91. package/dist/utils/renderSessionMarkdown.d.ts +10 -0
  92. package/dist/utils/ripgrep.d.ts +16 -0
  93. package/dist/utils/safeFrontMatter.d.ts +11 -0
  94. package/dist/utils/safeParseJson.d.ts +1 -0
  95. package/dist/utils/safeStringify.d.ts +1 -0
  96. package/dist/utils/sanitizeAIResponse.d.ts +30 -0
  97. package/dist/utils/setTerminalTitle.d.ts +1 -0
  98. package/dist/utils/shell-execution.d.ts +44 -0
  99. package/dist/utils/string.d.ts +8 -0
  100. package/dist/utils/symbols.d.ts +14 -0
  101. package/dist/utils/system-encoding.d.ts +40 -0
  102. package/dist/utils/tokenCounter.d.ts +8 -0
  103. package/dist/utils/username.d.ts +1 -0
  104. package/package.json +106 -0
  105. package/src/agent/agent/agentManager.test.ts +124 -0
  106. package/src/agent/agent/agentManager.ts +372 -0
  107. package/src/agent/agent/builtin/common.ts +20 -0
  108. package/src/agent/agent/builtin/explore.ts +53 -0
  109. package/src/agent/agent/builtin/general-purpose.ts +38 -0
  110. package/src/agent/agent/builtin/index.ts +13 -0
  111. package/src/agent/agent/executor.test.ts +339 -0
  112. package/src/agent/agent/executor.ts +224 -0
  113. package/src/agent/agent/types.ts +119 -0
  114. package/src/api/engine.ts +466 -0
  115. package/src/communication/index.ts +18 -0
  116. package/src/communication/messageBus.ts +393 -0
  117. package/src/core/at.ts +315 -0
  118. package/src/core/backgroundTaskManager.ts +129 -0
  119. package/src/core/compact.ts +95 -0
  120. package/src/core/config.ts +441 -0
  121. package/src/core/constants.ts +82 -0
  122. package/src/core/context.ts +214 -0
  123. package/src/core/globalData.ts +77 -0
  124. package/src/core/history.ts +323 -0
  125. package/src/core/ide.ts +325 -0
  126. package/src/core/jsonl.ts +100 -0
  127. package/src/core/llmsContext.ts +117 -0
  128. package/src/core/loop.ts +638 -0
  129. package/src/core/message.ts +304 -0
  130. package/src/core/model.ts +2198 -0
  131. package/src/core/output-style/builtin/default.ts +9 -0
  132. package/src/core/output-style/builtin/explanatory.ts +22 -0
  133. package/src/core/output-style/builtin/index.ts +19 -0
  134. package/src/core/output-style/builtin/miao.ts +22 -0
  135. package/src/core/output-style/builtin/minimal.ts +8 -0
  136. package/src/core/output-style/types.ts +6 -0
  137. package/src/core/outputFormat.ts +93 -0
  138. package/src/core/outputStyle.ts +255 -0
  139. package/src/core/paths.ts +161 -0
  140. package/src/core/planSystemPrompt.ts +46 -0
  141. package/src/core/plugin.ts +299 -0
  142. package/src/core/project.ts +492 -0
  143. package/src/core/promptCache.ts +32 -0
  144. package/src/core/query.ts +46 -0
  145. package/src/core/rules.ts +56 -0
  146. package/src/core/systemPrompt.ts +176 -0
  147. package/src/core/thinking-config.ts +98 -0
  148. package/src/core/usage.ts +68 -0
  149. package/src/index.ts +39 -0
  150. package/src/mcp/mcp.ts +637 -0
  151. package/src/modes/builtin.ts +305 -0
  152. package/src/modes/index.ts +22 -0
  153. package/src/modes/registry.ts +39 -0
  154. package/src/modes/types.ts +56 -0
  155. package/src/platform/index.ts +6 -0
  156. package/src/platform/node.ts +108 -0
  157. package/src/platform/types.ts +54 -0
  158. package/src/plugins/index.ts +15 -0
  159. package/src/session/session.ts +187 -0
  160. package/src/skill/skill.ts +702 -0
  161. package/src/tools/tool.ts +378 -0
  162. package/src/tools/tools/askUserQuestion.ts +134 -0
  163. package/src/tools/tools/bash.test.ts +425 -0
  164. package/src/tools/tools/bash.ts +999 -0
  165. package/src/tools/tools/edit.ts +86 -0
  166. package/src/tools/tools/fetch.ts +129 -0
  167. package/src/tools/tools/glob.ts +69 -0
  168. package/src/tools/tools/grep.test.ts +194 -0
  169. package/src/tools/tools/grep.ts +358 -0
  170. package/src/tools/tools/ls.ts +51 -0
  171. package/src/tools/tools/read.test.ts +169 -0
  172. package/src/tools/tools/read.ts +284 -0
  173. package/src/tools/tools/skill.ts +73 -0
  174. package/src/tools/tools/task.test.ts +262 -0
  175. package/src/tools/tools/task.ts +284 -0
  176. package/src/tools/tools/todo.ts +269 -0
  177. package/src/tools/tools/write.ts +71 -0
  178. package/src/types.d.ts +18 -0
  179. package/src/utils/apiKeyRotation.test.ts +70 -0
  180. package/src/utils/apiKeyRotation.ts +24 -0
  181. package/src/utils/applyEdit.test.ts +388 -0
  182. package/src/utils/applyEdit.ts +547 -0
  183. package/src/utils/background-detection.test.ts +61 -0
  184. package/src/utils/background-detection.ts +58 -0
  185. package/src/utils/dotenv.ts +26 -0
  186. package/src/utils/env.ts +90 -0
  187. package/src/utils/error.ts +38 -0
  188. package/src/utils/execFileNoThrow.ts +49 -0
  189. package/src/utils/files.ts +93 -0
  190. package/src/utils/git.ts +1152 -0
  191. package/src/utils/ide.ts +279 -0
  192. package/src/utils/ignore.ts +275 -0
  193. package/src/utils/isLocal.ts +6 -0
  194. package/src/utils/language.ts +33 -0
  195. package/src/utils/list.ts +200 -0
  196. package/src/utils/mergeSystemMessagesMiddleware.ts +32 -0
  197. package/src/utils/messageNormalization.test.ts +401 -0
  198. package/src/utils/messageNormalization.ts +168 -0
  199. package/src/utils/path.ts +98 -0
  200. package/src/utils/prependSystemMessageMiddleware.ts +16 -0
  201. package/src/utils/project.ts +32 -0
  202. package/src/utils/proxy.ts +102 -0
  203. package/src/utils/randomUUID.ts +11 -0
  204. package/src/utils/renderSessionMarkdown.ts +175 -0
  205. package/src/utils/ripgrep.ts +189 -0
  206. package/src/utils/safeFrontMatter.test.ts +118 -0
  207. package/src/utils/safeFrontMatter.ts +68 -0
  208. package/src/utils/safeParseJson.ts +7 -0
  209. package/src/utils/safeStringify.ts +10 -0
  210. package/src/utils/sanitizeAIResponse.test.ts +135 -0
  211. package/src/utils/sanitizeAIResponse.ts +55 -0
  212. package/src/utils/setTerminalTitle.ts +7 -0
  213. package/src/utils/shell-execution.test.ts +237 -0
  214. package/src/utils/shell-execution.ts +279 -0
  215. package/src/utils/string.ts +13 -0
  216. package/src/utils/symbols.ts +18 -0
  217. package/src/utils/system-encoding.test.ts +164 -0
  218. package/src/utils/system-encoding.ts +296 -0
  219. package/src/utils/tokenCounter.test.ts +38 -0
  220. package/src/utils/tokenCounter.ts +19 -0
  221. package/src/utils/username.ts +21 -0
@@ -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
+ }