MCPcopy
hub / github.com/continuedev/continue / createNewPromptFileV2

Function createNewPromptFileV2

core/promptFiles/createNewPromptFile.ts:38–76  ·  view source on GitHub ↗
(
  ide: IDE,
  promptPath: string | undefined,
)

Source from the content-addressed store, hash-verified

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}

Callers 1

Calls 7

getMethod · 0.95
updateMethod · 0.95
joinPathsToUriFunction · 0.90
getWorkspaceDirsMethod · 0.65
fileExistsMethod · 0.65
writeFileMethod · 0.65
openFileMethod · 0.65

Tested by

no test coverage detected