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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/ai.js +39 -30
  3. package/src/index.js +5 -59
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codebrief",
3
- "version": "1.1.8",
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": {
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 and you must write a comprehensive, deeply detailed CONTEXT.md file that will help AI assistants (like GitHub Copilot or Cursor) understand this project perfectly.
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
- ## Auto-detected project info
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
- - Type / Framework: ${analysis.type}
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 (first 80 entries)
137
+ ## File tree (up to 80 entries)
131
138
  ${fileList}
132
139
 
133
- ## Key source file samples
140
+ ## Source file samples
134
141
  ${samplesText}
135
142
 
136
143
  ---
137
144
 
138
- Now produce a CONTEXT.md file in this exact Markdown structure. Be as specific and detailed as possible — infer architecture from the actual code, don't be generic:
145
+ Produce the CONTEXT.md in exactly this structure:
139
146
 
140
147
  # Project Context: ${analysis.name}
141
- > Auto-generated and AI-enhanced by **codebrief**
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
- (bullet list of every detected technology with brief description of its role in THIS project)
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 Conventions
150
- (bullet list explaining what each main folder/directory is responsible for, inferred from the file tree and source)
158
+ ## 📁 Folder Structure
159
+ - Explain what each top-level folder is responsible for, inferred from the actual file tree.
151
160
 
152
- ## 🔧 Available Scripts
153
- (bullet list of scripts and what they actually do in context)
161
+ ## 🔧 Scripts
162
+ - Explain what each script actually does in the context of this project.
154
163
 
155
- ## 🗂️ Project Structure
164
+ ## 🗂️ Project Tree
156
165
  \`\`\`
157
- (the file tree, neatly formatted)
166
+ ${fileList}
158
167
  \`\`\`
159
168
 
160
169
  ## 🏗️ Architecture Notes
161
- (this is the most valuable section — write 8-15 detailed bullet points explaining:
162
- - how data flows through the app
163
- - where auth/session logic lives
164
- - how the database/ORM is used
165
- - how routing works
166
- - key patterns or abstractions in the codebase
167
- - anything a new developer MUST know before coding)
170
+ Write 815 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
- (bullet list of 8-12 concrete rules the AI assistant must follow when generating code for THIS specific project — based on the actual patterns observed in the source)
176
+ Write 812 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
- (bullet list of 6-10 things an AI must NEVER do in this project — inferred from the stack and code style)
181
+ Write 610 prohibitions inferred from the stack and code style. Be specific, not generic.
174
182
 
175
- ## 🔐 Security & Environment
176
- (notes about environment variables, secrets, auth patterns seen in the code)
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 content. No explanations, no code fences around the whole output.`;
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 files...");
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
- `Detected: ${analysis.stack.join(", ") || "Unknown project type"}`,
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
- print(bold(" 📄 Files Created:"));
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 (analysis.isMonorepo && analysis.packages.length > 0) {
434
+ if (!aiMode) {
457
435
  print("");
458
- print(bold(" 📦 Monorepo Packages:"));
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 ───────────────────────────────