codebrief 1.1.8 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ai.js +39 -30
- package/src/index.js +5 -59
package/package.json
CHANGED
package/src/ai.js
CHANGED
|
@@ -108,77 +108,86 @@ function buildPrompt(analysis, fileTree, fileSamples) {
|
|
|
108
108
|
.map(([k, v]) => ` ${k}: ${v}`)
|
|
109
109
|
.join("\n") || " (none)";
|
|
110
110
|
|
|
111
|
-
return `You are a senior software architect. A developer ran \`codebrief\` on their project
|
|
111
|
+
return `You are a senior software architect performing a deep code review. A developer ran \`codebrief\` on their project. Your job is to write a CONTEXT.md that gives an AI coding assistant (Cursor, Copilot, etc.) enough knowledge to contribute code as if it had written the project itself.
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
CRITICAL RULES:
|
|
114
|
+
- Every claim must be grounded in the actual files and code samples provided. No generic filler.
|
|
115
|
+
- Reference specific file paths (e.g. \`src/lib/auth.ts\`, \`app/api/users/route.ts\`) wherever possible.
|
|
116
|
+
- If you cannot infer something from the provided code, omit that bullet entirely — do NOT guess or write placeholders.
|
|
117
|
+
- Architecture Notes must name real functions, classes, modules, or patterns you actually observed, not vague descriptions.
|
|
118
|
+
- Rules for AI must reflect patterns actually present in the source — not generic best practices.
|
|
119
|
+
|
|
120
|
+
## Project metadata
|
|
114
121
|
- Name: ${analysis.name}
|
|
115
|
-
-
|
|
122
|
+
- Framework / Type: ${analysis.type}
|
|
116
123
|
- Language: ${analysis.language}
|
|
117
124
|
- Package manager: ${analysis.packageManager}
|
|
118
125
|
- Stack: ${analysis.stack.join(", ") || "unknown"}
|
|
119
126
|
- CSS framework: ${analysis.cssFramework || "none detected"}
|
|
120
127
|
- UI library: ${analysis.uiLibrary || "none detected"}
|
|
121
128
|
- State management: ${analysis.stateManagement || "none detected"}
|
|
122
|
-
- Database: ${analysis.database || "none detected"}
|
|
129
|
+
- Database / ORM: ${analysis.database || "none detected"}
|
|
123
130
|
- Test framework: ${analysis.testFramework || "none detected"}
|
|
124
|
-
- Deployment: ${analysis.deployment || "unknown"}
|
|
131
|
+
- Deployment target: ${analysis.deployment || "unknown"}
|
|
125
132
|
- Monorepo: ${analysis.isMonorepo}
|
|
126
133
|
|
|
127
134
|
## Scripts
|
|
128
135
|
${scripts}
|
|
129
136
|
|
|
130
|
-
## File tree (
|
|
137
|
+
## File tree (up to 80 entries)
|
|
131
138
|
${fileList}
|
|
132
139
|
|
|
133
|
-
##
|
|
140
|
+
## Source file samples
|
|
134
141
|
${samplesText}
|
|
135
142
|
|
|
136
143
|
---
|
|
137
144
|
|
|
138
|
-
|
|
145
|
+
Produce the CONTEXT.md in exactly this structure:
|
|
139
146
|
|
|
140
147
|
# Project Context: ${analysis.name}
|
|
141
|
-
>
|
|
142
|
-
> Generated: ${new Date().toISOString().split("T")[0]}
|
|
148
|
+
> AI-enhanced by **codebrief** · ${new Date().toISOString().split("T")[0]}
|
|
143
149
|
|
|
144
150
|
---
|
|
145
151
|
|
|
146
152
|
## 🧱 Tech Stack
|
|
147
|
-
|
|
153
|
+
- List each technology and its specific role in this project (e.g. "Prisma — ORM used in \`src/db/\` for all database queries").
|
|
154
|
+
|
|
155
|
+
## 🚀 Key Files
|
|
156
|
+
- List the 5–8 most important files a new developer should read first, with one sentence explaining what each does. Use exact paths from the file tree.
|
|
148
157
|
|
|
149
|
-
## 📁 Folder
|
|
150
|
-
|
|
158
|
+
## 📁 Folder Structure
|
|
159
|
+
- Explain what each top-level folder is responsible for, inferred from the actual file tree.
|
|
151
160
|
|
|
152
|
-
## 🔧
|
|
153
|
-
|
|
161
|
+
## 🔧 Scripts
|
|
162
|
+
- Explain what each script actually does in the context of this project.
|
|
154
163
|
|
|
155
|
-
## 🗂️ Project
|
|
164
|
+
## 🗂️ Project Tree
|
|
156
165
|
\`\`\`
|
|
157
|
-
|
|
166
|
+
${fileList}
|
|
158
167
|
\`\`\`
|
|
159
168
|
|
|
160
169
|
## 🏗️ Architecture Notes
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
- how routing works
|
|
166
|
-
- key patterns or abstractions in the codebase
|
|
167
|
-
- anything a new developer MUST know before coding)
|
|
170
|
+
Write 8–15 bullet points. Each bullet must:
|
|
171
|
+
- Name the specific file(s) or function(s) involved (e.g. "Auth flow starts in \`middleware.ts\`, validates JWT via \`src/lib/auth.ts:verifyToken()\`")
|
|
172
|
+
- Describe a concrete data flow, pattern, or constraint — not a vague summary
|
|
173
|
+
- Cover: request lifecycle, data access layer, auth/session, key abstractions, inter-module dependencies, anything surprising
|
|
168
174
|
|
|
169
175
|
## 🤖 Rules for AI
|
|
170
|
-
|
|
176
|
+
Write 8–12 rules based on patterns you actually observed in the code. Example format:
|
|
177
|
+
- "Always use the \`db\` instance from \`src/lib/db.ts\` — never import Prisma directly"
|
|
178
|
+
- "API routes live in \`app/api/\` and must use the response helper from \`src/lib/response.ts\`"
|
|
171
179
|
|
|
172
180
|
## 🚫 Never Do
|
|
173
|
-
|
|
181
|
+
Write 6–10 prohibitions inferred from the stack and code style. Be specific, not generic.
|
|
174
182
|
|
|
175
|
-
## 🔐
|
|
176
|
-
|
|
183
|
+
## 🔐 Environment & Security
|
|
184
|
+
- List environment variables referenced in the code (exact names if found).
|
|
185
|
+
- Note any auth patterns, token handling, or secrets management observed.
|
|
177
186
|
|
|
178
187
|
---
|
|
179
|
-
*Re-run \`codebrief\` after major refactors to keep this file current.*
|
|
188
|
+
*Re-run \`codebrief --ai\` after major refactors to keep this file current.*
|
|
180
189
|
|
|
181
|
-
Respond with ONLY the Markdown
|
|
190
|
+
Respond with ONLY the Markdown. No preamble, no code fences wrapping the entire output.`;
|
|
182
191
|
}
|
|
183
192
|
|
|
184
193
|
// ── HTTP helper (native, no deps) ────────────────────────────
|
package/src/index.js
CHANGED
|
@@ -278,19 +278,16 @@ async function runInitPrompts(contextPath) {
|
|
|
278
278
|
async function main() {
|
|
279
279
|
print("");
|
|
280
280
|
print(bold(cyan("⚡ codebrief") + " — AI Context Generator"));
|
|
281
|
-
print(dim(" Scanning: " + rootDir));
|
|
282
281
|
print("");
|
|
283
282
|
|
|
284
283
|
// Step 1: Scan
|
|
285
|
-
startSpinner("Scanning project
|
|
284
|
+
startSpinner("Scanning project...");
|
|
286
285
|
const fileTree = scanDirectory(rootDir, maxDepth);
|
|
287
|
-
stopSpinner(`Found ${fileTree.length} files and folders`);
|
|
288
286
|
|
|
289
287
|
// Step 2: Analyze
|
|
290
|
-
startSpinner("Analyzing stack and conventions...");
|
|
291
288
|
const analysis = analyzeProject(rootDir);
|
|
292
289
|
stopSpinner(
|
|
293
|
-
|
|
290
|
+
`${fileTree.length} files · ${analysis.stack.join(", ") || "unknown stack"}`,
|
|
294
291
|
);
|
|
295
292
|
|
|
296
293
|
// Step 3: Generate files
|
|
@@ -432,63 +429,12 @@ async function main() {
|
|
|
432
429
|
|
|
433
430
|
// ── Summary ───────────────────────────────────────────────
|
|
434
431
|
print("");
|
|
435
|
-
|
|
436
|
-
filesCreated.forEach((f) => {
|
|
437
|
-
print(` ${green("✅")} ${bold(f.label)}`);
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
print("");
|
|
441
|
-
print(bold(" 🧱 Detected Stack:"));
|
|
442
|
-
if (analysis.stack.length > 0) {
|
|
443
|
-
analysis.stack.forEach((s) => print(` ${cyan("→")} ${s}`));
|
|
444
|
-
} else {
|
|
445
|
-
print(
|
|
446
|
-
` ${c.yellow}Could not auto-detect stack — check CONTEXT.md${c.reset}`,
|
|
447
|
-
);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
if (analysis.conventions.length > 0) {
|
|
451
|
-
print("");
|
|
452
|
-
print(bold(" 📁 Detected Conventions:"));
|
|
453
|
-
analysis.conventions.forEach((s) => print(` ${cyan("→")} ${s}`));
|
|
454
|
-
}
|
|
432
|
+
filesCreated.forEach((f) => print(` ${green("✔")} ${bold(f.label)}`));
|
|
455
433
|
|
|
456
|
-
if (
|
|
434
|
+
if (!aiMode) {
|
|
457
435
|
print("");
|
|
458
|
-
print(
|
|
459
|
-
analysis.packages.forEach((p) =>
|
|
460
|
-
print(` ${cyan("→")} ${bold(p.name)} ${dim("(" + p.path + ")")}`),
|
|
461
|
-
);
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
print("");
|
|
465
|
-
print(bold(" ✏️ Next Steps:"));
|
|
466
|
-
if (!initMode) {
|
|
467
|
-
print(
|
|
468
|
-
` 1. Open ${cyan("CONTEXT.md")} and fill in the ${bold("Architecture Notes")} section`,
|
|
469
|
-
);
|
|
470
|
-
print(` 2. Add your own rules to the ${bold("Never Do")} section`);
|
|
436
|
+
print(dim(` Tip: use ${cyan("--ai")} for an AI-enhanced CONTEXT.md.`));
|
|
471
437
|
}
|
|
472
|
-
if (!skipCursor) {
|
|
473
|
-
print(
|
|
474
|
-
` 3. In Cursor, open the Notepads panel and reference ${cyan("CONTEXT.md")}`,
|
|
475
|
-
);
|
|
476
|
-
print(
|
|
477
|
-
` 4. Your ${cyan(".cursor/rules/project.mdc")} is already active automatically`,
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
print(
|
|
481
|
-
dim(
|
|
482
|
-
` Tip: use ${cyan("--update")} next time to preserve your notes on re-run.`,
|
|
483
|
-
),
|
|
484
|
-
);
|
|
485
|
-
print(
|
|
486
|
-
dim(
|
|
487
|
-
` Tip: use ${cyan("--ai")} for a deeply detailed AI-enhanced CONTEXT.md.`,
|
|
488
|
-
),
|
|
489
|
-
);
|
|
490
|
-
print("");
|
|
491
|
-
print(dim(" Re-run codebrief after major refactors to keep context fresh."));
|
|
492
438
|
print("");
|
|
493
439
|
|
|
494
440
|
// ── Interactive --init prompts ───────────────────────────────
|