Skip to content

Commit

Permalink
.instructions file
Browse files Browse the repository at this point in the history
  • Loading branch information
sestinj committed Nov 12, 2024
1 parent d69f4d9 commit 7105be0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions .instructions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Give concise responses.
27 changes: 27 additions & 0 deletions core/config/getSystemPromptDotFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { IDE } from "..";

export const SYSTEM_PROMPT_DOT_FILE = ".instructions";

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");
}
6 changes: 6 additions & 0 deletions core/config/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
defaultSlashCommandsJetBrains,
defaultSlashCommandsVscode,
} from "./default";
import { getSystemPromptDotFile } from "./getSystemPromptDotFile";
import {
DEFAULT_PROMPTS_FOLDER,
getPromptFiles,
Expand Down Expand Up @@ -732,6 +733,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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions extensions/vscode/src/extension/VsCodeExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ export class VsCodeExtension {

if (
filepath.endsWith(".continuerc.json") ||
filepath.endsWith(".prompt")
filepath.endsWith(".prompt") ||
filepath.endsWith(".instructions")
) {
this.configHandler.reloadConfig();
} else if (
Expand All @@ -296,14 +297,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("/"),
),
});
});

Expand Down Expand Up @@ -352,7 +355,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;
Expand Down

0 comments on commit 7105be0

Please sign in to comment.