support user definded instructions
This commit is contained in:
parent
101638b161
commit
06215450ad
@ -1 +0,0 @@
|
||||
You are a software developer assistant
|
22
instructions/instCode.txt
Normal file
22
instructions/instCode.txt
Normal file
@ -0,0 +1,22 @@
|
||||
As a software developer assistant, your tasks are to:
|
||||
|
||||
- Provide a clear and concise response to address the user's <request>.
|
||||
- Write code and give advice based on given code or information in the <context> if provided.
|
||||
- Follow language-specific best practices and coding standards.
|
||||
|
||||
When responding:
|
||||
|
||||
1. Summarize and describe the requirements or provided information in your own words.
|
||||
2. The summary and description should better be written in bullet points (excluding code).
|
||||
3. If modifying given code, output the changes and avoid unnecessary unchanged code.
|
||||
4. Enclose code or changes within blocks using triple backticks (```), and include the programming language and the file path, if available. For example:
|
||||
```
|
||||
```python path=./path/to/file.py
|
||||
print("Hello, World!")
|
||||
```
|
||||
```
|
||||
If no file paths or folder structure are provided and you are unsure about the file path of the code, you may omit the file path.
|
||||
5. Use separate code blocks for different files.
|
||||
6. Utilize the previous messages, if provided in the end of this prompt, to create your response. Note that not all previous messages are necessarily relevant.
|
||||
7. When providing a suggestion or instruction, begin by explaining the reason behind it.
|
||||
8. If you need more information, ask for it.
|
1
instructions/instCommon.txt
Normal file
1
instructions/instCommon.txt
Normal file
@ -0,0 +1 @@
|
||||
You are a software developer assistant.
|
1
instructions/instLangPython.txt
Normal file
1
instructions/instLangPython.txt
Normal file
@ -0,0 +1 @@
|
||||
When writing Python code, include type hints where appropriate and maintain compliance with PEP-8 guidelines, such as providing docstrings for modules, classes, and functions.
|
34
package-lock.json
generated
34
package-lock.json
generated
@ -19,6 +19,8 @@
|
||||
"@tiptap/react": "^2.0.3",
|
||||
"@tiptap/starter-kit": "^2.0.3",
|
||||
"axios": "^1.3.6",
|
||||
"dotenv": "^16.0.3",
|
||||
"ncp": "^2.0.0",
|
||||
"node-fetch": "^3.3.1",
|
||||
"nonce": "^1.0.4",
|
||||
"openai": "^3.2.1",
|
||||
@ -34,6 +36,7 @@
|
||||
"@types/glob": "^8.1.0",
|
||||
"@types/jest": "^29.5.1",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@types/ncp": "^2.0.5",
|
||||
"@types/node": "16.x",
|
||||
"@types/react-dom": "^18.2.3",
|
||||
"@types/shell-escape": "^0.2.1",
|
||||
@ -3753,6 +3756,15 @@
|
||||
"integrity": "sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/ncp": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/ncp/-/ncp-2.0.5.tgz",
|
||||
"integrity": "sha512-ocK0p8JuFmX7UkMabFPjY0F7apPvQyLWt5qtdvuvQEBz9i4m2dbzV+6L1zNaUp042RfnL6pHnxDE53OH6XQ9VQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "16.18.24",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.24.tgz",
|
||||
@ -8921,6 +8933,14 @@
|
||||
"integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/ncp": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz",
|
||||
"integrity": "sha512-zIdGUrPRFTUELUvr3Gmc7KZ2Sw/h1PiVM0Af/oHB6zgnV1ikqSfRk+TOufi79aHYCW3NiOXmr1BP5nWbzojLaA==",
|
||||
"bin": {
|
||||
"ncp": "bin/ncp"
|
||||
}
|
||||
},
|
||||
"node_modules/negotiator": {
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
|
||||
@ -14888,6 +14908,15 @@
|
||||
"integrity": "sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/ncp": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/ncp/-/ncp-2.0.5.tgz",
|
||||
"integrity": "sha512-ocK0p8JuFmX7UkMabFPjY0F7apPvQyLWt5qtdvuvQEBz9i4m2dbzV+6L1zNaUp042RfnL6pHnxDE53OH6XQ9VQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "16.18.24",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.24.tgz",
|
||||
@ -18808,6 +18837,11 @@
|
||||
"integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==",
|
||||
"dev": true
|
||||
},
|
||||
"ncp": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz",
|
||||
"integrity": "sha512-zIdGUrPRFTUELUvr3Gmc7KZ2Sw/h1PiVM0Af/oHB6zgnV1ikqSfRk+TOufi79aHYCW3NiOXmr1BP5nWbzojLaA=="
|
||||
},
|
||||
"negotiator": {
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
|
||||
|
@ -89,6 +89,7 @@
|
||||
"@types/glob": "^8.1.0",
|
||||
"@types/jest": "^29.5.1",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@types/ncp": "^2.0.5",
|
||||
"@types/node": "16.x",
|
||||
"@types/react-dom": "^18.2.3",
|
||||
"@types/shell-escape": "^0.2.1",
|
||||
@ -132,6 +133,8 @@
|
||||
"@tiptap/react": "^2.0.3",
|
||||
"@tiptap/starter-kit": "^2.0.3",
|
||||
"axios": "^1.3.6",
|
||||
"dotenv": "^16.0.3",
|
||||
"ncp": "^2.0.0",
|
||||
"node-fetch": "^3.3.1",
|
||||
"nonce": "^1.0.4",
|
||||
"openai": "^3.2.1",
|
||||
|
@ -54,9 +54,6 @@ export const commitMessageCommand: Command = {
|
||||
const diff_file = path.join(tempDir, 'diff_output.txt');
|
||||
await writeDiffFile(diff_file);
|
||||
|
||||
const commonInstructions = vscode.Uri.joinPath(ExtensionContextHolder.context?.extensionUri as vscode.Uri, 'instructions/commonInstructions.txt');
|
||||
const commitMsgInstructions = vscode.Uri.joinPath(ExtensionContextHolder.context?.extensionUri as vscode.Uri, 'instructions/commitMessageCommandInstructions.txt');
|
||||
|
||||
return `[instruction|${commonInstructions.path}] [instruction|${commitMsgInstructions.path}] [context|${diff_file}] Write a commit message`;
|
||||
return `[context|${diff_file}] Write a commit message`;
|
||||
},
|
||||
};
|
||||
|
@ -1,11 +1,46 @@
|
||||
import * as vscode from 'vscode';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as ncp from 'ncp'; // 需要安装 ncp 模块,用于复制目录
|
||||
|
||||
const ChatPanel = require('./chatPanel').default;
|
||||
const sendFileSelectMessage = require('./messageHandler').sendFileSelectMessage;
|
||||
const sendCodeSelectMessage = require('./messageHandler').sendCodeSelectMessage;
|
||||
import ExtensionContextHolder from './extensionContext';
|
||||
|
||||
function createChatDirectoryAndCopyInstructionsSync(extensionUri: vscode.Uri) {
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
if (!workspaceFolders) {
|
||||
return;
|
||||
}
|
||||
|
||||
const workspaceRoot = workspaceFolders[0].uri.fsPath;
|
||||
const chatDirPath = path.join(workspaceRoot, '.chat');
|
||||
const instructionsSrcPath = path.join(extensionUri.fsPath, 'instructions');
|
||||
|
||||
try {
|
||||
// 检查 .chat 目录是否存在,如果不存在,则创建它
|
||||
if (!fs.existsSync(chatDirPath)) {
|
||||
fs.mkdirSync(chatDirPath);
|
||||
}
|
||||
|
||||
// 将 instructions 目录复制到 .chat 目录中
|
||||
ncp.ncp(instructionsSrcPath, path.join(chatDirPath, 'instructions'), (err) => {
|
||||
if (err) {
|
||||
console.error('Error copying instructions:', err);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error creating .chat directory and copying instructions:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function activate(context: vscode.ExtensionContext) {
|
||||
ExtensionContextHolder.context = context;
|
||||
|
||||
// 创建 .chat 目录并复制 instructions
|
||||
createChatDirectoryAndCopyInstructionsSync(context.extensionUri);
|
||||
|
||||
let disposable = vscode.commands.registerCommand('devchat.openChatPanel', () => {
|
||||
if (vscode.workspace.workspaceFolders) {
|
||||
ChatPanel.createOrShow(context.extensionUri);
|
||||
|
@ -77,6 +77,28 @@ function parseMessage(message: string): { context: string[]; instruction: string
|
||||
return { context: contextPaths, instruction: instructionPaths, reference: referencePaths, text };
|
||||
}
|
||||
|
||||
function getInstructionFiles(): string[] {
|
||||
const instructionFiles: string[] = [];
|
||||
const workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
|
||||
if (workspaceDir) {
|
||||
const chatInstructionsPath = path.join(workspaceDir, '.chat', 'instructions');
|
||||
try {
|
||||
// 读取 chatInstructionsPath 目录下的所有文件和目录
|
||||
const files = fs.readdirSync(chatInstructionsPath);
|
||||
// 过滤出文件,忽略目录
|
||||
for (const file of files) {
|
||||
const filePath = path.join(chatInstructionsPath, file);
|
||||
const fileStats = fs.statSync(filePath);
|
||||
if (fileStats.isFile()) {
|
||||
instructionFiles.push(filePath);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error reading instruction files:', error);
|
||||
}
|
||||
}
|
||||
return instructionFiles;
|
||||
}
|
||||
|
||||
async function handleMessage(
|
||||
message: any,
|
||||
@ -96,9 +118,9 @@ async function handleMessage(
|
||||
if (parsedMessage.context.length > 0) {
|
||||
chatOptions.context = parsedMessage.context;
|
||||
}
|
||||
if (parsedMessage.instruction.length > 0) {
|
||||
chatOptions.header = parsedMessage.instruction;
|
||||
}
|
||||
|
||||
chatOptions.header = getInstructionFiles();
|
||||
|
||||
if (parsedMessage.reference.length > 0) {
|
||||
chatOptions.reference = parsedMessage.reference;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user