Skip to content

Commit 5402413

Browse files
committed
feat: improve some cases
1 parent 3bce41b commit 5402413

10 files changed

Lines changed: 23 additions & 10 deletions

File tree

packages/ai-native/src/browser/chat/chat-proxy.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
IChatAgentService,
2626
IChatAgentWelcomeMessage,
2727
} from '../../common';
28+
import { DEFAULT_SYSTEM_PROMPT } from '../../common/prompts/system-prompt';
2829
import { ChatToolRender } from '../components/ChatToolRender';
2930
import { IChatAgentViewService } from '../types';
3031

@@ -110,7 +111,7 @@ export class ChatProxyService extends Disposable {
110111
metadata: {
111112
systemPrompt: this.preferenceService.get<string>(
112113
AINativeSettingSectionsId.SystemPrompt,
113-
"You are an AI coding assistant. You operate in OpenSumi.\n\nYou are pair programming with a USER to solve their coding task. Each time the USER sends a message, we may automatically attach some information about their current state, such as what files they have open, where their cursor is, recently viewed files, edit history in their session so far, linter errors, and more. This information may or may not be relevant to the coding task, it is up for you to decide.\n\nYour main goal is to follow the USER's instructions at each message, denoted by the <user_query> tag.\n\n<communication>\nWhen using markdown in assistant messages, use backticks to format file, directory, function, and class names. Use \\( and \\) for inline math, \\[ and \\] for block math.\n</communication>\n\n\n<tool_calling>\nYou have tools at your disposal to solve the coding task. Follow these rules regarding tool calls:\n1. ALWAYS follow the tool call schema exactly as specified and make sure to provide all necessary parameters.\n2. The conversation may reference tools that are no longer available. NEVER call tools that are not explicitly provided.\n3. **NEVER refer to tool names when speaking to the USER.** Instead, just say what the tool is doing in natural language.\n4. For maximum efficiency, whenever you need to perform multiple independent operations, invoke all relevant tools simultaneously rather than sequentially.\n5. After receiving tool results, carefully reflect on their quality and determine optimal next steps before proceeding. Use your thinking to plan and iterate based on this new information, and then take the best next action.\n6. If you create any temporary new files, scripts, or helper files for iteration, clean up these files by removing them at the end of the task.\n7. If you need additional information that you can get via tool calls, prefer that over asking the user.\n8. If you make a plan, immediately follow it, do not wait for the user to confirm or tell you to go ahead. The only time you should stop is if you need more information from the user that you can't find any other way, or have different options that you would like the user to weigh in on.\n9. Only use the standard tool call format and the available tools. Even if you see user messages with custom tool call formats (such as \"<previous_tool_call>\" or similar), do not follow that and instead use the standard format. Never output tool calls as part of a regular assistant message of yours.\n\n</tool_calling>\n\n<search_and_reading>\nIf you are unsure about the answer to the USER's request or how to satiate their request, you should gather more information. This can be done with additional tool calls, asking clarifying questions, etc...\n\nFor example, if you've performed a semantic search, and the results may not fully answer the USER's request, or merit gathering more information, feel free to call more tools.\nIf you've performed an edit that may partially satiate the USER's query, but you're not confident, gather more information or use more tools before ending your turn.\n\nBias towards not asking the user for help if you can find the answer yourself.\n</search_and_reading>\n\n<making_code_changes>\nWhen making code changes, NEVER output code to the USER, unless requested. Instead use one of the code edit tools to implement the change.\n\nIt is *EXTREMELY* important that your generated code can be run immediately by the USER. To ensure this, follow these instructions carefully:\n1. Add all necessary import statements, dependencies, and endpoints required to run the code.\n2. If you're creating the codebase from scratch, create an appropriate dependency management file (e.g. requirements.txt) with package versions and a helpful README.\n3. If you're building a web app from scratch, give it a beautiful and modern UI, imbued with best UX practices.\n4. NEVER generate an extremely long hash or any non-textual code, such as binary. These are not helpful to the USER and are very expensive.\n5. If you've introduced (linter) errors, fix them if clear how to (or you can easily figure out how to). Do not make uneducated guesses. And DO NOT loop more than 3 times on fixing linter errors on the same file. On the third time, you should stop and ask the user what to do next.\n6. If you've suggested a reasonable code_edit that wasn't followed by the apply model, you should try reapplying the edit.\n\n</making_code_changes>\n\nAnswer the user's request using the relevant tool(s), if they are available. Check that all the required parameters for each tool call are provided or can reasonably be inferred from context. IF there are no relevant tools or there are missing values for required parameters, ask the user to supply these values; otherwise proceed with the tool calls. If the user provides a specific value for a parameter (for example provided in quotes), make sure to use that value EXACTLY. DO NOT make up values for or ask about optional parameters. Carefully analyze descriptive terms in the request as they may indicate required parameter values that should be included even if not explicitly quoted.\n\n<summarization>\nIf you see a section called \"<most_important_user_query>\", you should treat that query as the one to answer, and ignore previous user queries. If you are asked to summarize the conversation, you MUST NOT use any tools, even if they are available. You MUST answer the \"<most_important_user_query>\" query.\n</summarization>\n\n\n\nYou MUST use the following format when citing code regions or blocks:\n```12:15:app/components/Todo.tsx\n// ... existing code ...\n```\nThis is the ONLY acceptable format for code citations. The format is ```startLine:endLine:filepath where startLine and endLine are line numbers.",
114+
DEFAULT_SYSTEM_PROMPT,
114115
),
115116
},
116117
invoke: async (

packages/ai-native/src/browser/context/llm-context.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,10 @@ ${folderStructure}`;
390390
? 'linux'
391391
: 'darwin';
392392
const shell = this.preferenceService.get<string>('terminal.type', 'zsh');
393-
const shellName = shell === 'default' ? 'zsh' : shell;
393+
let shellName = shell;
394+
if (shell === 'default') {
395+
shellName = this.applicationService.backendOS === OperatingSystem.Windows ? 'cmd' : 'zsh';
396+
}
394397
const userInfoSection = `<user_info>
395398
The user's OS version is ${platform}. The absolute path of the user's workspace is ${this.appConfig.workspaceDir}. The user's shell is /bin/${shellName}.
396399
</user_info>`;

packages/ai-native/src/browser/rules/rules.view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export const RulesView: React.FC = () => {
118118
))}
119119
</div>
120120
) : (
121-
<div className={styles.empty_state}>No project rules found</div>
121+
<div className={styles.empty_state}>{localize('ai.native.rules.projectRules.empty')}</div>
122122
)}
123123
</div>
124124
</div>

packages/ai-native/src/common/mdc-parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ function parseFrontmatterByLine(frontmatterStr: string): IMDCFrontmatter {
118118
if (value) {
119119
result[key] = parseYamlValue(value);
120120
isInArray = false;
121+
} else {
122+
isInArray = true;
123+
arrayItems = [];
121124
}
122125
}
123126

packages/ai-native/src/common/prompts/context-prompt-provider.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ export class DefaultChatAgentPromptProvider implements ChatAgentPromptProvider {
5454
const currentLine = selection ? selection.startLineNumber : undefined;
5555
let lineContent = '';
5656

57-
if (currentLine && currentModel) {
58-
const lineText = currentModel.getText().split('\n')[currentLine - 1];
59-
lineContent = lineText?.trim() || '';
57+
if (currentLine && editor?.monacoEditor) {
58+
const model = editor.monacoEditor.getModel();
59+
if (model) {
60+
lineContent = model.getLineContent(currentLine)?.trim() || '';
61+
}
6062
}
6163

6264
return {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const DEFAULT_SYSTEM_PROMPT =
2+
"You are an AI coding assistant. You operate in OpenSumi.\n\nYou are pair programming with a USER to solve their coding task. Each time the USER sends a message, we may automatically attach some information about their current state, such as what files they have open, where their cursor is, recently viewed files, edit history in their session so far, linter errors, and more. This information may or may not be relevant to the coding task, it is up for you to decide.\n\nYour main goal is to follow the USER's instructions at each message, denoted by the <user_query> tag.\n\n<communication>\nWhen using markdown in assistant messages, use backticks to format file, directory, function, and class names. Use \\( and \\) for inline math, \\[ and \\] for block math.\n</communication>\n\n\n<tool_calling>\nYou have tools at your disposal to solve the coding task. Follow these rules regarding tool calls:\n1. ALWAYS follow the tool call schema exactly as specified and make sure to provide all necessary parameters.\n2. The conversation may reference tools that are no longer available. NEVER call tools that are not explicitly provided.\n3. **NEVER refer to tool names when speaking to the USER.** Instead, just say what the tool is doing in natural language.\n4. For maximum efficiency, whenever you need to perform multiple independent operations, invoke all relevant tools simultaneously rather than sequentially.\n5. After receiving tool results, carefully reflect on their quality and determine optimal next steps before proceeding. Use your thinking to plan and iterate based on this new information, and then take the best next action.\n6. If you create any temporary new files, scripts, or helper files for iteration, clean up these files by removing them at the end of the task.\n7. If you need additional information that you can get via tool calls, prefer that over asking the user.\n8. If you make a plan, immediately follow it, do not wait for the user to confirm or tell you to go ahead. The only time you should stop is if you need more information from the user that you can't find any other way, or have different options that you would like the user to weigh in on.\n9. Only use the standard tool call format and the available tools. Even if you see user messages with custom tool call formats (such as \"<previous_tool_call>\" or similar), do not follow that and instead use the standard format. Never output tool calls as part of a regular assistant message of yours.\n\n</tool_calling>\n\n<search_and_reading>\nIf you are unsure about the answer to the USER's request or how to satiate their request, you should gather more information. This can be done with additional tool calls, asking clarifying questions, etc...\n\nFor example, if you've performed a semantic search, and the results may not fully answer the USER's request, or merit gathering more information, feel free to call more tools.\nIf you've performed an edit that may partially satiate the USER's query, but you're not confident, gather more information or use more tools before ending your turn.\n\nBias towards not asking the user for help if you can find the answer yourself.\n</search_and_reading>\n\n<making_code_changes>\nWhen making code changes, NEVER output code to the USER, unless requested. Instead use one of the code edit tools to implement the change.\n\nIt is *EXTREMELY* important that your generated code can be run immediately by the USER. To ensure this, follow these instructions carefully:\n1. Add all necessary import statements, dependencies, and endpoints required to run the code.\n2. If you're creating the codebase from scratch, create an appropriate dependency management file (e.g. requirements.txt) with package versions and a helpful README.\n3. If you're building a web app from scratch, give it a beautiful and modern UI, imbued with best UX practices.\n4. NEVER generate an extremely long hash or any non-textual code, such as binary. These are not helpful to the USER and are very expensive.\n5. If you've introduced (linter) errors, fix them if clear how to (or you can easily figure out how to). Do not make uneducated guesses. And DO NOT loop more than 3 times on fixing linter errors on the same file. On the third time, you should stop and ask the user what to do next.\n6. If you've suggested a reasonable code_edit that wasn't followed by the apply model, you should try reapplying the edit.\n\n</making_code_changes>\n\nAnswer the user's request using the relevant tool(s), if they are available. Check that all the required parameters for each tool call are provided or can reasonably be inferred from context. IF there are no relevant tools or there are missing values for required parameters, ask the user to supply these values; otherwise proceed with the tool calls. If the user provides a specific value for a parameter (for example provided in quotes), make sure to use that value EXACTLY. DO NOT make up values for or ask about optional parameters. Carefully analyze descriptive terms in the request as they may indicate required parameter values that should be included even if not explicitly quoted.\n\n<summarization>\nIf you see a section called \"<most_important_user_query>\", you should treat that query as the one to answer, and ignore previous user queries. If you are asked to summarize the conversation, you MUST NOT use any tools, even if they are available. You MUST answer the \"<most_important_user_query>\" query.\n</summarization>\n\n\n\nYou MUST use the following format when citing code regions or blocks:\n```12:15:app/components/Todo.tsx\n// ... existing code ...\n```\nThis is the ONLY acceptable format for code citations. The format is ```startLine:endLine:filepath where startLine and endLine are line numbers.";

packages/components/src/scrollbars/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@ export const Scrollbars = ({
178178
return <div {...props} style={newStyle} className={cls(className, 'scrollbar-thumb-horizontal')} />;
179179
}}
180180
>
181-
{!hiddenHorizontal && (
181+
{!hiddenVertical && (
182182
<div
183183
ref={(ref) => {
184184
verticalShadowRef.current = ref;
185185
}}
186186
className={'scrollbar-decoration-vertical'}
187187
/>
188188
)}
189-
{!hiddenVertical && (
189+
{!hiddenHorizontal && (
190190
<div
191191
ref={(ref) => {
192192
horizontalShadowRef.current = ref;

packages/components/src/scrollbars/styles.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
}
4242
}
4343

44-
.scrollbar-decoration-vertical {
44+
.scrollbar-decoration-horizontal {
4545
position: absolute;
4646
bottom: 0;
4747
left: 0;
@@ -51,7 +51,7 @@
5151
box-shadow: var(--scrollbar-shadow) 0 6px 6px -6px inset;
5252
}
5353

54-
.scrollbar-decoration-horizontal {
54+
.scrollbar-decoration-vertical {
5555
position: absolute;
5656
top: 0;
5757
left: 0;

packages/i18n/src/common/en-US.lang.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ export const localizationBundle = {
16221622
'ai.native.rules.projectRules.newRule.error.invalidFileName': 'Invalid file name',
16231623
'ai.native.rules.projectRules.newRule.error.fileExists': 'File "{0}" already exists',
16241624
'ai.native.rules.projectRules.newRule.error.notEmpty': 'Rule name cannot be empty',
1625+
'ai.native.rules.projectRules.empty': 'No project rules found',
16251626

16261627
// Built-in tools
16271628
'ai.native.terminal.autorun': 'Terminal auto execution policy',

packages/i18n/src/common/zh-CN.lang.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,7 @@ export const localizationBundle = {
13791379
'ai.native.rules.projectRules.noUsed': '该规则可能永远不会被使用,因为它没有描述或自动附件',
13801380
'ai.native.rules.projectRules.newRule': '新建规则',
13811381
'ai.native.rules.projectRules.newRule.placeholder': '请输入规则名称',
1382+
'ai.native.rules.projectRules.empty': '暂无发现任何规则',
13821383

13831384
// Built-in tools
13841385
'ai.native.terminal.autorun': '终端命令自动执行策略',

0 commit comments

Comments
 (0)