diff --git a/README.md b/README.md index e5f0c6dc..c566a3c6 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/packages/cli/src/commands/primer.ts b/packages/cli/src/commands/primer.ts index 186c35bf..84891883 100644 --- a/packages/cli/src/commands/primer.ts +++ b/packages/cli/src/commands/primer.ts @@ -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, diff --git a/packages/core/src/primer/__tests__/primer.test.ts b/packages/core/src/primer/__tests__/primer.test.ts index 6779aabd..520ce107 100644 --- a/packages/core/src/primer/__tests__/primer.test.ts +++ b/packages/core/src/primer/__tests__/primer.test.ts @@ -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'); diff --git a/packages/core/src/primer/analyzer.ts b/packages/core/src/primer/analyzer.ts index be46171f..c98dd5a4 100644 --- a/packages/core/src/primer/analyzer.ts +++ b/packages/core/src/primer/analyzer.ts @@ -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 = new Set(); + private detectPackageManagers(): PackageManager[] { + const managers: Set = 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++; diff --git a/packages/core/src/primer/generator.ts b/packages/core/src/primer/generator.ts index 32f4a41c..aab908f7 100644 --- a/packages/core/src/primer/generator.ts +++ b/packages/core/src/primer/generator.ts @@ -61,6 +61,7 @@ export class PrimerGenerator { const warnings: string[] = []; const errors: string[] = []; const generated: GeneratedInstruction[] = []; + const seenPaths = new Map(); 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); } diff --git a/packages/core/src/primer/types.ts b/packages/core/src/primer/types.ts index 85840c5e..6f121e76 100644 --- a/packages/core/src/primer/types.ts +++ b/packages/core/src/primer/types.ts @@ -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(),