Elffuss BraidHub

kikocis/continue public

main · 2.2 KiBRawPermalink
1import { IDE } from "..";
2import { GlobalContext } from "../util/GlobalContext";
3import { joinPathsToUri } from "../util/uri";
4
5const FIRST_TIME_DEFAULT_PROMPT_FILE = `# This is an example ".prompt" file
6# It is used to define and reuse prompts within Continue
7# Each .prompt file can be accessed by typing "@prompts" in the Chat input
8
9# A prompt file consists of two parts:
10# 1. Everything above the "---" is YAML. Here you can set "temperature", "description", and other options
11# 2. Everything below the "---" is the prompt body
12
13# If you do not want to set any options, you do not need to include the "---"
14
15# In the body, you can reference:
16# 1. Files, using either absolute or relative paths (based on the workspace root)
17 # @README.md
18 # @src/test/test.py
19 # @/Users/me/Desktop/my-project/src/test/test.py
20# 2. URLs, for example
21 # @https://example.com
22# 3. Context providers, for example
23 # @currentFile
24 # @os
25 # @repo-map
26
27# To learn more, see the full .prompt file reference: https://docs.continue.dev/features/prompt-files
28name: Example
29description: Example prompt file
30---
31
32Here is information about the current repo:
33
34@README.md`;
35
36const DEFAULT_PROMPT_FILE = "";
37
38export async function createNewPromptFileV2(
39 ide: IDE,
40 promptPath: string | undefined,
41): Promise<void> {
42 const workspaceDirs = await ide.getWorkspaceDirs();
43 if (workspaceDirs.length === 0) {
44 throw new Error(
45 "No workspace directories found. Make sure you've opened a folder in your IDE.",
46 );
47 }
48
49 const baseDirUri = joinPathsToUri(
50 workspaceDirs[0],
51 promptPath ?? ".continue/prompts",
52 );
53
54 // Find the first available filename
55 let counter = 0;
56 let promptFileUri: string;
57 do {
58 const suffix = counter === 0 ? "" : `-${counter}`;
59 promptFileUri = joinPathsToUri(
60 baseDirUri,
61 `new-prompt-file${suffix}.prompt`,
62 );
63 counter++;
64 } while (await ide.fileExists(promptFileUri));
65
66 const globalContext = new GlobalContext();
67 const PROMPT_FILE =
68 globalContext.get("hasAlreadyCreatedAPromptFile") === true
69 ? DEFAULT_PROMPT_FILE
70 : FIRST_TIME_DEFAULT_PROMPT_FILE;
71
72 globalContext.update("hasAlreadyCreatedAPromptFile", true);
73
74 await ide.writeFile(promptFileUri, PROMPT_FILE);
75 await ide.openFile(promptFileUri);
76}