Merge pull request #2881 from continuedev/nate/sys-prompt-file

.continuerules
This commit is contained in:
Nate Sesti 2024-11-13 16:59:01 -08:00 • committed by GitHub
commit 7231f84d99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 44 additions and 5 deletions

1
.instructions Normal file
View file

@ -0,0 +1 @@
Give concise responses.

View file

@ -0,0 +1,27 @@
import { IDE } from "..";
export const SYSTEM_PROMPT_DOT_FILE = ".continuerules";
export async function getSystemPromptDotFile(ide: IDE): Promise<string | null> {
const dirs = await ide.getWorkspaceDirs();
let prompts: string[] = [];
const pathSep = await ide.pathSep();
for (const dir of dirs) {
const dotFile = `${dir}${pathSep}${SYSTEM_PROMPT_DOT_FILE}`;
if (await ide.fileExists(dotFile)) {
try {
const content = await ide.readFile(dotFile);
prompts.push(content);
} catch (e) {
// ignore if file doesn't exist
}
}
}
if (!prompts.length) {
return null;
}
return prompts.join("\n\n");
}

View file

@ -64,6 +64,7 @@ import {
defaultSlashCommandsJetBrains,
defaultSlashCommandsVscode,
} from "./default";
import { getSystemPromptDotFile } from "./getSystemPromptDotFile";
import {
DEFAULT_PROMPTS_FOLDER,
getPromptFiles,
@ -735,6 +736,11 @@ async function loadFullConfigNode(
return { errors, config: undefined, configLoadInterrupted: true };
}
const systemPromptDotFile = await getSystemPromptDotFile(ide);
if (systemPromptDotFile) {
serialized.systemMessage = systemPromptDotFile;
}
// Convert serialized to intermediate config
let intermediate = await serializedToIntermediateConfig(serialized, ide);

View file

@ -105,7 +105,7 @@ class AsyncFileSaveListener(private val ideProtocolClient: IdeProtocolClient) :
for (event in events) {
if (event.path.endsWith(".continue/config.json") || event.path.endsWith(".continue/config.ts") || event.path.endsWith(
".continue\\config.json"
) || event.path.endsWith(".continue\\config.ts") || event.path.endsWith(".continuerc.json")
) || event.path.endsWith(".continue\\config.ts") || event.path.endsWith(".continuerc.json") || event.path.endsWith(".continuerc.json")
) {
return object : AsyncFileListener.ChangeApplier {
override fun afterVfsChange() {

View file

@ -37,6 +37,7 @@ import { VsCodeIde } from "../VsCodeIde";
import { VsCodeMessenger } from "./VsCodeMessenger";
import { SYSTEM_PROMPT_DOT_FILE } from "core/config/getSystemPromptDotFile";
import type { VsCodeWebviewProtocol } from "../webviewProtocol";
export class VsCodeExtension {
@ -284,7 +285,8 @@ export class VsCodeExtension {
if (
filepath.endsWith(".continuerc.json") ||
filepath.endsWith(".prompt")
filepath.endsWith(".prompt") ||
filepath.endsWith(SYSTEM_PROMPT_DOT_FILE)
) {
this.configHandler.reloadConfig();
} else if (
@ -296,14 +298,16 @@ export class VsCodeExtension {
} else {
// Reindex the file
this.core.invoke("index/forceReIndex", {
dirs: [filepath]
dirs: [filepath],
});
}
});
vscode.workspace.onDidDeleteFiles(async (event) => {
this.core.invoke("index/forceReIndex", {
dirs: event.files.map((file) => file.fsPath.split("/").slice(0, -1).join("/"))
dirs: event.files.map((file) =>
file.fsPath.split("/").slice(0, -1).join("/"),
),
});
});
@ -352,7 +356,8 @@ export class VsCodeExtension {
// Register a content provider for the readonly virtual documents
const documentContentProvider = new (class
implements vscode.TextDocumentContentProvider {
implements vscode.TextDocumentContentProvider
{
// emitter and its event
onDidChangeEmitter = new vscode.EventEmitter<vscode.Uri>();
onDidChange = this.onDidChangeEmitter.event;