-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument-prompt-rules-generic.ts
More file actions
294 lines (253 loc) · 8.39 KB
/
document-prompt-rules-generic.ts
File metadata and controls
294 lines (253 loc) · 8.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/**
* Documentation Prompt Rules - Generic
* Framework-agnostic prompt rules for unknown/undetected project types
* Used as fallback when project type detection doesn't match frontend/backend/mobile/devops
*/
import { CRITICAL_RULE_0, CRITICAL_RULE_1 } from './document-prompt-rules-frontend';
export { CRITICAL_RULE_0, CRITICAL_RULE_1 };
export interface DocumentFileDefinition {
filename: string;
description: string;
requiredFor: 'minimal' | 'standard' | 'comprehensive';
sections?: string[];
}
/**
* Generic-specific rules — no framework assumptions
*/
export const GENERIC_SPECIFIC_RULES = `## Generic Project Verification Rules
### General Principles
- ✅ Document what is actually found in the codebase — no framework assumptions
- ✅ Identify entry points, build processes, and project structure from actual files
- ✅ Document dependencies and their roles based on package manifests
- ✅ Describe modules, directories, and their purposes based on file contents
- ❌ Don't assume any specific framework, architecture, or pattern
- ❌ Don't invent project conventions not evidenced in code
### Source Code Documentation
- ✅ Only document modules, classes, and functions found in actual source files
- ✅ Verify entry points from package.json scripts, main/bin fields, or config files
- ✅ Document actual file organization and naming patterns
- ❌ Don't assume MVC, microservices, or any specific architecture
### Configuration Documentation
- ✅ Document configuration files found in the project root and subdirectories
- ✅ Verify build commands from package.json scripts or Makefile targets
- ✅ Document environment variable usage from actual .env files or code references
- ❌ Don't invent configuration that doesn't exist`;
/**
* Generic file definitions — framework-agnostic documentation files
*/
export const GENERIC_FILE_DEFINITIONS: DocumentFileDefinition[] = [
{
filename: 'ARCHITECTURE.md',
description: 'Project overview, tech stack, and structure',
requiredFor: 'minimal',
sections: [
'Project Overview',
'Tech Stack',
'Project Structure',
'Key Directories',
'Entry Points',
'Key Dependencies',
],
},
{
filename: 'CODEBASE.md',
description: 'Source code organization, key modules, and entry points',
requiredFor: 'standard',
sections: [
'Source Organization',
'Key Modules',
'Entry Points',
'Module Dependencies',
'Code Conventions',
],
},
{
filename: 'DEPENDENCIES.md',
description: 'Dependencies, configuration, and build setup',
requiredFor: 'standard',
sections: [
'Production Dependencies',
'Development Dependencies',
'Build Configuration',
'Scripts and Commands',
'Environment Configuration',
],
},
{
filename: 'AUTHENTICATION.md',
description: 'Authentication implementation if present',
requiredFor: 'standard',
sections: [
'Auth Overview',
'Auth Strategy',
'Token Management',
'Auth Flow',
'Security Considerations',
],
},
{
filename: 'ERROR_HANDLING.md',
description: 'Error handling patterns and logging',
requiredFor: 'standard',
sections: [
'Error Handling Overview',
'Error Types',
'Error Propagation',
'Logging Strategy',
'Error Recovery',
],
},
{
filename: 'TESTING.md',
description: 'Test setup, patterns, and coverage',
requiredFor: 'comprehensive',
sections: [
'Testing Overview',
'Test Framework',
'Test Structure',
'Test Patterns',
'Running Tests',
'Test Coverage',
],
},
{
filename: 'SECURITY.md',
description: 'Security practices and considerations',
requiredFor: 'comprehensive',
sections: [
'Security Overview',
'Input Validation',
'Authentication & Authorization',
'Secrets Management',
'Security Dependencies',
],
},
{
filename: 'DEVELOPMENT_PATTERNS.md',
description: 'Conventions, patterns, and common issues',
requiredFor: 'standard',
sections: [
'Code Conventions',
'Project Patterns',
'Common Issues',
'Development Setup',
'Development Tips',
],
},
];
/**
* Get files to generate based on tier
*/
export function getGenericFilesToGenerate(
tier: 'minimal' | 'standard' | 'comprehensive'
): DocumentFileDefinition[] {
if (tier === 'minimal') {
return GENERIC_FILE_DEFINITIONS.filter((f) => f.requiredFor === 'minimal');
}
if (tier === 'standard') {
return GENERIC_FILE_DEFINITIONS.filter(
(f) => f.requiredFor === 'minimal' || f.requiredFor === 'standard'
);
}
return GENERIC_FILE_DEFINITIONS;
}
/**
* Generate prompt for a single generic documentation file
* Uses minimal context — only fileTree, dependencies, devDependencies, gitRecentCommits, packageJsonContent
*/
export function generateGenericFilePrompt(
file: { filename: string; description: string },
context: {
projectName: string;
projectDescription: string;
industry: string;
documentationTier: 'minimal' | 'standard' | 'comprehensive';
fileTree: string;
dependencies: Record<string, string>;
devDependencies: Record<string, string>;
gitRecentCommits: string;
packageJsonContent?: string;
}
): string {
const {
projectName,
projectDescription,
industry,
documentationTier,
fileTree,
dependencies,
devDependencies,
gitRecentCommits,
packageJsonContent,
} = context;
// Build tier guidance
const tierGuidance =
documentationTier === 'minimal'
? `**DOCUMENTATION TIER: MINIMAL** (<20 files) - Keep focused and concise. Aim for 200-400 lines.`
: documentationTier === 'standard'
? `**DOCUMENTATION TIER: STANDARD** (20-200 files) - Provide balanced coverage. Aim for 300-500 lines.`
: `**DOCUMENTATION TIER: COMPREHENSIVE** (200+ files) - Provide detailed coverage. Aim for 400-600 lines.`;
return `${CRITICAL_RULE_0}
---
${CRITICAL_RULE_1}
---
${GENERIC_SPECIFIC_RULES}
---
# Generic Documentation: ${file.filename}
## Project Context
**Project Name:** ${projectName}
**Description:** ${projectDescription}
**Industry:** ${industry}
**Documentation Tier:** ${documentationTier}
${tierGuidance}
## Dependencies
**Production Dependencies (${Object.keys(dependencies).length} packages):**
${Object.entries(dependencies)
.slice(0, 25)
.map(([pkg, ver]) => `- ${pkg}: ${ver}`)
.join('\n')}
${Object.keys(dependencies).length > 25 ? `... and ${Object.keys(dependencies).length - 25} more` : ''}
**Dev Dependencies (${Object.keys(devDependencies).length} packages):**
${Object.entries(devDependencies)
.slice(0, 15)
.map(([pkg, ver]) => `- ${pkg}: ${ver}`)
.join('\n')}
${Object.keys(devDependencies).length > 15 ? `... and ${Object.keys(devDependencies).length - 15} more` : ''}
## Project Structure
**File Tree:**
\`\`\`
${fileTree.substring(0, 3000)}
\`\`\`
${packageJsonContent ? `**package.json:**\n\`\`\`json\n${packageJsonContent.substring(0, 1500)}\n\`\`\`` : ''}
## Recent Development Activity
\`\`\`
${gitRecentCommits.split('\n').slice(0, 15).join('\n')}
\`\`\`
---
## Your Task
Generate comprehensive **${file.filename}** documentation.
**Purpose:** ${file.description}
**Critical Requirements:**
1. **100% ACCURACY** - Only document what you can verify from context above
2. **DOMAIN-SPECIFIC** - Use ${industry} terminology throughout
3. **FILE-BASED EVIDENCE** - Reference specific files from the file tree above
4. **STRUCTURED** - Use clear hierarchical sections with headers (##, ###, ####)
5. **FILE-SPECIFIC FOCUS** - Focus on: ${file.description}
6. **NO FRAMEWORK ASSUMPTIONS** - Document what exists, don't assume patterns
7. **NO FUTURE CONTENT** - Do NOT add "Future Considerations", "Roadmap", or "Planned Features"
**DO's:**
- ✅ Reference specific files by path
- ✅ Include actual version numbers from dependencies
- ✅ Quote real commit messages
- ✅ Use ${industry} domain terminology
- ✅ Document ONLY current state of codebase
**DON'Ts:**
- ❌ Invent file paths that don't exist
- ❌ Assume any specific framework or architecture
- ❌ Make assumptions about unverified features
- ❌ Use generic placeholders or invented code
- ❌ Include speculative or future content
**FORMAT:** Return ONLY the markdown content. No JSON wrapper, no outer code blocks. Start directly with:
# ${file.filename.replace('.md', '')}
Generate the documentation now.`;
}