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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2025 AI Code Engine
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,199 @@
1
+ <div align="center">
2
+
3
+ # OriCore
4
+
5
+ **A powerful, standalone AI coding engine with multi-model support, tool calling, and extensible architecture**
6
+
7
+ [![npm version](https://badge.fury.io/js/oricore.svg)](https://www.npmjs.com/package/oricore)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ </div>
11
+
12
+ ## Features
13
+
14
+ - 🤖 **Multi-Model Support**: OpenAI, Anthropic, Google, DeepSeek, and 40+ providers
15
+ - 🛠️ **Rich Tool System**: read, write, edit, grep, glob, fetch, and more
16
+ - 🧠 **Interaction Modes**: brainstorm, plan, review, debug, and default modes
17
+ - 🔌 **MCP Integration**: Extensible via Model Context Protocol
18
+ - 🎯 **Agent System**: Built-in agents for complex tasks
19
+ - 💬 **Interactive**: Q&A tool for user interaction
20
+ - 📦 **Zero Configuration**: Works out of the box with sensible defaults
21
+ - 🔧 **Fully Typed**: Complete TypeScript support
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install oricore
27
+ ```
28
+
29
+ ```bash
30
+ # Using pnpm
31
+ pnpm add oricore
32
+
33
+ # Using bun
34
+ bun add oricore
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ ```typescript
40
+ import { createEngine } from 'oricore';
41
+
42
+ const engine = createEngine({
43
+ productName: 'MyApp',
44
+ version: '1.0.0',
45
+ });
46
+
47
+ await engine.initialize({
48
+ model: 'openai/gpt-4o',
49
+ });
50
+
51
+ const result = await engine.sendMessage({
52
+ message: 'Create a TypeScript function to calculate fibonacci',
53
+ write: true,
54
+ });
55
+
56
+ console.log(result.data.text);
57
+ ```
58
+
59
+ ## Usage
60
+
61
+ ### Basic Chat
62
+
63
+ ```typescript
64
+ const answer = await engine.ask('What is TypeScript?');
65
+ ```
66
+
67
+ ### Multi-Turn Conversation
68
+
69
+ ```typescript
70
+ const result = await engine.sendMessage({
71
+ message: 'Create a user class',
72
+ write: true,
73
+ maxTurns: 50,
74
+ });
75
+ ```
76
+
77
+ ### Brainstorming Mode
78
+
79
+ ```typescript
80
+ engine.setMode('brainstorm');
81
+
82
+ const result = await engine.sendMessageWithMode(
83
+ 'I want to build a task management app',
84
+ {
85
+ onToolApprove: async (toolUse) => {
86
+ if (toolUse.name === 'askUserQuestion') {
87
+ const questions = toolUse.params.questions;
88
+ // Collect user answers
89
+ const answers = await collectAnswers(questions);
90
+ return {
91
+ approved: true,
92
+ params: { ...toolUse.params, answers },
93
+ };
94
+ }
95
+ return { approved: true };
96
+ },
97
+ }
98
+ );
99
+ ```
100
+
101
+ ### Custom Mode
102
+
103
+ ```typescript
104
+ engine.registerMode({
105
+ id: 'code-reviewer',
106
+ name: 'Code Reviewer',
107
+ config: {
108
+ systemPrompt: 'You are a code reviewer...',
109
+ write: false,
110
+ askUserQuestion: false,
111
+ },
112
+ });
113
+
114
+ engine.setMode('code-reviewer');
115
+ ```
116
+
117
+ ## Configuration
118
+
119
+ ### Environment Variables
120
+
121
+ ```bash
122
+ # OpenAI
123
+ export OPENAI_API_KEY=sk-...
124
+ export OPENAI_API_BASE=https://api.openai.com/v1
125
+
126
+ # Anthropic
127
+ export ANTHROPIC_API_KEY=sk-ant-...
128
+
129
+ # Google
130
+ export GOOGLE_API_KEY=...
131
+
132
+ # DeepSeek
133
+ export DEEPSEEK_API_KEY=...
134
+ ```
135
+
136
+ ### Initialize with Config
137
+
138
+ ```typescript
139
+ await engine.initialize({
140
+ model: 'openai/gpt-4o',
141
+ provider: {
142
+ openai: {
143
+ apiKey: 'sk-...',
144
+ baseURL: 'https://api.openai.com/v1'
145
+ }
146
+ }
147
+ });
148
+ ```
149
+
150
+ ## API
151
+
152
+ ### Engine Class
153
+
154
+ ```typescript
155
+ class Engine {
156
+ constructor(options: EngineOptions)
157
+ async initialize(config: EngineConfig): Promise<void>
158
+ async sendMessage(options: SendMessageOptions): Promise<LoopResult>
159
+ async ask(message: string): Promise<string>
160
+ async createSession(options?: SessionOptions): Promise<Session>
161
+ setMode(mode: ModeType): void
162
+ sendMessageWithMode(message: string, options?: Partial<SendMessageOptions>): Promise<LoopResult>
163
+ getContext(): Context
164
+ getMessageBus(): MessageBus
165
+ async shutdown(): Promise<void>
166
+ }
167
+ ```
168
+
169
+ ### Modes
170
+
171
+ - `default` - General purpose coding assistant
172
+ - `brainstorm` - Interactive design and ideation
173
+ - `plan` - Create implementation plans
174
+ - `review` - Code review and analysis
175
+ - `debug` - Troubleshooting and debugging
176
+
177
+ ## Examples
178
+
179
+ See the `examples/` directory for more examples:
180
+
181
+ - `basic.ts` - Basic usage
182
+ - `modes.ts` - Using different modes
183
+ - `streaming.ts` - Streaming responses
184
+
185
+ ## Documentation
186
+
187
+ For more detailed documentation, please visit the [USAGE.md](./USAGE.md) file.
188
+
189
+ ## License
190
+
191
+ MIT © [lyw405](https://github.com/lyw405)
192
+
193
+ ## Contributing
194
+
195
+ Contributions are welcome! Please feel free to submit a Pull Request.
196
+
197
+ ## Support
198
+
199
+ If you have any questions or issues, please [open an issue](https://github.com/lyw405/oricore/issues) on GitHub.
@@ -0,0 +1,38 @@
1
+ import type { Context } from '../../core/context';
2
+ import type { NormalizedMessage } from '../../core/message';
3
+ import type { ApprovalCategory, Tool, ToolApprovalResult, ToolUse } from '../../tools/tool';
4
+ import type { AgentDefinition, AgentExecutionResult, AgentLoadError, TaskToolInput } from './types';
5
+ export declare class AgentManager {
6
+ private agents;
7
+ private context;
8
+ private errors;
9
+ constructor(opts: {
10
+ context: Context;
11
+ });
12
+ private registerBuiltinAgents;
13
+ registerAgent(definition: AgentDefinition): void;
14
+ isAgentEnabled(agent: AgentDefinition): boolean;
15
+ getAgent(agentType: string): AgentDefinition | undefined;
16
+ getAllAgents(): AgentDefinition[];
17
+ getAgentTypes(): string[];
18
+ executeTask(input: TaskToolInput, context: {
19
+ tools: Tool[];
20
+ cwd: string;
21
+ signal?: AbortSignal;
22
+ parentSessionId?: string;
23
+ forkContextMessages?: NormalizedMessage[];
24
+ onMessage?: (message: NormalizedMessage, agentId: string, model: string) => void | Promise<void>;
25
+ onToolApprove?: (opts: {
26
+ toolUse: ToolUse;
27
+ category?: ApprovalCategory;
28
+ }) => Promise<boolean | ToolApprovalResult>;
29
+ }): Promise<AgentExecutionResult>;
30
+ getAgentDescriptions(): string;
31
+ loadAgents(): Promise<void>;
32
+ private loadAgentsFromPlugins;
33
+ getErrors(): AgentLoadError[];
34
+ private loadAgentsFromDirectory;
35
+ private loadAgentFile;
36
+ private convertToolNames;
37
+ private parseAgentFile;
38
+ }
@@ -0,0 +1,5 @@
1
+ export declare const TASK_TOOL_NAME = "task";
2
+ export declare const EDIT_TOOLS: string[];
3
+ export declare function buildDisallowedTools(...toolGroups: string[][]): string[];
4
+ export declare const CONTEXT_NOTES: string;
5
+ export declare const THOROUGHNESS_LEVELS: string;
@@ -0,0 +1,5 @@
1
+ import type { Context } from '../../../core/context';
2
+ import { type AgentDefinition } from '../types';
3
+ export declare function createExploreAgent(opts: {
4
+ context: Context;
5
+ }): AgentDefinition;
@@ -0,0 +1,5 @@
1
+ import type { Context } from '../../../core/context';
2
+ import { type AgentDefinition } from '../types';
3
+ export declare function createGeneralPurposeAgent(opts: {
4
+ context: Context;
5
+ }): AgentDefinition;
@@ -0,0 +1,5 @@
1
+ import type { Context } from '../../../core/context';
2
+ import type { AgentDefinition } from '../types';
3
+ export declare function getBuiltinAgents(opts: {
4
+ context: Context;
5
+ }): AgentDefinition[];
@@ -0,0 +1,2 @@
1
+ import type { AgentExecuteOptions, AgentExecutionResult } from './types';
2
+ export declare function executeAgent(options: AgentExecuteOptions): Promise<AgentExecutionResult>;
@@ -0,0 +1,98 @@
1
+ import type { Context } from '../../core/context';
2
+ import type { NormalizedMessage } from '../../core/message';
3
+ import type { ApprovalCategory, Tool, ToolApprovalResult, ToolUse } from '../../tools/tool';
4
+ export interface AgentDefinition {
5
+ agentType: string;
6
+ whenToUse: string;
7
+ systemPrompt: string;
8
+ model: string;
9
+ source: AgentSource;
10
+ tools?: string[];
11
+ disallowedTools?: string[];
12
+ forkContext?: boolean;
13
+ color?: string;
14
+ path?: string;
15
+ /**
16
+ * Controls whether the agent is available for use.
17
+ * - boolean: Static toggle (default: true)
18
+ * - function: Dynamic check based on context
19
+ */
20
+ isEnabled?: boolean | ((context: Context) => boolean);
21
+ }
22
+ export type PluginAgentDefinition = Omit<AgentDefinition, 'source' | 'model'> & {
23
+ model?: string;
24
+ };
25
+ export interface TaskToolInput {
26
+ description: string;
27
+ prompt: string;
28
+ subagent_type: string;
29
+ model?: string;
30
+ resume?: string;
31
+ }
32
+ export interface AgentExecutionResult {
33
+ status: 'completed' | 'failed';
34
+ agentId: string;
35
+ content: string;
36
+ totalToolCalls: number;
37
+ totalDuration: number;
38
+ model?: string;
39
+ usage: {
40
+ inputTokens: number;
41
+ outputTokens: number;
42
+ };
43
+ }
44
+ export interface AgentExecuteOptions {
45
+ definition: AgentDefinition;
46
+ prompt: string;
47
+ tools: Tool[];
48
+ context: Context;
49
+ model?: string;
50
+ forkContextMessages?: NormalizedMessage[];
51
+ cwd: string;
52
+ signal?: AbortSignal;
53
+ resume?: string;
54
+ parentSessionId?: string;
55
+ onMessage?: (message: NormalizedMessage, agentId: string, model: string) => void | Promise<void>;
56
+ onToolApprove?: (opts: {
57
+ toolUse: ToolUse;
58
+ category?: ApprovalCategory;
59
+ }) => Promise<boolean | ToolApprovalResult>;
60
+ }
61
+ /**
62
+ * Real-time progress data for SubAgent execution
63
+ * Used to track and display SubAgent progress in the UI
64
+ */
65
+ export interface AgentProgressData {
66
+ /** The tool use ID that triggered this SubAgent (e.g., "task-1") */
67
+ toolUseID: string;
68
+ /** Unique identifier for the SubAgent instance */
69
+ agentId: string;
70
+ /** The latest message produced by the SubAgent */
71
+ message: NormalizedMessage;
72
+ /** Timestamp when this progress update was created */
73
+ timestamp: number;
74
+ }
75
+ /**
76
+ * Event payload for agent.progress events sent through MessageBus
77
+ */
78
+ export interface AgentProgressEvent {
79
+ /** Session ID of the parent agent */
80
+ sessionId: string;
81
+ /** Current working directory */
82
+ cwd: string;
83
+ /** Progress data payload */
84
+ progressData: AgentProgressData;
85
+ }
86
+ export declare enum AgentSource {
87
+ BuiltIn = "built-in",
88
+ Plugin = "plugin",
89
+ User = "user",
90
+ ProjectClaude = "project-claude",
91
+ Project = "project",
92
+ GlobalClaude = "global-claude",
93
+ Global = "global"
94
+ }
95
+ export interface AgentLoadError {
96
+ path: string;
97
+ message: string;
98
+ }
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Engine API
3
+ *
4
+ * Main entry point for the OriCore package.
5
+ * Provides a high-level API for AI-powered coding assistance.
6
+ */
7
+ import type { Context } from '../core/context';
8
+ import type { ProviderConfig } from '../core/config';
9
+ import { MessageBus } from '../communication/messageBus';
10
+ import type { PlatformAdapter } from '../platform';
11
+ import type { Session } from '../session/session';
12
+ import { type LoopResult } from '../core/loop';
13
+ import type { NormalizedMessage } from '../core/message';
14
+ import type { ToolUse, ToolResult, ToolApprovalResult } from '../tools/tool';
15
+ import { type Mode, type ModeType } from '../modes';
16
+ /**
17
+ * Engine initialization options
18
+ */
19
+ export interface EngineOptions {
20
+ /** Product name (e.g., "AI Engine") */
21
+ productName: string;
22
+ /** ASCII art banner for display */
23
+ productASCIIArt?: string;
24
+ /** Version string */
25
+ version: string;
26
+ /** Current working directory */
27
+ cwd?: string;
28
+ /** Fetch implementation (optional, uses globalThis.fetch by default) */
29
+ fetch?: typeof globalThis.fetch;
30
+ /** Platform implementation (defaults to Node.js) */
31
+ platform?: PlatformAdapter;
32
+ /** Message bus for event communication */
33
+ messageBus?: MessageBus;
34
+ }
35
+ /**
36
+ * Engine configuration
37
+ */
38
+ export interface EngineConfig {
39
+ /** Model to use for AI responses */
40
+ model?: string;
41
+ /** Model for planning mode */
42
+ planModel?: string;
43
+ /** Approval mode for tool usage */
44
+ approvalMode?: 'default' | 'autoEdit' | 'yolo';
45
+ /** System prompt override */
46
+ systemPrompt?: string;
47
+ /** Additional system prompt */
48
+ appendSystemPrompt?: string;
49
+ /** Language for responses */
50
+ language?: string;
51
+ /** MCP servers configuration */
52
+ mcpServers?: Record<string, any>;
53
+ /** Tools configuration */
54
+ tools?: Record<string, boolean>;
55
+ /** Plugins to load */
56
+ plugins?: (string | any)[];
57
+ /** Provider configuration (custom API endpoints, keys, etc.) */
58
+ provider?: Record<string, ProviderConfig>;
59
+ }
60
+ /**
61
+ * Session creation options
62
+ */
63
+ export interface SessionOptions {
64
+ /** Session ID (auto-generated if not provided) */
65
+ sessionId?: string;
66
+ /** Resume from existing session */
67
+ resume?: string;
68
+ /** Continue from latest session */
69
+ continue?: boolean;
70
+ }
71
+ /**
72
+ * Message sending options
73
+ */
74
+ export interface SendMessageOptions {
75
+ /** Message content (string or message array) */
76
+ message: string | NormalizedMessage[];
77
+ /** Enable write tools (default: true) */
78
+ write?: boolean;
79
+ /** Enable todo tools (default: true) */
80
+ todo?: boolean;
81
+ /** Enable ask user question tool (default: false) */
82
+ askUserQuestion?: boolean;
83
+ /** Enable task/agent tool (default: false) */
84
+ task?: boolean;
85
+ /** Override model for this message */
86
+ model?: string;
87
+ /** Maximum turns (default: 50) */
88
+ maxTurns?: number;
89
+ /** Abort signal for cancellation */
90
+ signal?: AbortSignal;
91
+ /** Callback for text delta (streaming) */
92
+ onTextDelta?: (text: string) => Promise<void>;
93
+ /** Callback for complete text */
94
+ onText?: (text: string) => Promise<void>;
95
+ /** Callback for reasoning */
96
+ onReasoning?: (text: string) => Promise<void>;
97
+ /** Callback for tool use */
98
+ onToolUse?: (toolUse: ToolUse) => Promise<ToolUse>;
99
+ /** Callback for tool result */
100
+ onToolResult?: (toolUse: ToolUse, toolResult: ToolResult, approved: boolean) => Promise<ToolResult>;
101
+ /** Callback for tool approval (return false to deny) */
102
+ onToolApprove?: (toolUse: ToolUse) => Promise<ToolApprovalResult>;
103
+ /** Callback for turn completion */
104
+ onTurn?: (turn: any) => Promise<void>;
105
+ }
106
+ /**
107
+ * Main Engine class
108
+ *
109
+ * The Engine is the primary interface for interacting with the AI coding assistant.
110
+ * It manages initialization, configuration, and provides access to context.
111
+ */
112
+ export declare class Engine {
113
+ private context;
114
+ private platform;
115
+ private messageBus;
116
+ private options;
117
+ private initialized;
118
+ private currentMode;
119
+ constructor(options: EngineOptions);
120
+ /**
121
+ * Initialize the engine with configuration
122
+ */
123
+ initialize(config?: EngineConfig): Promise<void>;
124
+ /**
125
+ * Create or resume a session
126
+ */
127
+ createSession(options?: SessionOptions): Promise<Session>;
128
+ /**
129
+ * Get the MessageBus for event communication
130
+ */
131
+ getMessageBus(): MessageBus;
132
+ /**
133
+ * Get the current context
134
+ */
135
+ getContext(): Context;
136
+ /**
137
+ * Shutdown the engine and cleanup resources
138
+ */
139
+ shutdown(): Promise<void>;
140
+ /**
141
+ * Send a message to the AI and get a response
142
+ *
143
+ * This is the main method for interacting with the AI engine.
144
+ * It handles the full conversation loop including tool execution.
145
+ *
146
+ * @param options - Message sending options
147
+ * @returns Promise<LoopResult> - The result of the conversation loop
148
+ */
149
+ sendMessage(options: SendMessageOptions): Promise<LoopResult>;
150
+ /**
151
+ * Create a simple request-response interaction (single turn)
152
+ *
153
+ * This is a simplified version of sendMessage that returns just the text response.
154
+ * Tools are disabled by default for simple requests.
155
+ *
156
+ * @param message - The message to send
157
+ * @param options - Optional configuration
158
+ * @returns Promise<string> - The AI's text response
159
+ */
160
+ ask(message: string, options?: {
161
+ model?: string;
162
+ systemPrompt?: string;
163
+ }): Promise<string>;
164
+ /**
165
+ * Set the current interaction mode
166
+ *
167
+ * @param mode - The mode to set (e.g., 'brainstorm', 'plan', 'review')
168
+ */
169
+ setMode(mode: ModeType): void;
170
+ /**
171
+ * Get the current mode
172
+ */
173
+ getMode(): ModeType;
174
+ /**
175
+ * Get all available modes
176
+ */
177
+ getAvailableModes(): Mode[];
178
+ /**
179
+ * Register a custom mode
180
+ *
181
+ * @param mode - The mode to register
182
+ */
183
+ registerMode(mode: Mode): void;
184
+ /**
185
+ * Send a message using the current mode
186
+ *
187
+ * This is a convenience method that applies the current mode's configuration
188
+ *
189
+ * @param message - The message to send
190
+ * @param options - Optional overrides for this specific message
191
+ * @returns Promise<LoopResult> - The result of the conversation loop
192
+ */
193
+ sendMessageWithMode(message: string | NormalizedMessage[], options?: Partial<Omit<SendMessageOptions, 'message' | 'systemPrompt'>> & {
194
+ systemPrompt?: string;
195
+ }): Promise<LoopResult>;
196
+ /**
197
+ * Internal method to send message with custom system prompt
198
+ */
199
+ private _sendMessageWithSystemPrompt;
200
+ /**
201
+ * Generate a unique session ID
202
+ */
203
+ private generateSessionId;
204
+ }
205
+ /**
206
+ * Create a new Engine instance
207
+ */
208
+ export declare function createEngine(options: EngineOptions): Engine;
209
+ export type { Config, ApprovalMode } from '../core/config';
210
+ export type { Session, SessionId } from '../session/session';
211
+ export type { Tool, ToolUse, ToolResult } from '../tools/tool';
212
+ export type { Message, NormalizedMessage, UserMessage, AssistantMessage } from '../core/message';
213
+ export type { Plugin, PluginHookType } from '../core/plugin';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Communication layer exports
3
+ */
4
+ export { MessageBus, DirectTransport, type MessageId, type BaseMessage, type RequestMessage, type ResponseMessage, type EventMessage, type Message, type ConnectionState, type MessageTransport, type MessageHandler, type EventHandler, } from './messageBus';
@@ -0,0 +1,71 @@
1
+ import EventEmitter from 'events';
2
+ export type MessageId = string;
3
+ export type BaseMessage = {
4
+ id: MessageId;
5
+ timestamp: number;
6
+ };
7
+ export type RequestMessage = BaseMessage & {
8
+ type: 'request';
9
+ method: string;
10
+ params: any;
11
+ };
12
+ export type ResponseMessage = BaseMessage & {
13
+ type: 'response';
14
+ result?: any;
15
+ error?: any;
16
+ };
17
+ export type EventMessage = BaseMessage & {
18
+ type: 'event';
19
+ event: string;
20
+ data: any;
21
+ };
22
+ export type Message = RequestMessage | ResponseMessage | EventMessage;
23
+ export type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'error' | 'closed';
24
+ export interface MessageTransport {
25
+ send: (message: Message) => Promise<void>;
26
+ onMessage: (handler: (message: Message) => void) => void;
27
+ onError: (handler: (error: Error) => void) => void;
28
+ onClose: (handler: () => void) => void;
29
+ close: () => Promise<void>;
30
+ isConnected: () => boolean;
31
+ }
32
+ export declare class DirectTransport extends EventEmitter implements MessageTransport {
33
+ private peer?;
34
+ private state;
35
+ private messageBuffer;
36
+ constructor();
37
+ static createPair(): [DirectTransport, DirectTransport];
38
+ setPeer(peer: DirectTransport): void;
39
+ isConnected(): boolean;
40
+ onMessage(handler: (message: Message) => void): void;
41
+ onError(handler: (error: Error) => void): void;
42
+ onClose(handler: () => void): void;
43
+ send(message: Message): Promise<void>;
44
+ close(): Promise<void>;
45
+ private flushBuffer;
46
+ private receive;
47
+ }
48
+ export type MessageHandler = (data: any) => Promise<any>;
49
+ export type EventHandler = (data: any) => void;
50
+ export declare class MessageBus extends EventEmitter {
51
+ messageHandlers: Map<string, MessageHandler>;
52
+ private transport?;
53
+ private pendingRequests;
54
+ private eventHandlers;
55
+ constructor();
56
+ setTransport(transport: MessageTransport): void;
57
+ isConnected(): boolean;
58
+ request(method: string, params: any, options?: {
59
+ timeout?: number;
60
+ }): Promise<any>;
61
+ registerHandler(method: string, handler: MessageHandler): void;
62
+ unregisterHandler(method: string): void;
63
+ emitEvent(event: string, data: any): Promise<void>;
64
+ onEvent(event: string, handler: EventHandler): void;
65
+ offEvent(event: string, handler: EventHandler): void;
66
+ private handleIncomingMessage;
67
+ private handleRequest;
68
+ private handleResponse;
69
+ private handleEvent;
70
+ private sendResponse;
71
+ }