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
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { AGENT_TYPE, TOOL_NAMES } from './constants';
|
|
2
|
+
import type { OutputStyle } from './outputStyle';
|
|
3
|
+
|
|
4
|
+
function getTasksPrompt(opts: { todo: boolean; productName: string }) {
|
|
5
|
+
if (!opts.todo) {
|
|
6
|
+
return '';
|
|
7
|
+
}
|
|
8
|
+
const productName = opts.productName;
|
|
9
|
+
return `
|
|
10
|
+
# Task Management
|
|
11
|
+
You have access to the ${TOOL_NAMES.TODO_WRITE} tool to help you manage and plan tasks. Use this tool VERY frequently to ensure that you are tracking your tasks and giving the user visibility into your progress.
|
|
12
|
+
These tools are also EXTREMELY helpful for planning tasks, and for breaking down larger complex tasks into smaller steps. If you do not use this tool when planning, you may forget to do important tasks - and that is unacceptable.
|
|
13
|
+
|
|
14
|
+
It is critical that you mark todos as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.
|
|
15
|
+
|
|
16
|
+
Examples:
|
|
17
|
+
|
|
18
|
+
<example>
|
|
19
|
+
user: Run the build and fix any type errors
|
|
20
|
+
assistant: I'm going to use the ${TOOL_NAMES.TODO_WRITE} tool to write the following items to the todo list:
|
|
21
|
+
- Run the build
|
|
22
|
+
- Fix any type errors
|
|
23
|
+
|
|
24
|
+
I'm now going to run the build using ${TOOL_NAMES.BASH}.
|
|
25
|
+
|
|
26
|
+
Looks like I found 10 type errors. I'm going to use the ${TOOL_NAMES.TODO_WRITE} tool to write 10 items to the todo list.
|
|
27
|
+
|
|
28
|
+
marking the first todo as in_progress
|
|
29
|
+
|
|
30
|
+
Let me start working on the first item...
|
|
31
|
+
|
|
32
|
+
The first item has been fixed, let me mark the first todo as completed, and move on to the second item...
|
|
33
|
+
|
|
34
|
+
</example>
|
|
35
|
+
In the above example, the assistant completes all the tasks, including the 10 error fixes and running the build and fixing all errors.
|
|
36
|
+
|
|
37
|
+
<example>
|
|
38
|
+
user: Help me write a new feature that allows users to track their usage metrics and export them to various formats
|
|
39
|
+
|
|
40
|
+
assistant: I'll help you implement a usage metrics tracking and export feature. Let me first use the ${TOOL_NAMES.TODO_WRITE} tool to plan this task.
|
|
41
|
+
Adding the following todos to the todo list:
|
|
42
|
+
1. Research existing metrics tracking in the codebase
|
|
43
|
+
2. Design the metrics collection system
|
|
44
|
+
3. Implement core metrics tracking functionality
|
|
45
|
+
4. Create export functionality for different formats
|
|
46
|
+
|
|
47
|
+
Let me start by researching the existing codebase to understand what metrics we might already be tracking and how we can build on that.
|
|
48
|
+
|
|
49
|
+
I'm going to search for any existing metrics or telemetry code in the project.
|
|
50
|
+
|
|
51
|
+
I've found some existing telemetry code. Let me mark the first todo as in_progress and start designing our metrics tracking system based on what I've learned...
|
|
52
|
+
|
|
53
|
+
[Assistant continues implementing the feature step by step, marking todos as in_progress and completed as they go]
|
|
54
|
+
</example>
|
|
55
|
+
|
|
56
|
+
# Doing tasks
|
|
57
|
+
The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended:
|
|
58
|
+
- Use the ${TOOL_NAMES.TODO_WRITE} tool to plan the task if required
|
|
59
|
+
- Use the available search tools to understand the codebase and the user's query. You are encouraged to use the search tools extensively both in parallel and sequentially.
|
|
60
|
+
- Implement the solution using all tools available to you
|
|
61
|
+
- Verify the solution if possible with tests. NEVER assume specific test framework or test script. Check the README or search codebase to determine the testing approach.
|
|
62
|
+
- VERY IMPORTANT: When you have completed a task, you MUST run the lint and typecheck commands (eg. npm run lint, npm run typecheck, ruff, etc.) with ${TOOL_NAMES.BASH} if they were provided to you to ensure your code is correct. If you are unable to find the correct command, ask the user for the command to run and if they supply it, proactively suggest writing it to ${productName}.md so that you will know to run it next time.
|
|
63
|
+
NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive.
|
|
64
|
+
|
|
65
|
+
IMPORTANT: Always use the ${TOOL_NAMES.TODO_WRITE} tool to plan and track tasks throughout the conversation.
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function getToolUsagePolicyPrompt(task: boolean) {
|
|
70
|
+
const taskPolicy = task
|
|
71
|
+
? `
|
|
72
|
+
- When doing file search, prefer to use the ${TOOL_NAMES.TASK} tool in order to reduce context usage.
|
|
73
|
+
- You should proactively use the ${TOOL_NAMES.TASK} tool with specialized agents when the task at hand matches the agent's description.
|
|
74
|
+
- If the user specifies that they want you to run tools "in parallel", you MUST send a single message with multiple tool use content blocks. For example, if you need to launch multiple agents in parallel, send a single message with multiple ${TOOL_NAMES.TASK} tool calls.
|
|
75
|
+
- VERY IMPORTANT: When exploring the codebase to gather context or to answer a question that is not a needle query for a specific file/class/function, it is CRITICAL that you use the ${TOOL_NAMES.TASK} tool with subagent_type=${AGENT_TYPE.EXPLORE} instead of running search commands directly.
|
|
76
|
+
<example>
|
|
77
|
+
user: Where are errors from the client handled?
|
|
78
|
+
assistant: [Uses the ${TOOL_NAMES.TASK} tool with subagent_type=${AGENT_TYPE.EXPLORE} to find the files that handle client errors instead of using ${TOOL_NAMES.GLOB} or ${TOOL_NAMES.GREP} directly]
|
|
79
|
+
</example>
|
|
80
|
+
<example>
|
|
81
|
+
user: What is the codebase structure?
|
|
82
|
+
assistant: [Uses the ${TOOL_NAMES.TASK} tool with subagent_type=${AGENT_TYPE.EXPLORE}]
|
|
83
|
+
</example>`
|
|
84
|
+
: '';
|
|
85
|
+
|
|
86
|
+
return `
|
|
87
|
+
# Tool usage policy${taskPolicy}
|
|
88
|
+
- When fetch returns a message about a redirect to a different host, you should immediately make a new fetch request with the redirect URL provided in the response.
|
|
89
|
+
- You can call multiple tools in a single response. If you intend to call multiple tools and there are no dependencies between them, make all independent tool calls in parallel. Maximize use of parallel tool calls where possible to increase efficiency. However, if some tool calls depend on previous calls to inform dependent values, do NOT call these tools in parallel and instead call them sequentially. For instance, if one operation must complete before another starts, run these operations sequentially instead. Never use placeholders or guess missing parameters in tool calls.
|
|
90
|
+
- Use specialized tools instead of bash commands when possible, as this provides a better user experience. For file operations, use dedicated tools: ${TOOL_NAMES.READ} for reading files instead of cat/head/tail, ${TOOL_NAMES.EDIT} for editing instead of sed/awk, and ${TOOL_NAMES.WRITE} for creating files instead of cat with heredoc or echo redirection. Reserve bash tools exclusively for actual system commands and terminal operations that require shell execution. NEVER use bash echo or other command-line tools to communicate thoughts, explanations, or instructions to the user. Output all communication directly in your response text instead.
|
|
91
|
+
`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function generateSystemPrompt(opts: {
|
|
95
|
+
todo: boolean;
|
|
96
|
+
productName: string;
|
|
97
|
+
language?: string;
|
|
98
|
+
appendSystemPrompt?: string;
|
|
99
|
+
outputStyle: OutputStyle;
|
|
100
|
+
task?: boolean;
|
|
101
|
+
}) {
|
|
102
|
+
const { outputStyle } = opts;
|
|
103
|
+
const isDefaultOutputStyle = outputStyle.isDefault();
|
|
104
|
+
return `
|
|
105
|
+
You are an interactive CLI tool that helps users ${isDefaultOutputStyle ? 'with software engineering tasks.' : `according to your "Output Style" below, which describes how you should respond to user queries.`} Use the instructions below and the tools available to you to assist the user.
|
|
106
|
+
|
|
107
|
+
IMPORTANT: Refuse to write code or explain code that may be used maliciously; even if the user claims it is for educational purposes.
|
|
108
|
+
${
|
|
109
|
+
opts.language === 'English'
|
|
110
|
+
? ''
|
|
111
|
+
: `IMPORTANT: Answer in ${opts.language}.
|
|
112
|
+
`
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
${
|
|
116
|
+
!isDefaultOutputStyle
|
|
117
|
+
? `
|
|
118
|
+
# Output style: ${outputStyle.name}
|
|
119
|
+
${outputStyle.prompt}
|
|
120
|
+
`
|
|
121
|
+
: `
|
|
122
|
+
# Tone and style
|
|
123
|
+
You should be concise, direct, and to the point. When you run a non-trivial bash command, you should explain what the command does and why you are running it.
|
|
124
|
+
Output text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. Never use tools like \`bash\` to communicate with the user during the session.
|
|
125
|
+
If you cannot or will not help the user with something, please do not say why or what it could lead to, since this comes across as preachy and annoying. Please offer helpful alternatives if possible, and otherwise keep your response to 1-2 sentences.
|
|
126
|
+
Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked.
|
|
127
|
+
IMPORTANT: You should minimize output tokens as much as possible while maintaining helpfulness, quality, and accuracy. Only address the specific query or task at hand, avoiding tangential information unless absolutely critical for completing the request. If you can answer in 1-3 sentences or a short paragraph, please do.
|
|
128
|
+
IMPORTANT: You should NOT answer with unnecessary preamble or postamble (such as explaining your code or summarizing your action), unless the user asks you to.
|
|
129
|
+
IMPORTANT: Keep your responses short, since they will be displayed on a command line interface. You MUST answer concisely with fewer than 4 lines (not including tool use or code generation), unless user asks for detail. Answer the user's question directly, without elaboration, explanation, or details. One word answers are best. Avoid introductions, conclusions, and explanations. You MUST avoid text before/after your response, such as "The answer is <answer>.", "Here is the content of the file..." or "Based on the information provided, the answer is..." or "Here is what I will do next...". Here are some examples to demonstrate appropriate verbosity:
|
|
130
|
+
<example>
|
|
131
|
+
user: 2 + 2
|
|
132
|
+
assistant: 4
|
|
133
|
+
</example>
|
|
134
|
+
<example>
|
|
135
|
+
user: is 11 a prime number?
|
|
136
|
+
assistant: Yes
|
|
137
|
+
</example>
|
|
138
|
+
<example>
|
|
139
|
+
user: what command should I run to list files in the current directory?
|
|
140
|
+
assistant: ls
|
|
141
|
+
</example>
|
|
142
|
+
<example>
|
|
143
|
+
user: what files are in the directory src/?
|
|
144
|
+
assistant: [runs ls and sees foo.c, bar.c, baz.c]
|
|
145
|
+
user: which file contains the implementation of foo?
|
|
146
|
+
assistant: src/foo.c
|
|
147
|
+
</example>
|
|
148
|
+
<example>
|
|
149
|
+
user: write tests for new feature
|
|
150
|
+
assistant: [uses grep and glob tools to find where similar tests are defined, uses concurrent read file tool use blocks in one tool call to read relevant files at the same time, uses edit file tool to write new tests]
|
|
151
|
+
</example>
|
|
152
|
+
`
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# Following conventions
|
|
156
|
+
When making changes to files, first understand the file's code conventions. Mimic code style, use existing libraries and utilities, and follow existing patterns.
|
|
157
|
+
- NEVER assume that a given library is available, even if it is well known. Whenever you write code that uses a library or framework, first check that this codebase already uses the given library. For example, you might look at neighboring files, or check the package.json (or cargo.toml, and so on depending on the language).
|
|
158
|
+
- When you create a new component, first look at existing components to see how they're written; then consider framework choice, naming conventions, typing, and other conventions.
|
|
159
|
+
- When you edit a piece of code, first look at the code's surrounding context (especially its imports) to understand the code's choice of frameworks and libraries. Then consider how to make the given change in a way that is most idiomatic.
|
|
160
|
+
- Always follow security best practices. Never introduce code that exposes or logs secrets and keys. Never commit secrets or keys to the repository.
|
|
161
|
+
|
|
162
|
+
${
|
|
163
|
+
outputStyle.isCodingRelated
|
|
164
|
+
? `
|
|
165
|
+
# Code style
|
|
166
|
+
- IMPORTANT: DO NOT ADD ***ANY*** COMMENTS unless asked
|
|
167
|
+
|
|
168
|
+
${getTasksPrompt(opts)}`
|
|
169
|
+
: ''
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
${getToolUsagePolicyPrompt(opts.task ?? false)}
|
|
173
|
+
|
|
174
|
+
${opts.appendSystemPrompt ? opts.appendSystemPrompt : ''}
|
|
175
|
+
`.trim();
|
|
176
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { ModelInfo } from '../core/model';
|
|
2
|
+
|
|
3
|
+
export type ReasoningEffort = 'low' | 'medium' | 'high';
|
|
4
|
+
|
|
5
|
+
export function getThinkingConfig(
|
|
6
|
+
model: ModelInfo,
|
|
7
|
+
reasoningEffort: ReasoningEffort,
|
|
8
|
+
): Record<string, any> | undefined {
|
|
9
|
+
if (!model.model.reasoning) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (model.provider.id === 'xiaomi') {
|
|
14
|
+
return {
|
|
15
|
+
providerOptions: {
|
|
16
|
+
xiaomi: {
|
|
17
|
+
thinking: {
|
|
18
|
+
type: 'enabled',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (model.provider.id === 'xai') {
|
|
26
|
+
return {
|
|
27
|
+
providerOptions: {
|
|
28
|
+
xai: {
|
|
29
|
+
// https://ai-sdk.dev/providers/ai-sdk-providers/xai#provider-options
|
|
30
|
+
// Only supported by grok-3-mini and grok-3-mini-fast models?
|
|
31
|
+
// reasoningEffort: 'low',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (['openrouter', 'zenmux', 'wanqing'].includes(model.provider.id)) {
|
|
38
|
+
let effort: ReasoningEffort | undefined = reasoningEffort;
|
|
39
|
+
let budgetTokens = undefined;
|
|
40
|
+
if (effort === 'high') {
|
|
41
|
+
effort = undefined;
|
|
42
|
+
budgetTokens = 31999;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
providerOptions: {
|
|
46
|
+
[model.provider.id]: {
|
|
47
|
+
reasoning: {
|
|
48
|
+
enabled: true,
|
|
49
|
+
effort,
|
|
50
|
+
max_tokens: budgetTokens,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (model.provider.id === 'modelwatch' && model.model.id.startsWith('gpt-')) {
|
|
58
|
+
return {
|
|
59
|
+
providerOptions: {
|
|
60
|
+
openai: {
|
|
61
|
+
reasoningEffort: reasoningEffort,
|
|
62
|
+
reasoningSummary: 'detailed',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (
|
|
69
|
+
(model.provider.id === 'modelwatch' &&
|
|
70
|
+
model.model.id.startsWith('claude-')) ||
|
|
71
|
+
model.model.id.startsWith('gemini-') ||
|
|
72
|
+
(model.provider.createModelType === 'anthropic' && model.model.reasoning)
|
|
73
|
+
) {
|
|
74
|
+
return {
|
|
75
|
+
providerOptions: {
|
|
76
|
+
anthropic: {
|
|
77
|
+
thinking: {
|
|
78
|
+
type: 'enabled' as const,
|
|
79
|
+
budgetTokens: reasoningEffort === 'low' ? 1024 : 31999,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (model.provider.id === 'google') {
|
|
87
|
+
return {
|
|
88
|
+
providerOptions: {
|
|
89
|
+
google: {
|
|
90
|
+
thinkingConfig: {
|
|
91
|
+
thinkingBudget: reasoningEffort === 'low' ? 1024 : 31999,
|
|
92
|
+
includeThoughts: true,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { AssistantMessage } from '../core/message';
|
|
2
|
+
|
|
3
|
+
export class Usage {
|
|
4
|
+
promptTokens: number;
|
|
5
|
+
completionTokens: number;
|
|
6
|
+
totalTokens: number;
|
|
7
|
+
|
|
8
|
+
constructor(init?: Partial<Usage>) {
|
|
9
|
+
this.promptTokens = init?.promptTokens ?? 0;
|
|
10
|
+
this.completionTokens = init?.completionTokens ?? 0;
|
|
11
|
+
this.totalTokens = init?.totalTokens ?? 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static empty(): Usage {
|
|
15
|
+
return new Usage();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static fromEventUsage(eventUsage: any): Usage {
|
|
19
|
+
const promptTokens =
|
|
20
|
+
eventUsage?.promptTokens ?? eventUsage?.inputTokens ?? 0;
|
|
21
|
+
const completionTokens =
|
|
22
|
+
eventUsage?.completionTokens ?? eventUsage?.outputTokens ?? 0;
|
|
23
|
+
const totalTokens =
|
|
24
|
+
eventUsage?.totalTokens ?? promptTokens + completionTokens;
|
|
25
|
+
|
|
26
|
+
return new Usage({
|
|
27
|
+
promptTokens: Number.isNaN(promptTokens) ? 0 : promptTokens,
|
|
28
|
+
completionTokens: Number.isNaN(completionTokens) ? 0 : completionTokens,
|
|
29
|
+
totalTokens: Number.isNaN(totalTokens) ? 0 : totalTokens,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static fromAssistantMessage(message: AssistantMessage): Usage {
|
|
34
|
+
return new Usage({
|
|
35
|
+
promptTokens: message.usage?.input_tokens,
|
|
36
|
+
completionTokens: message.usage?.output_tokens,
|
|
37
|
+
totalTokens: message.usage?.input_tokens + message.usage?.output_tokens,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
add(other: Usage): void {
|
|
42
|
+
this.promptTokens += other.promptTokens;
|
|
43
|
+
this.completionTokens += other.completionTokens;
|
|
44
|
+
this.totalTokens += other.totalTokens;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
reset(): void {
|
|
48
|
+
this.promptTokens = 0;
|
|
49
|
+
this.completionTokens = 0;
|
|
50
|
+
this.totalTokens = 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
clone(): Usage {
|
|
54
|
+
return new Usage({
|
|
55
|
+
promptTokens: this.promptTokens,
|
|
56
|
+
completionTokens: this.completionTokens,
|
|
57
|
+
totalTokens: this.totalTokens,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
isValid(): boolean {
|
|
62
|
+
return (
|
|
63
|
+
this.promptTokens >= 0 &&
|
|
64
|
+
this.completionTokens >= 0 &&
|
|
65
|
+
this.totalTokens >= 0
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OriCore
|
|
3
|
+
*
|
|
4
|
+
* Core AI engine for AI-powered coding assistance.
|
|
5
|
+
* This package provides the core functionality for AI-powered coding assistance.
|
|
6
|
+
*
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Main Engine API
|
|
11
|
+
export {
|
|
12
|
+
Engine,
|
|
13
|
+
createEngine,
|
|
14
|
+
type EngineOptions,
|
|
15
|
+
type EngineConfig,
|
|
16
|
+
type SessionOptions,
|
|
17
|
+
type SendMessageOptions,
|
|
18
|
+
} from './api/engine';
|
|
19
|
+
|
|
20
|
+
// Mode system
|
|
21
|
+
export * from './modes';
|
|
22
|
+
|
|
23
|
+
// Platform abstraction
|
|
24
|
+
export * from './platform';
|
|
25
|
+
|
|
26
|
+
// Communication layer
|
|
27
|
+
export * from './communication';
|
|
28
|
+
|
|
29
|
+
// Core utilities
|
|
30
|
+
export { randomUUID } from './utils/randomUUID';
|
|
31
|
+
|
|
32
|
+
// Paths
|
|
33
|
+
export { Paths, getGlobalDataPath } from './core/paths';
|
|
34
|
+
|
|
35
|
+
// Loop result type (for sendMessage return value)
|
|
36
|
+
export type { LoopResult } from './core/loop';
|
|
37
|
+
|
|
38
|
+
// Version
|
|
39
|
+
export const ENGINE_VERSION = '1.0.0';
|