mirror of
https://github.com/rohitg00/skillkit.git
synced 2026-11-18 18:04:26 +00:00
fix: address CodeRabbit PR review issues for primer
- Fix OS-agnostic path handling in analyzer using path.relative() and path.sep - Prevent output collisions when multiple agents produce same filename - Add defensive check in test before accessing generated[0] - Remove duplicate projectPath parameter in CLI primer command - Use PackageManager enum instead of z.string() for type safety - Detect monorepos before src-based layout to prevent misclassification - Document --output and --json flags in README examples
This commit is contained in:
@@ -323,6 +323,9 @@ skillkit primer --all-agents # Generate for all 32 agents
|
||||
skillkit primer --agent claude-code,cursor # Specific agents only
|
||||
skillkit primer --dry-run # Preview without writing files
|
||||
skillkit primer --analyze-only # Only show codebase analysis
|
||||
skillkit primer --output ./instructions # Write to custom directory
|
||||
skillkit primer --json # Output analysis as JSON (for scripting)
|
||||
skillkit primer --json --analyze-only # Machine-readable analysis
|
||||
```
|
||||
|
||||
Inspired by [primer](https://github.com/pierceboggan/primer) but extended for all SkillKit agents.
|
||||
|
||||
@@ -107,7 +107,6 @@ export class PrimerCommand extends Command {
|
||||
|
||||
try {
|
||||
const result = generatePrimer(projectPath, {
|
||||
projectPath,
|
||||
agents,
|
||||
allAgents: this.allAgents,
|
||||
outputDir: this.output ? resolve(this.output) : undefined,
|
||||
|
||||
@@ -173,6 +173,7 @@ describe('Primer', () => {
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.generated.length).toBeGreaterThan(0);
|
||||
const instruction = result.generated[0];
|
||||
|
||||
expect(instruction.content).toContain('# test-project');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
||||
import { join, basename } from 'node:path';
|
||||
import { join, basename, relative, sep } from 'node:path';
|
||||
import type {
|
||||
PrimerAnalysis,
|
||||
PackageManager,
|
||||
@@ -125,7 +125,8 @@ export class PrimerAnalyzer {
|
||||
try {
|
||||
const entries = readdirSync(dir, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
const relativePath = join(dir, entry.name).replace(this.projectPath + '/', '');
|
||||
const fullPath = join(dir, entry.name);
|
||||
const relativePath = relative(this.projectPath, fullPath);
|
||||
if (entry.name.startsWith('.') && entry.name !== '.github' && entry.name !== '.env.example') {
|
||||
if (!entry.isDirectory()) {
|
||||
this.files.add(relativePath);
|
||||
@@ -137,7 +138,7 @@ export class PrimerAnalyzer {
|
||||
}
|
||||
this.files.add(relativePath);
|
||||
if (entry.isDirectory()) {
|
||||
scan(join(dir, entry.name), depth + 1);
|
||||
scan(fullPath, depth + 1);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
@@ -289,8 +290,8 @@ export class PrimerAnalyzer {
|
||||
return languages;
|
||||
}
|
||||
|
||||
private detectPackageManagers(): string[] {
|
||||
const managers: Set<string> = new Set();
|
||||
private detectPackageManagers(): PackageManager[] {
|
||||
const managers: Set<PackageManager> = new Set();
|
||||
|
||||
for (const [file, manager] of Object.entries(PACKAGE_MANAGER_FILES)) {
|
||||
if (this.hasFile(file)) {
|
||||
@@ -302,8 +303,8 @@ export class PrimerAnalyzer {
|
||||
const packageManager = this.packageJson.packageManager;
|
||||
if (typeof packageManager === 'string') {
|
||||
const match = packageManager.match(/^(npm|pnpm|yarn|bun)@/);
|
||||
if (match) {
|
||||
managers.add(match[1]);
|
||||
if (match && ['npm', 'pnpm', 'yarn', 'bun'].includes(match[1])) {
|
||||
managers.add(match[1] as PackageManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -316,11 +317,11 @@ export class PrimerAnalyzer {
|
||||
hasWorkspaces: false,
|
||||
};
|
||||
|
||||
if (this.hasFile('src')) {
|
||||
if (this.hasFile('packages') || this.hasFile('apps')) {
|
||||
structure.type = 'monorepo';
|
||||
} else if (this.hasFile('src')) {
|
||||
structure.type = 'src-based';
|
||||
structure.srcDir = 'src';
|
||||
} else if (this.hasFile('packages') || this.hasFile('apps')) {
|
||||
structure.type = 'monorepo';
|
||||
} else if (this.hasFile('lib')) {
|
||||
structure.type = 'src-based';
|
||||
structure.srcDir = 'lib';
|
||||
@@ -582,7 +583,7 @@ export class PrimerAnalyzer {
|
||||
let directories = 0;
|
||||
|
||||
for (const file of this.files) {
|
||||
if (file.includes('/')) {
|
||||
if (file.includes(sep)) {
|
||||
directories++;
|
||||
}
|
||||
files++;
|
||||
|
||||
@@ -61,6 +61,7 @@ export class PrimerGenerator {
|
||||
const warnings: string[] = [];
|
||||
const errors: string[] = [];
|
||||
const generated: GeneratedInstruction[] = [];
|
||||
const seenPaths = new Map<string, string>();
|
||||
|
||||
this.analysis = analyzePrimer(this.projectPath);
|
||||
|
||||
@@ -80,6 +81,15 @@ export class PrimerGenerator {
|
||||
try {
|
||||
const instruction = this.generateForAgent(agent);
|
||||
if (instruction) {
|
||||
const existingAgent = seenPaths.get(instruction.filepath);
|
||||
if (existingAgent) {
|
||||
warnings.push(
|
||||
`Skipping ${agent}: output path "${instruction.filename}" already used by ${existingAgent}`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
seenPaths.set(instruction.filepath, agent);
|
||||
|
||||
if (!this.options.dryRun) {
|
||||
this.writeInstruction(instruction);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ export const PrimerAnalysis = z.object({
|
||||
repository: z.string().optional(),
|
||||
}),
|
||||
languages: z.array(Detection).default([]),
|
||||
packageManagers: z.array(z.string()).default([]),
|
||||
packageManagers: z.array(PackageManager).default([]),
|
||||
stack: ProjectStack,
|
||||
patterns: ProjectPatterns.optional(),
|
||||
structure: ProjectStructure.optional(),
|
||||
|
||||
Reference in New Issue
Block a user