codebrief 1.1.7 → 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 +2 -2
- package/src/ai.js +39 -30
- package/src/index.js +9 -60
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codebrief",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Generate AI context files for your project in seconds",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"codebrief": "
|
|
7
|
+
"codebrief": "src/index.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "node src/index.js",
|
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
|
@@ -30,7 +30,10 @@ function loadEnvFile(filePath) {
|
|
|
30
30
|
const eq = line.indexOf("=");
|
|
31
31
|
if (eq === -1) continue;
|
|
32
32
|
const key = line.slice(0, eq).trim();
|
|
33
|
-
const val = line
|
|
33
|
+
const val = line
|
|
34
|
+
.slice(eq + 1)
|
|
35
|
+
.trim()
|
|
36
|
+
.replace(/^['"]|['"]$/g, "");
|
|
34
37
|
if (key && !(key in process.env)) process.env[key] = val;
|
|
35
38
|
}
|
|
36
39
|
}
|
|
@@ -275,19 +278,16 @@ async function runInitPrompts(contextPath) {
|
|
|
275
278
|
async function main() {
|
|
276
279
|
print("");
|
|
277
280
|
print(bold(cyan("⚡ codebrief") + " — AI Context Generator"));
|
|
278
|
-
print(dim(" Scanning: " + rootDir));
|
|
279
281
|
print("");
|
|
280
282
|
|
|
281
283
|
// Step 1: Scan
|
|
282
|
-
startSpinner("Scanning project
|
|
284
|
+
startSpinner("Scanning project...");
|
|
283
285
|
const fileTree = scanDirectory(rootDir, maxDepth);
|
|
284
|
-
stopSpinner(`Found ${fileTree.length} files and folders`);
|
|
285
286
|
|
|
286
287
|
// Step 2: Analyze
|
|
287
|
-
startSpinner("Analyzing stack and conventions...");
|
|
288
288
|
const analysis = analyzeProject(rootDir);
|
|
289
289
|
stopSpinner(
|
|
290
|
-
|
|
290
|
+
`${fileTree.length} files · ${analysis.stack.join(", ") || "unknown stack"}`,
|
|
291
291
|
);
|
|
292
292
|
|
|
293
293
|
// Step 3: Generate files
|
|
@@ -429,63 +429,12 @@ async function main() {
|
|
|
429
429
|
|
|
430
430
|
// ── Summary ───────────────────────────────────────────────
|
|
431
431
|
print("");
|
|
432
|
-
|
|
433
|
-
filesCreated.forEach((f) => {
|
|
434
|
-
print(` ${green("✅")} ${bold(f.label)}`);
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
print("");
|
|
438
|
-
print(bold(" 🧱 Detected Stack:"));
|
|
439
|
-
if (analysis.stack.length > 0) {
|
|
440
|
-
analysis.stack.forEach((s) => print(` ${cyan("→")} ${s}`));
|
|
441
|
-
} else {
|
|
442
|
-
print(
|
|
443
|
-
` ${c.yellow}Could not auto-detect stack — check CONTEXT.md${c.reset}`,
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
if (analysis.conventions.length > 0) {
|
|
448
|
-
print("");
|
|
449
|
-
print(bold(" 📁 Detected Conventions:"));
|
|
450
|
-
analysis.conventions.forEach((s) => print(` ${cyan("→")} ${s}`));
|
|
451
|
-
}
|
|
432
|
+
filesCreated.forEach((f) => print(` ${green("✔")} ${bold(f.label)}`));
|
|
452
433
|
|
|
453
|
-
if (
|
|
434
|
+
if (!aiMode) {
|
|
454
435
|
print("");
|
|
455
|
-
print(
|
|
456
|
-
analysis.packages.forEach((p) =>
|
|
457
|
-
print(` ${cyan("→")} ${bold(p.name)} ${dim("(" + p.path + ")")}`),
|
|
458
|
-
);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
print("");
|
|
462
|
-
print(bold(" ✏️ Next Steps:"));
|
|
463
|
-
if (!initMode) {
|
|
464
|
-
print(
|
|
465
|
-
` 1. Open ${cyan("CONTEXT.md")} and fill in the ${bold("Architecture Notes")} section`,
|
|
466
|
-
);
|
|
467
|
-
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.`));
|
|
468
437
|
}
|
|
469
|
-
if (!skipCursor) {
|
|
470
|
-
print(
|
|
471
|
-
` 3. In Cursor, open the Notepads panel and reference ${cyan("CONTEXT.md")}`,
|
|
472
|
-
);
|
|
473
|
-
print(
|
|
474
|
-
` 4. Your ${cyan(".cursor/rules/project.mdc")} is already active automatically`,
|
|
475
|
-
);
|
|
476
|
-
}
|
|
477
|
-
print(
|
|
478
|
-
dim(
|
|
479
|
-
` Tip: use ${cyan("--update")} next time to preserve your notes on re-run.`,
|
|
480
|
-
),
|
|
481
|
-
);
|
|
482
|
-
print(
|
|
483
|
-
dim(
|
|
484
|
-
` Tip: use ${cyan("--ai")} for a deeply detailed AI-enhanced CONTEXT.md.`,
|
|
485
|
-
),
|
|
486
|
-
);
|
|
487
|
-
print("");
|
|
488
|
-
print(dim(" Re-run codebrief after major refactors to keep context fresh."));
|
|
489
438
|
print("");
|
|
490
439
|
|
|
491
440
|
// ── Interactive --init prompts ───────────────────────────────
|