Elffuss BraidHub

kikocis/continue public

main · 4.9 KiBRawPermalink
1import { DEFAULT_PROMPTS_FOLDER_V1 } from ".";
2import { IDE } from "..";
3import { walkDir } from "../indexing/walkDir";
4import { readAllGlobalPromptFiles } from "../util/paths";
5import { joinPathsToUri } from "../util/uri";
6
7// The hardcoded init prompt content
8const INIT_PROMPT_CONTENT = `name: Init
9description: Initialize Codebase
10---
11You are an expert development assistant. Your task is to create a comprehensive CONTINUE.md project guide for the user's codebase to help them and their team better understand and work with the project.
12
13## Step 1: Check Required Tools
14First, verify that you have access to the necessary tools:
15- builtin_file_glob_search: To discover project files
16- builtin_read_file: To analyze file contents
17- builtin_ls: To explore directory structure
18- builtin_create_new_file: To generate the CONTINUE.md file
19
20If any of these tools are unavailable, inform the user that they need to activate them and enable "Agent Mode" in Continue before proceeding.
21
22## Step 2: Project Analysis
23Analyze the project structure and key files to understand:
24- The programming languages and frameworks used
25- The overall architecture and organization
26- Key components and their responsibilities
27- Important configuration files
28- Build/deployment system
29
30## Step 3: Generate CONTINUE.md
31Create a comprehensive CONTINUE.md file in the .continue/rules/ directory with the following sections:
32
331. **Project Overview**
34 - Brief description of the project's purpose
35 - Key technologies used
36 - High-level architecture
37
382. **Getting Started**
39 - Prerequisites (required software, dependencies)
40 - Installation instructions
41 - Basic usage examples
42 - Running tests
43
443. **Project Structure**
45 - Overview of main directories and their purpose
46 - Key files and their roles
47 - Important configuration files
48
494. **Development Workflow**
50 - Coding standards or conventions
51 - Testing approach
52 - Build and deployment process
53 - Contribution guidelines
54
555. **Key Concepts**
56 - Domain-specific terminology
57 - Core abstractions
58 - Design patterns used
59
606. **Common Tasks**
61 - Step-by-step guides for frequent development tasks
62 - Examples of common operations
63
647. **Troubleshooting**
65 - Common issues and their solutions
66 - Debugging tips
67
688. **References**
69 - Links to relevant documentation
70 - Important resources
71
72Make sure your analysis is thorough but concise. Focus on information that would be most helpful to developers working on the project. If certain information isn't available from the codebase, make reasonable assumptions but mark these sections as needing verification.
73
74## Step 4: Finalize
75After creating the .continue/rules/CONTINUE.md file, provide a summary of what you've created and remind the user to:
761. Review and edit the file as needed
772. Commit it to their repository to share with their team
783. Explain that Continue will automatically load this file into context when working with the project
79
80Also inform the user that they can create additional rules.md files in subdirectories for more specific documentation related to those components.`;
81
82export const DEFAULT_PROMPTS_FOLDER_V2 = ".continue/prompts";
83
84export async function getPromptFilesFromDir(
85 ide: IDE,
86 dir: string,
87): Promise<{ path: string; content: string }[]> {
88 try {
89 const exists = await ide.fileExists(dir);
90
91 if (!exists) {
92 return [];
93 }
94
95 const uris = await walkDir(dir, ide, {
96 source: "get dir prompt files",
97 });
98 const promptFilePaths = uris.filter((p) => p.endsWith(".prompt"));
99 const results = promptFilePaths.map(async (uri) => {
100 const content = await ide.readFile(uri); // make a try catch
101 return { path: uri, content };
102 });
103 return Promise.all(results);
104 } catch (e) {
105 console.error(e);
106 return [];
107 }
108}
109
110export async function getAllPromptFiles(
111 ide: IDE,
112 overridePromptFolder?: string,
113 checkV1DefaultFolder: boolean = false,
114): Promise<{ path: string; content: string }[]> {
115 const workspaceDirs = await ide.getWorkspaceDirs();
116 let promptFiles: { path: string; content: string }[] = [];
117
118 let dirsToCheck = [DEFAULT_PROMPTS_FOLDER_V2];
119 if (checkV1DefaultFolder) {
120 dirsToCheck.push(DEFAULT_PROMPTS_FOLDER_V1);
121 }
122 if (overridePromptFolder) {
123 dirsToCheck = [overridePromptFolder];
124 }
125
126 const fullDirs = workspaceDirs
127 .map((dir) => dirsToCheck.map((d) => joinPathsToUri(dir, d)))
128 .flat();
129
130 promptFiles = (
131 await Promise.all(fullDirs.map((dir) => getPromptFilesFromDir(ide, dir)))
132 ).flat();
133
134 // Also read from ~/.continue/.prompts
135 promptFiles.push(...readAllGlobalPromptFiles());
136
137 // Add hardcoded init prompt
138 promptFiles.push({
139 path: "builtin:/init.prompt",
140 content: INIT_PROMPT_CONTENT,
141 });
142
143 return await Promise.all(
144 promptFiles.map(async (file) => {
145 if (file.path.startsWith("builtin:")) {
146 return file;
147 }
148 const content = await ide.readFile(file.path);
149 return { path: file.path, content };
150 }),
151 );
152}