@weavelogic/knowledge-graph-agent 0.10.3 → 0.10.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"cultivate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/cultivate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgCpC;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CA4OhD"}
1
+ {"version":3,"file":"cultivate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/cultivate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgCpC;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CA8PhD"}
@@ -121,32 +121,52 @@ function createCultivateCommand() {
121
121
  console.log("");
122
122
  }
123
123
  if (tasks.deepAnalysis) {
124
- console.log(chalk.cyan("🧠 Running deep analysis with claude-flow...\n"));
125
- const hasClaudeFlow = await checkClaudeFlowAvailable();
126
- if (!hasClaudeFlow) {
127
- console.log(chalk.yellow(" āš ļø claude-flow not available"));
128
- console.log(chalk.gray(" Install with: npm install -g claude-flow"));
129
- result.warnings.push("claude-flow not available for deep analysis");
124
+ console.log(chalk.cyan("🧠 Running deep analysis...\n"));
125
+ const { DeepAnalyzer } = await import("../../cultivation/deep-analyzer.js");
126
+ const analyzer = new DeepAnalyzer({
127
+ projectRoot,
128
+ docsPath,
129
+ verbose
130
+ });
131
+ const availability = await analyzer.getAvailabilityStatus();
132
+ if (!availability.available) {
133
+ console.log(chalk.yellow(" āš ļø Deep analysis unavailable"));
134
+ console.log(chalk.gray(` ${availability.reason}`));
135
+ console.log("");
136
+ console.log(chalk.gray(" Options:"));
137
+ console.log(chalk.gray(" 1. Run from a regular terminal (outside Claude Code)"));
138
+ console.log(chalk.gray(" 2. Set ANTHROPIC_API_KEY environment variable"));
139
+ result.warnings.push(`Deep analysis unavailable: ${availability.reason}`);
130
140
  } else {
141
+ console.log(chalk.gray(` Mode: ${availability.reason}`));
131
142
  if (dryRun) {
132
- console.log(chalk.yellow(" [DRY RUN] Would spawn claude-flow agents:"));
133
- console.log(" - Researcher: Analyze codebase patterns");
134
- console.log(" - Analyst: Identify architectural decisions");
135
- console.log(" - Coder: Detect implementation patterns");
136
- console.log(" - Tester: Analyze testing coverage");
143
+ console.log(chalk.yellow("\n [DRY RUN] Would run analysis agents:"));
144
+ console.log(" - Pattern Researcher: Analyze codebase architecture");
145
+ console.log(" - Code Analyst: Identify quality issues");
146
+ console.log(" - Implementation Reviewer: Review code patterns");
147
+ console.log(" - Test Analyzer: Analyze test coverage");
137
148
  } else {
138
149
  try {
139
- const { DeepAnalyzer } = await import("../../cultivation/deep-analyzer.js");
140
- const analyzer = new DeepAnalyzer({
141
- projectRoot,
142
- docsPath,
143
- verbose
144
- });
145
150
  const deepResult = await analyzer.analyze();
146
- console.log(` ${chalk.green("āœ“")} Deep analysis complete`);
147
- console.log(` Agents spawned: ${deepResult.agentsSpawned}`);
148
- console.log(` Insights generated: ${deepResult.insightsCount}`);
149
- console.log(` Documentation created: ${deepResult.documentsCreated}`);
151
+ if (deepResult.success) {
152
+ console.log(`
153
+ ${chalk.green("āœ“")} Deep analysis complete`);
154
+ console.log(` Agents spawned: ${deepResult.agentsSpawned}`);
155
+ console.log(` Insights generated: ${deepResult.insightsCount}`);
156
+ console.log(` Documentation created: ${deepResult.documentsCreated}`);
157
+ console.log(` Mode: ${deepResult.mode}`);
158
+ } else {
159
+ console.log(`
160
+ ${chalk.yellow("⚠")} Deep analysis completed with issues`);
161
+ console.log(` Agents spawned: ${deepResult.agentsSpawned}`);
162
+ console.log(` Insights generated: ${deepResult.insightsCount}`);
163
+ if (deepResult.errors.length > 0) {
164
+ for (const err of deepResult.errors.slice(0, 3)) {
165
+ console.log(chalk.gray(` - ${err}`));
166
+ }
167
+ }
168
+ result.warnings.push(...deepResult.errors);
169
+ }
150
170
  } catch (error) {
151
171
  result.errors.push(`Deep analysis failed: ${error instanceof Error ? error.message : String(error)}`);
152
172
  console.log(chalk.red(` āœ— Deep analysis failed: ${error instanceof Error ? error.message : String(error)}`));
@@ -239,20 +259,6 @@ function displaySummary(result, dryRun) {
239
259
  console.log(chalk.gray("\nRun without --dry-run to apply changes\n"));
240
260
  }
241
261
  }
242
- async function checkClaudeFlowAvailable() {
243
- const { execSync } = await import("child_process");
244
- try {
245
- execSync("claude-flow --version", { stdio: "pipe", timeout: 5e3 });
246
- return true;
247
- } catch {
248
- }
249
- try {
250
- execSync("npx claude-flow --version", { stdio: "pipe", timeout: 3e4 });
251
- return true;
252
- } catch {
253
- return false;
254
- }
255
- }
256
262
  export {
257
263
  createCultivateCommand
258
264
  };
@@ -1 +1 @@
1
- {"version":3,"file":"cultivate.js","sources":["../../../src/cli/commands/cultivate.ts"],"sourcesContent":["/**\n * Cultivate Command - Systematically enhance the knowledge graph\n *\n * This command provides cultivation tasks:\n * - Seed primitives from codebase analysis\n * - Deep analysis with claude-flow integration\n * - Graph enhancement and optimization\n *\n * @module cli/commands/cultivate\n */\n\nimport { Command } from 'commander';\nimport chalk from 'chalk';\nimport { resolve, join, relative } from 'path';\nimport { existsSync, mkdirSync, readFileSync, readdirSync, statSync } from 'fs';\nimport { SeedGenerator } from '../../cultivation/seed-generator.js';\nimport { ShadowCache, loadShadowCache } from '../../core/cache.js';\nimport type { CultivationOptions, Ecosystem, SeedAnalysis } from '../../cultivation/types.js';\n\n/**\n * Cultivation result\n */\ninterface CultivationResult {\n success: boolean;\n seed: {\n created: number;\n documents: Array<{ title: string; path: string; type: string }>;\n };\n analysis: {\n filesProcessed: number;\n dependenciesFound: number;\n servicesFound: number;\n };\n cache: {\n updated: number;\n hits: number;\n misses: number;\n };\n duration: number;\n warnings: string[];\n errors: string[];\n}\n\n/**\n * Create cultivate command\n */\nexport function createCultivateCommand(): Command {\n return new Command('cultivate')\n .description('Systematically cultivate and enhance the knowledge graph')\n .argument('[path]', 'Directory to cultivate (defaults to current directory)', '.')\n .option('--dry-run', 'Preview changes without executing', false)\n .option('-d, --docs <path>', 'Documentation path', 'docs')\n .option('-v, --verbose', 'Verbose output', false)\n .option('--seed', 'Bootstrap vault with primitives from codebase analysis', false)\n .option('--deep-analysis', 'Use claude-flow agents for deep analysis', false)\n .option('--cache', 'Use shadow cache for incremental updates', true)\n .option('--ecosystem <ecosystems>', 'Filter to specific ecosystems (comma-separated)', undefined)\n .option('--include-dev', 'Include dev dependencies', false)\n .option('--major-only', 'Only process major dependencies', false)\n .option('--refresh-cache', 'Force refresh the shadow cache', false)\n .action(async (targetPath: string, options: {\n dryRun?: boolean;\n docs?: string;\n verbose?: boolean;\n seed?: boolean;\n deepAnalysis?: boolean;\n cache?: boolean;\n ecosystem?: string;\n includeDev?: boolean;\n majorOnly?: boolean;\n refreshCache?: boolean;\n }) => {\n const projectRoot = resolve(targetPath);\n const docsPath = options.docs || 'docs';\n const verbose = options.verbose || false;\n const dryRun = options.dryRun || false;\n\n console.log(chalk.bold.green('\\n🌱 Knowledge Graph Cultivator\\n'));\n console.log(` Project: ${projectRoot}`);\n console.log(` Docs: ${docsPath}`);\n if (dryRun) {\n console.log(` Mode: ${chalk.yellow('Dry Run')}`);\n }\n console.log('');\n\n // Determine tasks\n const tasks = {\n seed: options.seed || false,\n deepAnalysis: options.deepAnalysis || false,\n };\n\n // If no tasks selected, show help\n if (!tasks.seed && !tasks.deepAnalysis) {\n console.log(chalk.yellow('šŸ’” No tasks selected. Use one or more of:'));\n console.log(' --seed Bootstrap vault with primitives from codebase');\n console.log(' --deep-analysis Use claude-flow for deep codebase analysis');\n console.log('');\n console.log(chalk.gray('Options:'));\n console.log(' --dry-run Preview without writing files');\n console.log(' --cache Use shadow cache for incremental updates (default: true)');\n console.log(' --refresh-cache Force refresh the shadow cache');\n console.log(' --ecosystem Filter to ecosystems (nodejs,python,rust,go,php,java)');\n console.log(' --include-dev Include dev dependencies');\n console.log(' --major-only Only process major dependencies');\n console.log('');\n console.log('Run \"kg cultivate --help\" for more options');\n return;\n }\n\n const startTime = Date.now();\n const result: CultivationResult = {\n success: true,\n seed: { created: 0, documents: [] },\n analysis: { filesProcessed: 0, dependenciesFound: 0, servicesFound: 0 },\n cache: { updated: 0, hits: 0, misses: 0 },\n duration: 0,\n warnings: [],\n errors: [],\n };\n\n try {\n // Initialize shadow cache\n let cache: ShadowCache | undefined;\n if (options.cache !== false) {\n console.log(chalk.cyan('šŸ“¦ Initializing shadow cache...'));\n cache = await loadShadowCache(projectRoot);\n\n if (options.refreshCache) {\n cache.clear();\n console.log(chalk.gray(' Cache cleared (refresh mode)'));\n }\n\n const stats = cache.getStats();\n console.log(chalk.gray(` Entries: ${stats.totalEntries}, Hit rate: ${(stats.hitRate * 100).toFixed(1)}%`));\n console.log('');\n }\n\n // Task 1: Seed primitives\n if (tasks.seed) {\n console.log(chalk.cyan('🌱 Seeding primitives from codebase...\\n'));\n\n // Parse ecosystem filter\n let ecosystems: Ecosystem[] | undefined;\n if (options.ecosystem) {\n ecosystems = options.ecosystem.split(',').map(e => e.trim() as Ecosystem);\n console.log(chalk.gray(` Ecosystems: ${ecosystems.join(', ')}`));\n }\n\n // Create generator\n const generator = await SeedGenerator.create(projectRoot, docsPath);\n\n // Analyze\n console.log(chalk.gray(' Analyzing codebase...'));\n const analysis = await generator.analyze();\n\n result.analysis = {\n filesProcessed: analysis.metadata.filesScanned,\n dependenciesFound: analysis.dependencies.length,\n servicesFound: analysis.services.length,\n };\n\n // Display analysis\n console.log(`\\n ${chalk.bold('Analysis Results:')}`);\n console.log(` Languages: ${analysis.languages.join(', ') || 'none'}`);\n console.log(` Dependencies: ${analysis.dependencies.length}`);\n console.log(` Frameworks: ${analysis.frameworks.length}`);\n console.log(` Services: ${analysis.services.length}`);\n console.log(` Deployments: ${analysis.deployments.length}`);\n\n if (verbose) {\n displayDetailedAnalysis(analysis);\n }\n\n console.log('');\n\n // Generate primitives\n console.log(chalk.gray(' Generating primitive nodes...'));\n const documents = await generator.generatePrimitives(analysis);\n\n if (dryRun) {\n console.log(`\\n ${chalk.yellow('[DRY RUN]')} Would create ${documents.length} primitives:`);\n for (const doc of documents.slice(0, 10)) {\n console.log(` - ${doc.frontmatter.type}: ${doc.title}`);\n }\n if (documents.length > 10) {\n console.log(` ... and ${documents.length - 10} more`);\n }\n result.seed.documents = documents.map(d => ({\n title: d.title,\n path: d.path,\n type: d.frontmatter.type || 'unknown',\n }));\n } else {\n const writeResult = await generator.writePrimitives(documents);\n result.seed.created = writeResult.documentsGenerated.length;\n result.seed.documents = writeResult.documentsGenerated;\n\n console.log(`\\n ${chalk.green('āœ“')} Created ${writeResult.documentsGenerated.length} primitives`);\n\n if (writeResult.warnings.length > 0) {\n result.warnings.push(...writeResult.warnings);\n if (verbose) {\n console.log(chalk.yellow(` Warnings: ${writeResult.warnings.length}`));\n }\n }\n\n if (writeResult.errors.length > 0) {\n result.errors.push(...writeResult.errors);\n console.log(chalk.red(` Errors: ${writeResult.errors.length}`));\n }\n }\n\n console.log('');\n }\n\n // Task 2: Deep Analysis with claude-flow\n if (tasks.deepAnalysis) {\n console.log(chalk.cyan('🧠 Running deep analysis with claude-flow...\\n'));\n\n // Check if claude-flow is available\n const hasClaudeFlow = await checkClaudeFlowAvailable();\n\n if (!hasClaudeFlow) {\n console.log(chalk.yellow(' āš ļø claude-flow not available'));\n console.log(chalk.gray(' Install with: npm install -g claude-flow'));\n result.warnings.push('claude-flow not available for deep analysis');\n } else {\n if (dryRun) {\n console.log(chalk.yellow(' [DRY RUN] Would spawn claude-flow agents:'));\n console.log(' - Researcher: Analyze codebase patterns');\n console.log(' - Analyst: Identify architectural decisions');\n console.log(' - Coder: Detect implementation patterns');\n console.log(' - Tester: Analyze testing coverage');\n } else {\n // Import and run DeepAnalyzer\n try {\n const { DeepAnalyzer } = await import('../../cultivation/deep-analyzer.js');\n const analyzer = new DeepAnalyzer({\n projectRoot,\n docsPath,\n verbose,\n });\n\n const deepResult = await analyzer.analyze();\n\n console.log(` ${chalk.green('āœ“')} Deep analysis complete`);\n console.log(` Agents spawned: ${deepResult.agentsSpawned}`);\n console.log(` Insights generated: ${deepResult.insightsCount}`);\n console.log(` Documentation created: ${deepResult.documentsCreated}`);\n } catch (error) {\n result.errors.push(`Deep analysis failed: ${error instanceof Error ? error.message : String(error)}`);\n console.log(chalk.red(` āœ— Deep analysis failed: ${error instanceof Error ? error.message : String(error)}`));\n }\n }\n }\n\n console.log('');\n }\n\n // Update cache\n if (cache) {\n const stats = cache.getStats();\n result.cache = {\n updated: stats.totalEntries,\n hits: stats.hitCount,\n misses: stats.missCount,\n };\n\n await cache.save();\n }\n\n result.duration = Date.now() - startTime;\n result.success = result.errors.length === 0;\n\n // Final summary\n displaySummary(result, dryRun);\n\n } catch (error) {\n console.error(chalk.red('\\nāŒ Cultivation failed:'), error);\n process.exit(1);\n }\n });\n}\n\n/**\n * Display detailed analysis output\n */\nfunction displayDetailedAnalysis(analysis: SeedAnalysis): void {\n if (analysis.frameworks.length > 0) {\n console.log(`\\n ${chalk.gray('Frameworks:')}`);\n for (const fw of analysis.frameworks) {\n console.log(` - ${fw.name} (${fw.ecosystem}) v${fw.version}`);\n }\n }\n\n if (analysis.services.length > 0) {\n console.log(`\\n ${chalk.gray('Services:')}`);\n for (const svc of analysis.services) {\n console.log(` - ${svc.name}: ${svc.type} (${svc.technology})`);\n }\n }\n\n if (analysis.deployments.length > 0) {\n console.log(`\\n ${chalk.gray('Deployments:')}`);\n for (const dep of analysis.deployments) {\n console.log(` - ${dep}`);\n }\n }\n}\n\n/**\n * Display cultivation summary\n */\nfunction displaySummary(result: CultivationResult, dryRun: boolean): void {\n console.log(chalk.bold.blue('šŸ“Š Cultivation Summary\\n'));\n\n if (dryRun) {\n console.log(chalk.yellow('[DRY RUN] No changes were made\\n'));\n }\n\n console.log(' Analysis:');\n console.log(` Files processed: ${result.analysis.filesProcessed}`);\n console.log(` Dependencies: ${result.analysis.dependenciesFound}`);\n console.log(` Services: ${result.analysis.servicesFound}`);\n\n if (result.seed.created > 0 || result.seed.documents.length > 0) {\n console.log('\\n Seed:');\n console.log(` Primitives ${dryRun ? 'would create' : 'created'}: ${dryRun ? result.seed.documents.length : result.seed.created}`);\n }\n\n if (result.cache.updated > 0) {\n console.log('\\n Cache:');\n console.log(` Entries: ${result.cache.updated}`);\n const hitRate = result.cache.hits + result.cache.misses > 0\n ? (result.cache.hits / (result.cache.hits + result.cache.misses) * 100).toFixed(1)\n : 0;\n console.log(` Hit rate: ${hitRate}%`);\n }\n\n console.log(`\\n Duration: ${(result.duration / 1000).toFixed(2)}s`);\n\n if (result.warnings.length > 0) {\n console.log(chalk.yellow(`\\n āš ļø Warnings: ${result.warnings.length}`));\n for (const warning of result.warnings.slice(0, 5)) {\n console.log(chalk.gray(` - ${warning}`));\n }\n }\n\n if (result.errors.length > 0) {\n console.log(chalk.red(`\\n āŒ Errors: ${result.errors.length}`));\n for (const error of result.errors.slice(0, 5)) {\n console.log(chalk.gray(` - ${error}`));\n }\n }\n\n if (result.success && !dryRun) {\n console.log(chalk.bold.green('\\n✨ Cultivation complete!\\n'));\n } else if (!result.success) {\n console.log(chalk.yellow('\\nāš ļø Cultivation completed with errors\\n'));\n } else {\n console.log(chalk.gray('\\nRun without --dry-run to apply changes\\n'));\n }\n}\n\n/**\n * Check if claude-flow is available\n * Checks for direct command first (globally installed), then falls back to npx\n */\nasync function checkClaudeFlowAvailable(): Promise<boolean> {\n const { execSync } = await import('child_process');\n\n // First try direct command (globally installed claude-flow)\n try {\n execSync('claude-flow --version', { stdio: 'pipe', timeout: 5000 });\n return true;\n } catch {\n // Direct command not available, try npx\n }\n\n // Fall back to npx\n try {\n execSync('npx claude-flow --version', { stdio: 'pipe', timeout: 30000 });\n return true;\n } catch {\n return false;\n }\n}\n"],"names":[],"mappings":";;;;;AA8CO,SAAS,yBAAkC;AAChD,SAAO,IAAI,QAAQ,WAAW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AQ,IAAI;AAAA,eAAkB,OAAO,WAAW,KAAM,QAAQ,CAAC,CAAC,GAAG;AAEnE,MAAI,OAAO,SAAS,SAAS,GAAG;AAC9B,YAAQ,IAAI,MAAM,OAAO;AAAA,kBAAqB,OAAO,SAAS,MAAM,EAAE,CAAC;AACvE,eAAW,WAAW,OAAO,SAAS,MAAM,GAAG,CAAC,GAAG;AACjD,cAAQ,IAAI,MAAM,KAAK,SAAS,OAAO,EAAE,CAAC;AAAA,IAC5C;AAAA,EACF;AAEA,MAAI,OAAO,OAAO,SAAS,GAAG;AAC5B,YAAQ,IAAI,MAAM,IAAI;AAAA,cAAiB,OAAO,OAAO,MAAM,EAAE,CAAC;AAC9D,eAAW,SAAS,OAAO,OAAO,MAAM,GAAG,CAAC,GAAG;AAC7C,cAAQ,IAAI,MAAM,KAAK,SAAS,KAAK,EAAE,CAAC;AAAA,IAC1C;AAAA,EACF;AAEA,MAAI,OAAO,WAAW,CAAC,QAAQ;AAC7B,YAAQ,IAAI,MAAM,KAAK,MAAM,6BAA6B,CAAC;AAAA,EAC7D,WAAW,CAAC,OAAO,SAAS;AAC1B,YAAQ,IAAI,MAAM,OAAO,2CAA2C,CAAC;AAAA,EACvE,OAAO;AACL,YAAQ,IAAI,MAAM,KAAK,4CAA4C,CAAC;AAAA,EACtE;AACF;AAMA,eAAe,2BAA6C;AAC1D,QAAM,EAAE,SAAA,IAAa,MAAM,OAAO,eAAe;AAGjD,MAAI;AACF,aAAS,yBAAyB,EAAE,OAAO,QAAQ,SAAS,KAAM;AAClE,WAAO;AAAA,EACT,QAAQ;AAAA,EAER;AAGA,MAAI;AACF,aAAS,6BAA6B,EAAE,OAAO,QAAQ,SAAS,KAAO;AACvE,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;"}
1
+ {"version":3,"file":"cultivate.js","sources":["../../../src/cli/commands/cultivate.ts"],"sourcesContent":["/**\n * Cultivate Command - Systematically enhance the knowledge graph\n *\n * This command provides cultivation tasks:\n * - Seed primitives from codebase analysis\n * - Deep analysis with claude-flow integration\n * - Graph enhancement and optimization\n *\n * @module cli/commands/cultivate\n */\n\nimport { Command } from 'commander';\nimport chalk from 'chalk';\nimport { resolve, join, relative } from 'path';\nimport { existsSync, mkdirSync, readFileSync, readdirSync, statSync } from 'fs';\nimport { SeedGenerator } from '../../cultivation/seed-generator.js';\nimport { ShadowCache, loadShadowCache } from '../../core/cache.js';\nimport type { CultivationOptions, Ecosystem, SeedAnalysis } from '../../cultivation/types.js';\n\n/**\n * Cultivation result\n */\ninterface CultivationResult {\n success: boolean;\n seed: {\n created: number;\n documents: Array<{ title: string; path: string; type: string }>;\n };\n analysis: {\n filesProcessed: number;\n dependenciesFound: number;\n servicesFound: number;\n };\n cache: {\n updated: number;\n hits: number;\n misses: number;\n };\n duration: number;\n warnings: string[];\n errors: string[];\n}\n\n/**\n * Create cultivate command\n */\nexport function createCultivateCommand(): Command {\n return new Command('cultivate')\n .description('Systematically cultivate and enhance the knowledge graph')\n .argument('[path]', 'Directory to cultivate (defaults to current directory)', '.')\n .option('--dry-run', 'Preview changes without executing', false)\n .option('-d, --docs <path>', 'Documentation path', 'docs')\n .option('-v, --verbose', 'Verbose output', false)\n .option('--seed', 'Bootstrap vault with primitives from codebase analysis', false)\n .option('--deep-analysis', 'Use claude-flow agents for deep analysis', false)\n .option('--cache', 'Use shadow cache for incremental updates', true)\n .option('--ecosystem <ecosystems>', 'Filter to specific ecosystems (comma-separated)', undefined)\n .option('--include-dev', 'Include dev dependencies', false)\n .option('--major-only', 'Only process major dependencies', false)\n .option('--refresh-cache', 'Force refresh the shadow cache', false)\n .action(async (targetPath: string, options: {\n dryRun?: boolean;\n docs?: string;\n verbose?: boolean;\n seed?: boolean;\n deepAnalysis?: boolean;\n cache?: boolean;\n ecosystem?: string;\n includeDev?: boolean;\n majorOnly?: boolean;\n refreshCache?: boolean;\n }) => {\n const projectRoot = resolve(targetPath);\n const docsPath = options.docs || 'docs';\n const verbose = options.verbose || false;\n const dryRun = options.dryRun || false;\n\n console.log(chalk.bold.green('\\n🌱 Knowledge Graph Cultivator\\n'));\n console.log(` Project: ${projectRoot}`);\n console.log(` Docs: ${docsPath}`);\n if (dryRun) {\n console.log(` Mode: ${chalk.yellow('Dry Run')}`);\n }\n console.log('');\n\n // Determine tasks\n const tasks = {\n seed: options.seed || false,\n deepAnalysis: options.deepAnalysis || false,\n };\n\n // If no tasks selected, show help\n if (!tasks.seed && !tasks.deepAnalysis) {\n console.log(chalk.yellow('šŸ’” No tasks selected. Use one or more of:'));\n console.log(' --seed Bootstrap vault with primitives from codebase');\n console.log(' --deep-analysis Use claude-flow for deep codebase analysis');\n console.log('');\n console.log(chalk.gray('Options:'));\n console.log(' --dry-run Preview without writing files');\n console.log(' --cache Use shadow cache for incremental updates (default: true)');\n console.log(' --refresh-cache Force refresh the shadow cache');\n console.log(' --ecosystem Filter to ecosystems (nodejs,python,rust,go,php,java)');\n console.log(' --include-dev Include dev dependencies');\n console.log(' --major-only Only process major dependencies');\n console.log('');\n console.log('Run \"kg cultivate --help\" for more options');\n return;\n }\n\n const startTime = Date.now();\n const result: CultivationResult = {\n success: true,\n seed: { created: 0, documents: [] },\n analysis: { filesProcessed: 0, dependenciesFound: 0, servicesFound: 0 },\n cache: { updated: 0, hits: 0, misses: 0 },\n duration: 0,\n warnings: [],\n errors: [],\n };\n\n try {\n // Initialize shadow cache\n let cache: ShadowCache | undefined;\n if (options.cache !== false) {\n console.log(chalk.cyan('šŸ“¦ Initializing shadow cache...'));\n cache = await loadShadowCache(projectRoot);\n\n if (options.refreshCache) {\n cache.clear();\n console.log(chalk.gray(' Cache cleared (refresh mode)'));\n }\n\n const stats = cache.getStats();\n console.log(chalk.gray(` Entries: ${stats.totalEntries}, Hit rate: ${(stats.hitRate * 100).toFixed(1)}%`));\n console.log('');\n }\n\n // Task 1: Seed primitives\n if (tasks.seed) {\n console.log(chalk.cyan('🌱 Seeding primitives from codebase...\\n'));\n\n // Parse ecosystem filter\n let ecosystems: Ecosystem[] | undefined;\n if (options.ecosystem) {\n ecosystems = options.ecosystem.split(',').map(e => e.trim() as Ecosystem);\n console.log(chalk.gray(` Ecosystems: ${ecosystems.join(', ')}`));\n }\n\n // Create generator\n const generator = await SeedGenerator.create(projectRoot, docsPath);\n\n // Analyze\n console.log(chalk.gray(' Analyzing codebase...'));\n const analysis = await generator.analyze();\n\n result.analysis = {\n filesProcessed: analysis.metadata.filesScanned,\n dependenciesFound: analysis.dependencies.length,\n servicesFound: analysis.services.length,\n };\n\n // Display analysis\n console.log(`\\n ${chalk.bold('Analysis Results:')}`);\n console.log(` Languages: ${analysis.languages.join(', ') || 'none'}`);\n console.log(` Dependencies: ${analysis.dependencies.length}`);\n console.log(` Frameworks: ${analysis.frameworks.length}`);\n console.log(` Services: ${analysis.services.length}`);\n console.log(` Deployments: ${analysis.deployments.length}`);\n\n if (verbose) {\n displayDetailedAnalysis(analysis);\n }\n\n console.log('');\n\n // Generate primitives\n console.log(chalk.gray(' Generating primitive nodes...'));\n const documents = await generator.generatePrimitives(analysis);\n\n if (dryRun) {\n console.log(`\\n ${chalk.yellow('[DRY RUN]')} Would create ${documents.length} primitives:`);\n for (const doc of documents.slice(0, 10)) {\n console.log(` - ${doc.frontmatter.type}: ${doc.title}`);\n }\n if (documents.length > 10) {\n console.log(` ... and ${documents.length - 10} more`);\n }\n result.seed.documents = documents.map(d => ({\n title: d.title,\n path: d.path,\n type: d.frontmatter.type || 'unknown',\n }));\n } else {\n const writeResult = await generator.writePrimitives(documents);\n result.seed.created = writeResult.documentsGenerated.length;\n result.seed.documents = writeResult.documentsGenerated;\n\n console.log(`\\n ${chalk.green('āœ“')} Created ${writeResult.documentsGenerated.length} primitives`);\n\n if (writeResult.warnings.length > 0) {\n result.warnings.push(...writeResult.warnings);\n if (verbose) {\n console.log(chalk.yellow(` Warnings: ${writeResult.warnings.length}`));\n }\n }\n\n if (writeResult.errors.length > 0) {\n result.errors.push(...writeResult.errors);\n console.log(chalk.red(` Errors: ${writeResult.errors.length}`));\n }\n }\n\n console.log('');\n }\n\n // Task 2: Deep Analysis\n if (tasks.deepAnalysis) {\n console.log(chalk.cyan('🧠 Running deep analysis...\\n'));\n\n // Import and check DeepAnalyzer availability\n const { DeepAnalyzer } = await import('../../cultivation/deep-analyzer.js');\n const analyzer = new DeepAnalyzer({\n projectRoot,\n docsPath,\n verbose,\n });\n\n const availability = await analyzer.getAvailabilityStatus();\n\n if (!availability.available) {\n console.log(chalk.yellow(' āš ļø Deep analysis unavailable'));\n console.log(chalk.gray(` ${availability.reason}`));\n console.log('');\n console.log(chalk.gray(' Options:'));\n console.log(chalk.gray(' 1. Run from a regular terminal (outside Claude Code)'));\n console.log(chalk.gray(' 2. Set ANTHROPIC_API_KEY environment variable'));\n result.warnings.push(`Deep analysis unavailable: ${availability.reason}`);\n } else {\n console.log(chalk.gray(` Mode: ${availability.reason}`));\n\n if (dryRun) {\n console.log(chalk.yellow('\\n [DRY RUN] Would run analysis agents:'));\n console.log(' - Pattern Researcher: Analyze codebase architecture');\n console.log(' - Code Analyst: Identify quality issues');\n console.log(' - Implementation Reviewer: Review code patterns');\n console.log(' - Test Analyzer: Analyze test coverage');\n } else {\n try {\n const deepResult = await analyzer.analyze();\n\n if (deepResult.success) {\n console.log(`\\n ${chalk.green('āœ“')} Deep analysis complete`);\n console.log(` Agents spawned: ${deepResult.agentsSpawned}`);\n console.log(` Insights generated: ${deepResult.insightsCount}`);\n console.log(` Documentation created: ${deepResult.documentsCreated}`);\n console.log(` Mode: ${deepResult.mode}`);\n } else {\n console.log(`\\n ${chalk.yellow('⚠')} Deep analysis completed with issues`);\n console.log(` Agents spawned: ${deepResult.agentsSpawned}`);\n console.log(` Insights generated: ${deepResult.insightsCount}`);\n if (deepResult.errors.length > 0) {\n for (const err of deepResult.errors.slice(0, 3)) {\n console.log(chalk.gray(` - ${err}`));\n }\n }\n result.warnings.push(...deepResult.errors);\n }\n } catch (error) {\n result.errors.push(`Deep analysis failed: ${error instanceof Error ? error.message : String(error)}`);\n console.log(chalk.red(` āœ— Deep analysis failed: ${error instanceof Error ? error.message : String(error)}`));\n }\n }\n }\n\n console.log('');\n }\n\n // Update cache\n if (cache) {\n const stats = cache.getStats();\n result.cache = {\n updated: stats.totalEntries,\n hits: stats.hitCount,\n misses: stats.missCount,\n };\n\n await cache.save();\n }\n\n result.duration = Date.now() - startTime;\n result.success = result.errors.length === 0;\n\n // Final summary\n displaySummary(result, dryRun);\n\n } catch (error) {\n console.error(chalk.red('\\nāŒ Cultivation failed:'), error);\n process.exit(1);\n }\n });\n}\n\n/**\n * Display detailed analysis output\n */\nfunction displayDetailedAnalysis(analysis: SeedAnalysis): void {\n if (analysis.frameworks.length > 0) {\n console.log(`\\n ${chalk.gray('Frameworks:')}`);\n for (const fw of analysis.frameworks) {\n console.log(` - ${fw.name} (${fw.ecosystem}) v${fw.version}`);\n }\n }\n\n if (analysis.services.length > 0) {\n console.log(`\\n ${chalk.gray('Services:')}`);\n for (const svc of analysis.services) {\n console.log(` - ${svc.name}: ${svc.type} (${svc.technology})`);\n }\n }\n\n if (analysis.deployments.length > 0) {\n console.log(`\\n ${chalk.gray('Deployments:')}`);\n for (const dep of analysis.deployments) {\n console.log(` - ${dep}`);\n }\n }\n}\n\n/**\n * Display cultivation summary\n */\nfunction displaySummary(result: CultivationResult, dryRun: boolean): void {\n console.log(chalk.bold.blue('šŸ“Š Cultivation Summary\\n'));\n\n if (dryRun) {\n console.log(chalk.yellow('[DRY RUN] No changes were made\\n'));\n }\n\n console.log(' Analysis:');\n console.log(` Files processed: ${result.analysis.filesProcessed}`);\n console.log(` Dependencies: ${result.analysis.dependenciesFound}`);\n console.log(` Services: ${result.analysis.servicesFound}`);\n\n if (result.seed.created > 0 || result.seed.documents.length > 0) {\n console.log('\\n Seed:');\n console.log(` Primitives ${dryRun ? 'would create' : 'created'}: ${dryRun ? result.seed.documents.length : result.seed.created}`);\n }\n\n if (result.cache.updated > 0) {\n console.log('\\n Cache:');\n console.log(` Entries: ${result.cache.updated}`);\n const hitRate = result.cache.hits + result.cache.misses > 0\n ? (result.cache.hits / (result.cache.hits + result.cache.misses) * 100).toFixed(1)\n : 0;\n console.log(` Hit rate: ${hitRate}%`);\n }\n\n console.log(`\\n Duration: ${(result.duration / 1000).toFixed(2)}s`);\n\n if (result.warnings.length > 0) {\n console.log(chalk.yellow(`\\n āš ļø Warnings: ${result.warnings.length}`));\n for (const warning of result.warnings.slice(0, 5)) {\n console.log(chalk.gray(` - ${warning}`));\n }\n }\n\n if (result.errors.length > 0) {\n console.log(chalk.red(`\\n āŒ Errors: ${result.errors.length}`));\n for (const error of result.errors.slice(0, 5)) {\n console.log(chalk.gray(` - ${error}`));\n }\n }\n\n if (result.success && !dryRun) {\n console.log(chalk.bold.green('\\n✨ Cultivation complete!\\n'));\n } else if (!result.success) {\n console.log(chalk.yellow('\\nāš ļø Cultivation completed with errors\\n'));\n } else {\n console.log(chalk.gray('\\nRun without --dry-run to apply changes\\n'));\n }\n}\n\n"],"names":[],"mappings":";;;;;AA8CO,SAAS,yBAAkC;AAChD,SAAO,IAAI,QAAQ,WAAW,EAC3B,YAAY,0DAA0D,EACtE,SAAS,UAAU,0DAA0D,GAAG,EAChF,OAAO,aAAa,qCAAqC,KAAK,EAC9D,OAAO,qBAAqB,sBAAsB,MAAM,EACxD,OAAO,iBAAiB,kBAAkB,KAAK,EAC/C,OAAO,UAAU,0DAA0D,KAAK,EAChF,OAAO,mBAAmB,4CAA4C,KAAK,EAC3E,OAAO,WAAW,4CAA4C,IAAI,EAClE,OAAO,4BAA4B,mDAAmD,MAAS,EAC/F,OAAO,iBAAiB,4BAA4B,KAAK,EACzD,OAAO,gBAAgB,mCAAmC,KAAK,EAC/D,OAAO,mBAAmB,kCAAkC,KAAK,EACjE,OAAO,OAAO,YAAoB,YAW7B;AACJ,UAAM,cAAc,QAAQ,UAAU;AACtC,UAAM,WAAW,QAAQ,QAAQ;AACjC,UAAM,UAAU,QAAQ,WAAW;AACnC,UAAM,S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AE;AAClD,UAAM,UAAU,OAAO,MAAM,OAAO,OAAO,MAAM,SAAS,KACrD,OAAO,MAAM,QAAQ,OAAO,MAAM,OAAO,OAAO,MAAM,UAAU,KAAK,QAAQ,CAAC,IAC/E;AACJ,YAAQ,IAAI,iBAAiB,OAAO,GAAG;AAAA,EACzC;AAEA,UAAQ,IAAI;AAAA,eAAkB,OAAO,WAAW,KAAM,QAAQ,CAAC,CAAC,GAAG;AAEnE,MAAI,OAAO,SAAS,SAAS,GAAG;AAC9B,YAAQ,IAAI,MAAM,OAAO;AAAA,kBAAqB,OAAO,SAAS,MAAM,EAAE,CAAC;AACvE,eAAW,WAAW,OAAO,SAAS,MAAM,GAAG,CAAC,GAAG;AACjD,cAAQ,IAAI,MAAM,KAAK,SAAS,OAAO,EAAE,CAAC;AAAA,IAC5C;AAAA,EACF;AAEA,MAAI,OAAO,OAAO,SAAS,GAAG;AAC5B,YAAQ,IAAI,MAAM,IAAI;AAAA,cAAiB,OAAO,OAAO,MAAM,EAAE,CAAC;AAC9D,eAAW,SAAS,OAAO,OAAO,MAAM,GAAG,CAAC,GAAG;AAC7C,cAAQ,IAAI,MAAM,KAAK,SAAS,KAAK,EAAE,CAAC;AAAA,IAC1C;AAAA,EACF;AAEA,MAAI,OAAO,WAAW,CAAC,QAAQ;AAC7B,YAAQ,IAAI,MAAM,KAAK,MAAM,6BAA6B,CAAC;AAAA,EAC7D,WAAW,CAAC,OAAO,SAAS;AAC1B,YAAQ,IAAI,MAAM,OAAO,2CAA2C,CAAC;AAAA,EACvE,OAAO;AACL,YAAQ,IAAI,MAAM,KAAK,4CAA4C,CAAC;AAAA,EACtE;AACF;"}
@@ -1,10 +1,10 @@
1
1
  /**
2
- * DeepAnalyzer - Claude-Flow Integration for Deep Codebase Analysis
2
+ * DeepAnalyzer - Deep Codebase Analysis
3
3
  *
4
- * Uses claude-flow agents for comprehensive codebase analysis:
5
- * - Pattern detection and architectural insights
6
- * - Documentation gap analysis
7
- * - Standards compliance checking
4
+ * Provides comprehensive codebase analysis using:
5
+ * - Claude CLI (`claude -p`) when running outside Claude Code
6
+ * - Direct Anthropic API when ANTHROPIC_API_KEY is available
7
+ * - Clear error messaging when neither option is available
8
8
  *
9
9
  * @module cultivation/deep-analyzer
10
10
  */
@@ -26,6 +26,8 @@ export interface DeepAnalyzerOptions {
26
26
  agentMode?: 'sequential' | 'parallel' | 'adaptive';
27
27
  /** Timeout for each agent (ms) */
28
28
  agentTimeout?: number;
29
+ /** Force use of API key even if CLI is available */
30
+ forceApiKey?: boolean;
29
31
  }
30
32
  /**
31
33
  * Analysis result from an agent
@@ -53,9 +55,10 @@ export interface DeepAnalysisResult {
53
55
  results: AgentResult[];
54
56
  duration: number;
55
57
  errors: string[];
58
+ mode: 'cli' | 'api' | 'static';
56
59
  }
57
60
  /**
58
- * DeepAnalyzer - Uses claude-flow for deep codebase analysis
61
+ * DeepAnalyzer - Deep codebase analysis with multiple execution modes
59
62
  *
60
63
  * @example
61
64
  * ```typescript
@@ -76,46 +79,59 @@ export declare class DeepAnalyzer {
76
79
  private maxAgents;
77
80
  private agentMode;
78
81
  private agentTimeout;
79
- private claudeFlowCommand;
82
+ private forceApiKey;
80
83
  constructor(options: DeepAnalyzerOptions);
81
84
  /**
82
- * Check if claude-flow is available and determine the best command to use
83
- * Checks for direct command first (globally installed), then falls back to npx
85
+ * Check if running inside a Claude Code session
84
86
  */
85
- isAvailable(): Promise<boolean>;
87
+ private isInsideClaudeCode;
86
88
  /**
87
- * Detect which claude-flow command to use
88
- * Returns the command configuration or null if not available
89
+ * Check if Anthropic API key is available
89
90
  */
90
- private detectClaudeFlowCommand;
91
+ private hasApiKey;
91
92
  /**
92
- * Run deep analysis
93
+ * Check if Claude CLI is available
93
94
  */
94
- analyze(): Promise<DeepAnalysisResult>;
95
+ private isCliAvailable;
95
96
  /**
96
- * Execute agents in parallel
97
+ * Determine the best execution mode
97
98
  */
98
- private executeParallel;
99
+ private detectExecutionMode;
99
100
  /**
100
- * Execute agents sequentially
101
+ * Check if analysis is available
101
102
  */
102
- private executeSequential;
103
+ isAvailable(): Promise<boolean>;
103
104
  /**
104
- * Execute agents adaptively (start with 2, scale based on success)
105
+ * Get availability status with reason
105
106
  */
106
- private executeAdaptive;
107
+ getAvailabilityStatus(): Promise<{
108
+ available: boolean;
109
+ reason: string;
110
+ }>;
111
+ /**
112
+ * Run deep analysis
113
+ */
114
+ analyze(): Promise<DeepAnalysisResult>;
107
115
  /**
108
116
  * Execute a single agent
109
117
  */
110
118
  private executeAgent;
111
119
  /**
112
- * Build prompt for agent
120
+ * Build context-aware prompt for analysis
113
121
  */
114
122
  private buildPrompt;
115
123
  /**
116
- * Run claude-flow agent
124
+ * Gather project context for analysis
125
+ */
126
+ private gatherProjectContext;
127
+ /**
128
+ * Run analysis using Claude CLI
129
+ */
130
+ private runWithCli;
131
+ /**
132
+ * Run analysis using Anthropic API directly
117
133
  */
118
- private runClaudeFlowAgent;
134
+ private runWithApi;
119
135
  /**
120
136
  * Extract insights from agent output
121
137
  */
@@ -1 +1 @@
1
- {"version":3,"file":"deep-analyzer.d.ts","sourceRoot":"","sources":["../../src/cultivation/deep-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAsBH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8BAA8B;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,YAAY,GAAG,UAAU,GAAG,UAAU,CAAC;IACnD,kCAAkC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,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4BrB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAE7E;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,WAAW,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,kBAAkB,CAAC,CAG7B"}
@@ -1,17 +1,8 @@
1
- import { execFileSync, spawn } from "child_process";
2
- import { existsSync, mkdirSync, writeFileSync } from "fs";
1
+ import { execFileSync, execSync } from "child_process";
2
+ import { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync } from "fs";
3
3
  import { resolve, join } from "path";
4
4
  import { createLogger } from "../utils/logger.js";
5
5
  const logger = createLogger("deep-analyzer");
6
- const VALID_AGENT_TYPES = /* @__PURE__ */ new Set([
7
- "researcher",
8
- "architect",
9
- "analyst",
10
- "coder",
11
- "tester",
12
- "reviewer",
13
- "documenter"
14
- ]);
15
6
  class DeepAnalyzer {
16
7
  projectRoot;
17
8
  docsPath;
@@ -20,7 +11,7 @@ class DeepAnalyzer {
20
11
  maxAgents;
21
12
  agentMode;
22
13
  agentTimeout;
23
- claudeFlowCommand = null;
14
+ forceApiKey;
24
15
  constructor(options) {
25
16
  this.projectRoot = resolve(options.projectRoot);
26
17
  this.docsPath = options.docsPath || "docs";
@@ -28,51 +19,92 @@ class DeepAnalyzer {
28
19
  this.verbose = options.verbose || false;
29
20
  this.maxAgents = options.maxAgents || 5;
30
21
  this.agentMode = options.agentMode || "adaptive";
31
- this.agentTimeout = options.agentTimeout || 6e4;
22
+ this.agentTimeout = options.agentTimeout || 12e4;
23
+ this.forceApiKey = options.forceApiKey || false;
32
24
  }
33
25
  /**
34
- * Check if claude-flow is available and determine the best command to use
35
- * Checks for direct command first (globally installed), then falls back to npx
26
+ * Check if running inside a Claude Code session
36
27
  */
37
- async isAvailable() {
38
- const command = await this.detectClaudeFlowCommand();
39
- return command !== null;
28
+ isInsideClaudeCode() {
29
+ return process.env.CLAUDECODE === "1" || process.env.CLAUDE_CODE === "1";
40
30
  }
41
31
  /**
42
- * Detect which claude-flow command to use
43
- * Returns the command configuration or null if not available
32
+ * Check if Anthropic API key is available
44
33
  */
45
- async detectClaudeFlowCommand() {
46
- if (this.claudeFlowCommand !== null) {
47
- return this.claudeFlowCommand;
48
- }
34
+ hasApiKey() {
35
+ return !!process.env.ANTHROPIC_API_KEY;
36
+ }
37
+ /**
38
+ * Check if Claude CLI is available
39
+ */
40
+ isCliAvailable() {
49
41
  try {
50
- execFileSync("claude-flow", ["--version"], {
42
+ execFileSync("claude", ["--version"], {
51
43
  stdio: "pipe",
52
44
  timeout: 5e3,
53
45
  windowsHide: true
54
46
  });
55
- this.claudeFlowCommand = { cmd: "claude-flow", args: [] };
56
- return this.claudeFlowCommand;
47
+ return true;
57
48
  } catch {
49
+ return false;
58
50
  }
59
- try {
60
- execFileSync("npx", ["claude-flow", "--version"], {
61
- stdio: "pipe",
62
- timeout: 3e4,
63
- windowsHide: true
64
- });
65
- this.claudeFlowCommand = { cmd: "npx", args: ["claude-flow"] };
66
- return this.claudeFlowCommand;
67
- } catch {
68
- return null;
51
+ }
52
+ /**
53
+ * Determine the best execution mode
54
+ */
55
+ detectExecutionMode() {
56
+ const insideClaudeCode = this.isInsideClaudeCode();
57
+ const hasApiKey = this.hasApiKey();
58
+ const cliAvailable = this.isCliAvailable();
59
+ if (this.forceApiKey) {
60
+ if (hasApiKey) {
61
+ return { mode: "api", reason: "Using API key (forced)" };
62
+ }
63
+ return { mode: "unavailable", reason: "ANTHROPIC_API_KEY not set (required when forceApiKey=true)" };
64
+ }
65
+ if (insideClaudeCode) {
66
+ if (hasApiKey) {
67
+ return { mode: "api", reason: "Using API key (inside Claude Code session)" };
68
+ }
69
+ return {
70
+ mode: "unavailable",
71
+ reason: "Cannot run deep analysis inside Claude Code session without ANTHROPIC_API_KEY. Either set ANTHROPIC_API_KEY environment variable, or run this command from a regular terminal."
72
+ };
73
+ }
74
+ if (cliAvailable) {
75
+ return { mode: "cli", reason: "Using Claude CLI" };
76
+ }
77
+ if (hasApiKey) {
78
+ return { mode: "api", reason: "Using API key (CLI not available)" };
69
79
  }
80
+ return {
81
+ mode: "unavailable",
82
+ reason: "Claude CLI not found. Install Claude Code (https://claude.ai/code) or set ANTHROPIC_API_KEY."
83
+ };
84
+ }
85
+ /**
86
+ * Check if analysis is available
87
+ */
88
+ async isAvailable() {
89
+ const mode = this.detectExecutionMode();
90
+ return mode.mode !== "unavailable";
91
+ }
92
+ /**
93
+ * Get availability status with reason
94
+ */
95
+ async getAvailabilityStatus() {
96
+ const mode = this.detectExecutionMode();
97
+ return {
98
+ available: mode.mode !== "unavailable",
99
+ reason: mode.reason
100
+ };
70
101
  }
71
102
  /**
72
103
  * Run deep analysis
73
104
  */
74
105
  async analyze() {
75
106
  const startTime = Date.now();
107
+ const executionMode = this.detectExecutionMode();
76
108
  const result = {
77
109
  success: false,
78
110
  agentsSpawned: 0,
@@ -80,13 +112,16 @@ class DeepAnalyzer {
80
112
  documentsCreated: 0,
81
113
  results: [],
82
114
  duration: 0,
83
- errors: []
115
+ errors: [],
116
+ mode: executionMode.mode === "unavailable" ? "static" : executionMode.mode
84
117
  };
85
- if (!await this.isAvailable()) {
86
- result.errors.push("claude-flow is not available");
118
+ if (executionMode.mode === "unavailable") {
119
+ result.errors.push(executionMode.reason);
87
120
  result.duration = Date.now() - startTime;
121
+ logger.error("Deep analysis unavailable", new Error(executionMode.reason));
88
122
  return result;
89
123
  }
124
+ logger.info(`Starting deep analysis`, { mode: executionMode.mode, reason: executionMode.reason });
90
125
  if (!existsSync(this.outputDir)) {
91
126
  mkdirSync(this.outputDir, { recursive: true });
92
127
  }
@@ -116,18 +151,15 @@ class DeepAnalyzer {
116
151
  outputFile: "testing-analysis.md"
117
152
  }
118
153
  ];
119
- logger.info("Starting deep analysis", { agents: agents.length, mode: this.agentMode });
120
- if (this.agentMode === "parallel") {
121
- result.results = await this.executeParallel(agents);
122
- } else if (this.agentMode === "sequential") {
123
- result.results = await this.executeSequential(agents);
124
- } else {
125
- result.results = await this.executeAdaptive(agents);
154
+ logger.info("Executing analysis agents", { agents: agents.length, mode: "sequential" });
155
+ for (const agent of agents) {
156
+ const agentResult = await this.executeAgent(agent, executionMode.mode);
157
+ result.results.push(agentResult);
126
158
  }
127
159
  result.agentsSpawned = result.results.length;
128
160
  result.insightsCount = result.results.reduce((sum, r) => sum + r.insights.length, 0);
129
161
  result.documentsCreated = result.results.reduce((sum, r) => sum + r.documents.length, 0);
130
- result.success = result.results.every((r) => r.success);
162
+ result.success = result.results.some((r) => r.success);
131
163
  result.duration = Date.now() - startTime;
132
164
  for (const agentResult of result.results) {
133
165
  if (agentResult.error) {
@@ -142,48 +174,10 @@ class DeepAnalyzer {
142
174
  });
143
175
  return result;
144
176
  }
145
- /**
146
- * Execute agents in parallel
147
- */
148
- async executeParallel(agents) {
149
- const promises = agents.map((agent) => this.executeAgent(agent));
150
- return Promise.all(promises);
151
- }
152
- /**
153
- * Execute agents sequentially
154
- */
155
- async executeSequential(agents) {
156
- const results = [];
157
- for (const agent of agents) {
158
- results.push(await this.executeAgent(agent));
159
- }
160
- return results;
161
- }
162
- /**
163
- * Execute agents adaptively (start with 2, scale based on success)
164
- */
165
- async executeAdaptive(agents) {
166
- const results = [];
167
- const firstBatch = agents.slice(0, 2);
168
- const firstResults = await Promise.all(firstBatch.map((a) => this.executeAgent(a)));
169
- results.push(...firstResults);
170
- const successRate = firstResults.filter((r) => r.success).length / firstResults.length;
171
- if (successRate >= 0.5 && agents.length > 2) {
172
- const remaining = agents.slice(2);
173
- const remainingResults = await Promise.all(remaining.map((a) => this.executeAgent(a)));
174
- results.push(...remainingResults);
175
- } else if (agents.length > 2) {
176
- logger.warn("Low success rate, switching to sequential mode");
177
- for (const agent of agents.slice(2)) {
178
- results.push(await this.executeAgent(agent));
179
- }
180
- }
181
- return results;
182
- }
183
177
  /**
184
178
  * Execute a single agent
185
179
  */
186
- async executeAgent(agent) {
180
+ async executeAgent(agent, mode) {
187
181
  const startTime = Date.now();
188
182
  const outputPath = join(this.outputDir, agent.outputFile);
189
183
  const result = {
@@ -195,9 +189,14 @@ class DeepAnalyzer {
195
189
  duration: 0
196
190
  };
197
191
  try {
198
- logger.info(`Spawning agent: ${agent.name}`, { type: agent.type });
192
+ logger.info(`Executing agent: ${agent.name}`, { type: agent.type, mode });
199
193
  const prompt = this.buildPrompt(agent);
200
- const output = await this.runClaudeFlowAgent(agent.type, prompt);
194
+ let output;
195
+ if (mode === "cli") {
196
+ output = await this.runWithCli(prompt);
197
+ } else {
198
+ output = await this.runWithApi(prompt);
199
+ }
201
200
  result.insights = this.extractInsights(output);
202
201
  writeFileSync(outputPath, this.formatOutput(agent, output));
203
202
  result.documents.push({ path: outputPath, title: agent.name });
@@ -213,76 +212,122 @@ class DeepAnalyzer {
213
212
  return result;
214
213
  }
215
214
  /**
216
- * Build prompt for agent
215
+ * Build context-aware prompt for analysis
217
216
  */
218
217
  buildPrompt(agent) {
219
- return `You are a ${agent.name} analyzing the project at ${this.projectRoot}.
220
-
221
- **OBJECTIVE**: ${agent.task}
218
+ const context = this.gatherProjectContext();
219
+ return `You are analyzing a codebase. Here is the project context:
222
220
 
223
- **COORDINATION PROTOCOL**:
224
- \`\`\`bash
225
- claude-flow hooks pre-task --description "${agent.task}"
226
- \`\`\`
221
+ ${context}
227
222
 
228
- **YOUR TASKS**:
229
- 1. Analyze the codebase at ${this.projectRoot}
230
- 2. Identify key patterns and conventions
231
- 3. Document your findings with specific examples
232
- 4. Provide actionable recommendations
233
- 5. Generate comprehensive markdown documentation
223
+ Task: ${agent.task}
234
224
 
235
- **OUTPUT REQUIREMENTS**:
236
- - Use clear markdown formatting
237
- - Include code examples from the project
238
- - Organize findings by category
239
- - Prioritize actionable insights
225
+ Provide your findings in markdown format with:
226
+ 1. Key observations (prefix with "Observation:")
227
+ 2. Specific recommendations (prefix with "Recommendation:")
228
+ 3. Any potential issues found (prefix with "Finding:")
240
229
 
241
- After completing:
242
- \`\`\`bash
243
- claude-flow hooks post-task --task-id "${agent.type}-analysis"
244
- \`\`\`
245
- `;
230
+ Be specific and actionable in your analysis.`;
246
231
  }
247
232
  /**
248
- * Run claude-flow agent
233
+ * Gather project context for analysis
249
234
  */
250
- async runClaudeFlowAgent(type, prompt) {
251
- if (!VALID_AGENT_TYPES.has(type)) {
252
- throw new Error(`Invalid agent type: ${type}. Valid types: ${[...VALID_AGENT_TYPES].join(", ")}`);
235
+ gatherProjectContext() {
236
+ const lines = [];
237
+ const packageJsonPath = join(this.projectRoot, "package.json");
238
+ if (existsSync(packageJsonPath)) {
239
+ try {
240
+ const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
241
+ lines.push(`Project: ${pkg.name || "Unknown"} v${pkg.version || "0.0.0"}`);
242
+ lines.push(`Description: ${pkg.description || "No description"}`);
243
+ if (pkg.dependencies) {
244
+ const deps = Object.keys(pkg.dependencies).slice(0, 10);
245
+ lines.push(`Key dependencies: ${deps.join(", ")}`);
246
+ }
247
+ } catch {
248
+ }
253
249
  }
254
- const sanitizedPrompt = prompt.replace(/[`$\\]/g, "");
255
- const commandConfig = await this.detectClaudeFlowCommand();
256
- if (!commandConfig) {
257
- throw new Error("claude-flow is not available");
250
+ try {
251
+ const entries = readdirSync(this.projectRoot, { withFileTypes: true });
252
+ const dirs = entries.filter((e) => e.isDirectory() && !e.name.startsWith(".") && e.name !== "node_modules").map((e) => e.name).slice(0, 10);
253
+ if (dirs.length > 0) {
254
+ lines.push(`Project structure: ${dirs.join(", ")}`);
255
+ }
256
+ } catch {
258
257
  }
259
- return new Promise((resolve2, reject) => {
260
- const args = [...commandConfig.args, "agent", "run", type, sanitizedPrompt];
261
- const proc = spawn(commandConfig.cmd, args, {
258
+ const configFiles = [
259
+ "tsconfig.json",
260
+ "vite.config.ts",
261
+ "vitest.config.ts",
262
+ ".eslintrc.js",
263
+ "Dockerfile"
264
+ ];
265
+ const foundConfigs = configFiles.filter((f) => existsSync(join(this.projectRoot, f)));
266
+ if (foundConfigs.length > 0) {
267
+ lines.push(`Config files: ${foundConfigs.join(", ")}`);
268
+ }
269
+ return lines.join("\n");
270
+ }
271
+ /**
272
+ * Run analysis using Claude CLI
273
+ */
274
+ async runWithCli(prompt) {
275
+ const sanitizedPrompt = prompt.replace(/"/g, '\\"').replace(/[`$]/g, "");
276
+ try {
277
+ const result = execSync(`claude -p "${sanitizedPrompt}"`, {
262
278
  cwd: this.projectRoot,
263
- shell: false,
264
- // Security: Disable shell to prevent command injection
265
- timeout: this.agentTimeout
266
- });
267
- let stdout = "";
268
- let stderr = "";
269
- proc.stdout?.on("data", (data) => {
270
- stdout += data.toString();
271
- });
272
- proc.stderr?.on("data", (data) => {
273
- stderr += data.toString();
279
+ encoding: "utf8",
280
+ timeout: this.agentTimeout,
281
+ maxBuffer: 10 * 1024 * 1024
282
+ // 10MB buffer
274
283
  });
275
- proc.on("close", (code) => {
276
- if (code === 0) {
277
- resolve2(stdout);
278
- } else {
279
- reject(new Error(stderr || `Agent exited with code ${code}`));
284
+ return result;
285
+ } catch (error) {
286
+ if (error instanceof Error) {
287
+ const execError = error;
288
+ if (execError.killed) {
289
+ if (execError.stdout && execError.stdout.length > 100) {
290
+ return execError.stdout;
291
+ }
292
+ throw new Error(`Claude CLI timed out after ${this.agentTimeout / 1e3}s`);
280
293
  }
294
+ throw new Error(execError.stderr || error.message);
295
+ }
296
+ throw error;
297
+ }
298
+ }
299
+ /**
300
+ * Run analysis using Anthropic API directly
301
+ */
302
+ async runWithApi(prompt) {
303
+ const apiKey = process.env.ANTHROPIC_API_KEY;
304
+ if (!apiKey) {
305
+ throw new Error("ANTHROPIC_API_KEY not set");
306
+ }
307
+ try {
308
+ const { default: Anthropic } = await import("@anthropic-ai/sdk");
309
+ const client = new Anthropic({ apiKey });
310
+ const response = await client.messages.create({
311
+ model: "claude-sonnet-4-20250514",
312
+ max_tokens: 4096,
313
+ messages: [
314
+ {
315
+ role: "user",
316
+ content: prompt
317
+ }
318
+ ]
281
319
  });
282
- proc.on("error", (error) => {
283
- reject(error);
284
- });
285
- });
320
+ const textBlock = response.content.find((block) => block.type === "text");
321
+ if (textBlock && textBlock.type === "text") {
322
+ return textBlock.text;
323
+ }
324
+ throw new Error("No text content in API response");
325
+ } catch (error) {
326
+ if (error instanceof Error) {
327
+ throw new Error(`API call failed: ${error.message}`);
328
+ }
329
+ throw error;
330
+ }
286
331
  }
287
332
  /**
288
333
  * Extract insights from agent output
@@ -290,7 +335,7 @@ claude-flow hooks post-task --task-id "${agent.type}-analysis"
290
335
  extractInsights(output) {
291
336
  const insights = [];
292
337
  const patterns = [
293
- /[-*]\s*(?:insight|finding|observation|recommendation):\s*(.+)/gi,
338
+ /[-*]?\s*(?:insight|finding|observation|recommendation):\s*(.+)/gi,
294
339
  /##\s*(?:insight|finding|observation|recommendation):\s*(.+)/gi,
295
340
  /(?:key\s+)?(?:insight|finding|observation|recommendation):\s*(.+)/gi
296
341
  ];
@@ -319,7 +364,7 @@ created: ${timestamp}
319
364
 
320
365
  # ${agent.name} Analysis
321
366
 
322
- > Generated by DeepAnalyzer using claude-flow
367
+ > Generated by DeepAnalyzer
323
368
 
324
369
  ## Overview
325
370
 
@@ -1 +1 @@
1
- {"version":3,"file":"deep-analyzer.js","sources":["../../src/cultivation/deep-analyzer.ts"],"sourcesContent":["/**\n * DeepAnalyzer - Claude-Flow Integration for Deep Codebase Analysis\n *\n * Uses claude-flow agents for comprehensive codebase analysis:\n * - Pattern detection and architectural insights\n * - Documentation gap analysis\n * - Standards compliance checking\n *\n * @module cultivation/deep-analyzer\n */\n\nimport { execFileSync, spawn } from 'child_process';\nimport { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs';\nimport { join, resolve } from 'path';\nimport { createLogger } from '../utils/index.js';\n\nconst logger = createLogger('deep-analyzer');\n\n/**\n * Valid agent types for security validation\n */\nconst VALID_AGENT_TYPES = new Set([\n 'researcher',\n 'architect',\n 'analyst',\n 'coder',\n 'tester',\n 'reviewer',\n 'documenter',\n]);\n\n/**\n * Deep analyzer options\n */\nexport interface DeepAnalyzerOptions {\n /** Project root directory */\n projectRoot: string;\n /** Documentation path (relative to project root) */\n docsPath?: string;\n /** Output directory for analysis results */\n outputDir?: string;\n /** Enable verbose logging */\n verbose?: boolean;\n /** Maximum agents to spawn */\n maxAgents?: number;\n /** Agent execution mode */\n agentMode?: 'sequential' | 'parallel' | 'adaptive';\n /** Timeout for each agent (ms) */\n agentTimeout?: number;\n}\n\n/**\n * Analysis result from an agent\n */\nexport interface AgentResult {\n name: string;\n type: string;\n success: boolean;\n insights: string[];\n documents: Array<{ path: string; title: string }>;\n duration: number;\n error?: string;\n}\n\n/**\n * Deep analysis result\n */\nexport interface DeepAnalysisResult {\n success: boolean;\n agentsSpawned: number;\n insightsCount: number;\n documentsCreated: number;\n results: AgentResult[];\n duration: number;\n errors: string[];\n}\n\n/**\n * Agent configuration\n */\ninterface AgentConfig {\n name: string;\n type: 'researcher' | 'analyst' | 'coder' | 'tester' | 'reviewer';\n task: string;\n outputFile: string;\n}\n\n/**\n * DeepAnalyzer - Uses claude-flow for deep codebase analysis\n *\n * @example\n * ```typescript\n * const analyzer = new DeepAnalyzer({\n * projectRoot: '/my/project',\n * docsPath: 'docs',\n * });\n *\n * const result = await analyzer.analyze();\n * console.log(`Generated ${result.insightsCount} insights`);\n * ```\n */\nexport class DeepAnalyzer {\n private projectRoot: string;\n private docsPath: string;\n private outputDir: string;\n private verbose: boolean;\n private maxAgents: number;\n private agentMode: 'sequential' | 'parallel' | 'adaptive';\n private agentTimeout: number;\n private claudeFlowCommand: { cmd: string; args: string[] } | null = null;\n\n constructor(options: DeepAnalyzerOptions) {\n this.projectRoot = resolve(options.projectRoot);\n this.docsPath = options.docsPath || 'docs';\n this.outputDir = options.outputDir || join(this.projectRoot, this.docsPath, 'analysis');\n this.verbose = options.verbose || false;\n this.maxAgents = options.maxAgents || 5;\n this.agentMode = options.agentMode || 'adaptive';\n // Default timeout of 60 seconds (configurable via agentTimeout option)\n this.agentTimeout = options.agentTimeout || 60000;\n }\n\n /**\n * Check if claude-flow is available and determine the best command to use\n * Checks for direct command first (globally installed), then falls back to npx\n */\n async isAvailable(): Promise<boolean> {\n const command = await this.detectClaudeFlowCommand();\n return command !== null;\n }\n\n /**\n * Detect which claude-flow command to use\n * Returns the command configuration or null if not available\n */\n private async detectClaudeFlowCommand(): Promise<{ cmd: string; args: string[] } | null> {\n // Return cached result if available\n if (this.claudeFlowCommand !== null) {\n return this.claudeFlowCommand;\n }\n\n // First try direct command (globally installed claude-flow)\n try {\n // SECURITY: execFileSync does not spawn a shell by default, preventing shell injection\n execFileSync('claude-flow', ['--version'], {\n stdio: 'pipe',\n timeout: 5000,\n windowsHide: true,\n });\n this.claudeFlowCommand = { cmd: 'claude-flow', args: [] };\n return this.claudeFlowCommand;\n } catch {\n // Direct command not available, try npx\n }\n\n // Fall back to npx\n try {\n execFileSync('npx', ['claude-flow', '--version'], {\n stdio: 'pipe',\n timeout: 30000,\n windowsHide: true,\n });\n this.claudeFlowCommand = { cmd: 'npx', args: ['claude-flow'] };\n return this.claudeFlowCommand;\n } catch {\n return null;\n }\n }\n\n /**\n * Run deep analysis\n */\n async analyze(): Promise<DeepAnalysisResult> {\n const startTime = Date.now();\n\n const result: DeepAnalysisResult = {\n success: false,\n agentsSpawned: 0,\n insightsCount: 0,\n documentsCreated: 0,\n results: [],\n duration: 0,\n errors: [],\n };\n\n // Check availability\n if (!(await this.isAvailable())) {\n result.errors.push('claude-flow is not available');\n result.duration = Date.now() - startTime;\n return result;\n }\n\n // Ensure output directory exists\n if (!existsSync(this.outputDir)) {\n mkdirSync(this.outputDir, { recursive: true });\n }\n\n // Define agents\n const agents: AgentConfig[] = [\n {\n name: 'Pattern Researcher',\n type: 'researcher',\n task: 'Analyze codebase architecture, patterns, and design decisions',\n outputFile: 'architecture-patterns.md',\n },\n {\n name: 'Code Analyst',\n type: 'analyst',\n task: 'Identify code quality issues, complexity hotspots, and improvement opportunities',\n outputFile: 'code-analysis.md',\n },\n {\n name: 'Implementation Reviewer',\n type: 'coder',\n task: 'Review implementation patterns, naming conventions, and code style',\n outputFile: 'implementation-review.md',\n },\n {\n name: 'Test Analyzer',\n type: 'tester',\n task: 'Analyze test coverage, testing patterns, and testing gaps',\n outputFile: 'testing-analysis.md',\n },\n ];\n\n logger.info('Starting deep analysis', { agents: agents.length, mode: this.agentMode });\n\n // Execute agents based on mode\n if (this.agentMode === 'parallel') {\n result.results = await this.executeParallel(agents);\n } else if (this.agentMode === 'sequential') {\n result.results = await this.executeSequential(agents);\n } else {\n // Adaptive: start with 2, scale based on success\n result.results = await this.executeAdaptive(agents);\n }\n\n // Calculate totals\n result.agentsSpawned = result.results.length;\n result.insightsCount = result.results.reduce((sum, r) => sum + r.insights.length, 0);\n result.documentsCreated = result.results.reduce((sum, r) => sum + r.documents.length, 0);\n result.success = result.results.every(r => r.success);\n result.duration = Date.now() - startTime;\n\n // Collect errors\n for (const agentResult of result.results) {\n if (agentResult.error) {\n result.errors.push(`${agentResult.name}: ${agentResult.error}`);\n }\n }\n\n logger.info('Deep analysis complete', {\n success: result.success,\n insights: result.insightsCount,\n documents: result.documentsCreated,\n duration: result.duration,\n });\n\n return result;\n }\n\n /**\n * Execute agents in parallel\n */\n private async executeParallel(agents: AgentConfig[]): Promise<AgentResult[]> {\n const promises = agents.map(agent => this.executeAgent(agent));\n return Promise.all(promises);\n }\n\n /**\n * Execute agents sequentially\n */\n private async executeSequential(agents: AgentConfig[]): Promise<AgentResult[]> {\n const results: AgentResult[] = [];\n for (const agent of agents) {\n results.push(await this.executeAgent(agent));\n }\n return results;\n }\n\n /**\n * Execute agents adaptively (start with 2, scale based on success)\n */\n private async executeAdaptive(agents: AgentConfig[]): Promise<AgentResult[]> {\n const results: AgentResult[] = [];\n\n // First batch: 2 agents\n const firstBatch = agents.slice(0, 2);\n const firstResults = await Promise.all(firstBatch.map(a => this.executeAgent(a)));\n results.push(...firstResults);\n\n // Check success rate\n const successRate = firstResults.filter(r => r.success).length / firstResults.length;\n\n if (successRate >= 0.5 && agents.length > 2) {\n // Continue with remaining agents in parallel\n const remaining = agents.slice(2);\n const remainingResults = await Promise.all(remaining.map(a => this.executeAgent(a)));\n results.push(...remainingResults);\n } else if (agents.length > 2) {\n // Fall back to sequential\n logger.warn('Low success rate, switching to sequential mode');\n for (const agent of agents.slice(2)) {\n results.push(await this.executeAgent(agent));\n }\n }\n\n return results;\n }\n\n /**\n * Execute a single agent\n */\n private async executeAgent(agent: AgentConfig): Promise<AgentResult> {\n const startTime = Date.now();\n const outputPath = join(this.outputDir, agent.outputFile);\n\n const result: AgentResult = {\n name: agent.name,\n type: agent.type,\n success: false,\n insights: [],\n documents: [],\n duration: 0,\n };\n\n try {\n logger.info(`Spawning agent: ${agent.name}`, { type: agent.type });\n\n const prompt = this.buildPrompt(agent);\n\n // Execute claude-flow agent\n const output = await this.runClaudeFlowAgent(agent.type, prompt);\n\n // Parse output for insights\n result.insights = this.extractInsights(output);\n\n // Write output to file\n writeFileSync(outputPath, this.formatOutput(agent, output));\n result.documents.push({ path: outputPath, title: agent.name });\n\n result.success = true;\n\n if (this.verbose) {\n logger.debug(`Agent completed: ${agent.name}`, { insights: result.insights.length });\n }\n } catch (error) {\n result.error = error instanceof Error ? error.message : String(error);\n logger.error(`Agent failed: ${agent.name}`, error instanceof Error ? error : new Error(String(error)));\n }\n\n result.duration = Date.now() - startTime;\n return result;\n }\n\n /**\n * Build prompt for agent\n */\n private buildPrompt(agent: AgentConfig): string {\n return `You are a ${agent.name} analyzing the project at ${this.projectRoot}.\n\n**OBJECTIVE**: ${agent.task}\n\n**COORDINATION PROTOCOL**:\n\\`\\`\\`bash\nclaude-flow hooks pre-task --description \"${agent.task}\"\n\\`\\`\\`\n\n**YOUR TASKS**:\n1. Analyze the codebase at ${this.projectRoot}\n2. Identify key patterns and conventions\n3. Document your findings with specific examples\n4. Provide actionable recommendations\n5. Generate comprehensive markdown documentation\n\n**OUTPUT REQUIREMENTS**:\n- Use clear markdown formatting\n- Include code examples from the project\n- Organize findings by category\n- Prioritize actionable insights\n\nAfter completing:\n\\`\\`\\`bash\nclaude-flow hooks post-task --task-id \"${agent.type}-analysis\"\n\\`\\`\\`\n`;\n }\n\n /**\n * Run claude-flow agent\n */\n private async runClaudeFlowAgent(type: string, prompt: string): Promise<string> {\n // Security: Validate agent type against allowlist to prevent command injection\n if (!VALID_AGENT_TYPES.has(type)) {\n throw new Error(`Invalid agent type: ${type}. Valid types: ${[...VALID_AGENT_TYPES].join(', ')}`);\n }\n\n // Security: Sanitize prompt to prevent injection via shell metacharacters\n const sanitizedPrompt = prompt.replace(/[`$\\\\]/g, '');\n\n // Get the detected command configuration\n const commandConfig = await this.detectClaudeFlowCommand();\n if (!commandConfig) {\n throw new Error('claude-flow is not available');\n }\n\n return new Promise((resolve, reject) => {\n // Build args based on detected command\n // claude-flow agent run <type> \"<prompt>\"\n const args = [...commandConfig.args, 'agent', 'run', type, sanitizedPrompt];\n\n const proc = spawn(commandConfig.cmd, args, {\n cwd: this.projectRoot,\n shell: false, // Security: Disable shell to prevent command injection\n timeout: this.agentTimeout,\n });\n\n let stdout = '';\n let stderr = '';\n\n proc.stdout?.on('data', (data) => {\n stdout += data.toString();\n });\n\n proc.stderr?.on('data', (data) => {\n stderr += data.toString();\n });\n\n proc.on('close', (code) => {\n if (code === 0) {\n resolve(stdout);\n } else {\n reject(new Error(stderr || `Agent exited with code ${code}`));\n }\n });\n\n proc.on('error', (error) => {\n reject(error);\n });\n });\n }\n\n /**\n * Extract insights from agent output\n */\n private extractInsights(output: string): string[] {\n const insights: string[] = [];\n\n // Look for patterns like \"- Insight:\" or \"## Finding:\"\n const patterns = [\n /[-*]\\s*(?:insight|finding|observation|recommendation):\\s*(.+)/gi,\n /##\\s*(?:insight|finding|observation|recommendation):\\s*(.+)/gi,\n /(?:key\\s+)?(?:insight|finding|observation|recommendation):\\s*(.+)/gi,\n ];\n\n for (const pattern of patterns) {\n const matches = output.matchAll(pattern);\n for (const match of matches) {\n if (match[1]) {\n insights.push(match[1].trim());\n }\n }\n }\n\n // Deduplicate\n return [...new Set(insights)];\n }\n\n /**\n * Format output for documentation\n */\n private formatOutput(agent: AgentConfig, output: string): string {\n const timestamp = new Date().toISOString();\n\n return `---\ntitle: \"${agent.name} Analysis\"\ntype: analysis\ngenerator: deep-analyzer\nagent: ${agent.type}\ncreated: ${timestamp}\n---\n\n# ${agent.name} Analysis\n\n> Generated by DeepAnalyzer using claude-flow\n\n## Overview\n\n${agent.task}\n\n## Analysis\n\n${output}\n\n---\n\n*Generated on ${new Date().toLocaleString()}*\n`;\n }\n}\n\n/**\n * Create a deep analyzer instance\n */\nexport function createDeepAnalyzer(options: DeepAnalyzerOptions): DeepAnalyzer {\n return new DeepAnalyzer(options);\n}\n\n/**\n * Run deep analysis on a project\n */\nexport async function analyzeDeep(\n projectRoot: string,\n docsPath?: string\n): Promise<DeepAnalysisResult> {\n const analyzer = new DeepAnalyzer({ projectRoot, docsPath });\n return analyzer.analyze();\n}\n"],"names":["resolve"],"mappings":";;;;AAgBA,MAAM,SAAS,aAAa,eAAe;AAK3C,MAAM,wCAAwB,IAAI;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAwEM,MAAM,aAAa;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,oBAA4D;AAAA,EAEpE,YAAY,SAA8B;AACxC,SAAK,cAAc,QAAQ,QAAQ,WAAW;AAC9C,SAAK,WAAW,QAAQ,YAAY;AACpC,SAAK,YAAY,QAAQ,aAAa,KAAK,KAAK,aAAa,KAAK,UAAU,UAAU;AACtF,SAAK,UAAU,QAAQ,WAAW;AAClC,SAAK,YAAY,QAAQ,aAAa;AACtC,SAAK,YAAY,QAAQ,aAAa;AAEtC,SAAK,eAAe,QAAQ,gBAAgB;AAAA,EAC9C;AAAA;AAAA;AAAA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AGF,eAAW,WAAW,UAAU;AAC9B,YAAM,UAAU,OAAO,SAAS,OAAO;AACvC,iBAAW,SAAS,SAAS;AAC3B,YAAI,MAAM,CAAC,GAAG;AACZ,mBAAS,KAAK,MAAM,CAAC,EAAE,MAAM;AAAA,QAC/B;AAAA,MACF;AAAA,IACF;AAGA,WAAO,CAAC,GAAG,IAAI,IAAI,QAAQ,CAAC;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKQ,aAAa,OAAoB,QAAwB;AAC/D,UAAM,aAAY,oBAAI,KAAA,GAAO,YAAA;AAE7B,WAAO;AAAA,UACD,MAAM,IAAI;AAAA;AAAA;AAAA,SAGX,MAAM,IAAI;AAAA,WACR,SAAS;AAAA;AAAA;AAAA,IAGhB,MAAM,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMZ,MAAM,IAAI;AAAA;AAAA;AAAA;AAAA,EAIV,MAAM;AAAA;AAAA;AAAA;AAAA,iBAIQ,oBAAI,QAAO,gBAAgB;AAAA;AAAA,EAEzC;AACF;AAKO,SAAS,mBAAmB,SAA4C;AAC7E,SAAO,IAAI,aAAa,OAAO;AACjC;AAKA,eAAsB,YACpB,aACA,UAC6B;AAC7B,QAAM,WAAW,IAAI,aAAa,EAAE,aAAa,UAAU;AAC3D,SAAO,SAAS,QAAA;AAClB;"}
1
+ {"version":3,"file":"deep-analyzer.js","sources":["../../src/cultivation/deep-analyzer.ts"],"sourcesContent":["/**\n * DeepAnalyzer - Deep Codebase Analysis\n *\n * Provides comprehensive codebase analysis using:\n * - Claude CLI (`claude -p`) when running outside Claude Code\n * - Direct Anthropic API when ANTHROPIC_API_KEY is available\n * - Clear error messaging when neither option is available\n *\n * @module cultivation/deep-analyzer\n */\n\nimport { execFileSync, execSync } from 'child_process';\nimport { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync } from 'fs';\nimport { join, resolve, relative } from 'path';\nimport { createLogger } from '../utils/index.js';\n\nconst logger = createLogger('deep-analyzer');\n\n/**\n * Valid agent types for analysis\n */\nconst VALID_AGENT_TYPES = new Set([\n 'researcher',\n 'architect',\n 'analyst',\n 'coder',\n 'tester',\n 'reviewer',\n 'documenter',\n]);\n\n/**\n * Deep analyzer options\n */\nexport interface DeepAnalyzerOptions {\n /** Project root directory */\n projectRoot: string;\n /** Documentation path (relative to project root) */\n docsPath?: string;\n /** Output directory for analysis results */\n outputDir?: string;\n /** Enable verbose logging */\n verbose?: boolean;\n /** Maximum agents to spawn */\n maxAgents?: number;\n /** Agent execution mode */\n agentMode?: 'sequential' | 'parallel' | 'adaptive';\n /** Timeout for each agent (ms) */\n agentTimeout?: number;\n /** Force use of API key even if CLI is available */\n forceApiKey?: boolean;\n}\n\n/**\n * Analysis result from an agent\n */\nexport interface AgentResult {\n name: string;\n type: string;\n success: boolean;\n insights: string[];\n documents: Array<{ path: string; title: string }>;\n duration: number;\n error?: string;\n}\n\n/**\n * Deep analysis result\n */\nexport interface DeepAnalysisResult {\n success: boolean;\n agentsSpawned: number;\n insightsCount: number;\n documentsCreated: number;\n results: AgentResult[];\n duration: number;\n errors: string[];\n mode: 'cli' | 'api' | 'static';\n}\n\n/**\n * Agent configuration\n */\ninterface AgentConfig {\n name: string;\n type: 'researcher' | 'analyst' | 'coder' | 'tester' | 'reviewer';\n task: string;\n outputFile: string;\n}\n\n/**\n * Execution mode detection result\n */\ninterface ExecutionMode {\n mode: 'cli' | 'api' | 'unavailable';\n reason: string;\n}\n\n/**\n * DeepAnalyzer - Deep codebase analysis with multiple execution modes\n *\n * @example\n * ```typescript\n * const analyzer = new DeepAnalyzer({\n * projectRoot: '/my/project',\n * docsPath: 'docs',\n * });\n *\n * const result = await analyzer.analyze();\n * console.log(`Generated ${result.insightsCount} insights`);\n * ```\n */\nexport class DeepAnalyzer {\n private projectRoot: string;\n private docsPath: string;\n private outputDir: string;\n private verbose: boolean;\n private maxAgents: number;\n private agentMode: 'sequential' | 'parallel' | 'adaptive';\n private agentTimeout: number;\n private forceApiKey: boolean;\n\n constructor(options: DeepAnalyzerOptions) {\n this.projectRoot = resolve(options.projectRoot);\n this.docsPath = options.docsPath || 'docs';\n this.outputDir = options.outputDir || join(this.projectRoot, this.docsPath, 'analysis');\n this.verbose = options.verbose || false;\n this.maxAgents = options.maxAgents || 5;\n this.agentMode = options.agentMode || 'adaptive';\n // Default timeout of 2 minutes (120 seconds)\n this.agentTimeout = options.agentTimeout || 120000;\n this.forceApiKey = options.forceApiKey || false;\n }\n\n /**\n * Check if running inside a Claude Code session\n */\n private isInsideClaudeCode(): boolean {\n return process.env.CLAUDECODE === '1' || process.env.CLAUDE_CODE === '1';\n }\n\n /**\n * Check if Anthropic API key is available\n */\n private hasApiKey(): boolean {\n return !!process.env.ANTHROPIC_API_KEY;\n }\n\n /**\n * Check if Claude CLI is available\n */\n private isCliAvailable(): boolean {\n try {\n execFileSync('claude', ['--version'], {\n stdio: 'pipe',\n timeout: 5000,\n windowsHide: true,\n });\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * Determine the best execution mode\n */\n private detectExecutionMode(): ExecutionMode {\n const insideClaudeCode = this.isInsideClaudeCode();\n const hasApiKey = this.hasApiKey();\n const cliAvailable = this.isCliAvailable();\n\n // If forced to use API key\n if (this.forceApiKey) {\n if (hasApiKey) {\n return { mode: 'api', reason: 'Using API key (forced)' };\n }\n return { mode: 'unavailable', reason: 'ANTHROPIC_API_KEY not set (required when forceApiKey=true)' };\n }\n\n // Inside Claude Code session - CLI doesn't work due to resource contention\n if (insideClaudeCode) {\n if (hasApiKey) {\n return { mode: 'api', reason: 'Using API key (inside Claude Code session)' };\n }\n return {\n mode: 'unavailable',\n reason: 'Cannot run deep analysis inside Claude Code session without ANTHROPIC_API_KEY. ' +\n 'Either set ANTHROPIC_API_KEY environment variable, or run this command from a regular terminal.',\n };\n }\n\n // Outside Claude Code - prefer CLI for OAuth session support\n if (cliAvailable) {\n return { mode: 'cli', reason: 'Using Claude CLI' };\n }\n\n // CLI not available, try API key\n if (hasApiKey) {\n return { mode: 'api', reason: 'Using API key (CLI not available)' };\n }\n\n return {\n mode: 'unavailable',\n reason: 'Claude CLI not found. Install Claude Code (https://claude.ai/code) or set ANTHROPIC_API_KEY.',\n };\n }\n\n /**\n * Check if analysis is available\n */\n async isAvailable(): Promise<boolean> {\n const mode = this.detectExecutionMode();\n return mode.mode !== 'unavailable';\n }\n\n /**\n * Get availability status with reason\n */\n async getAvailabilityStatus(): Promise<{ available: boolean; reason: string }> {\n const mode = this.detectExecutionMode();\n return {\n available: mode.mode !== 'unavailable',\n reason: mode.reason,\n };\n }\n\n /**\n * Run deep analysis\n */\n async analyze(): Promise<DeepAnalysisResult> {\n const startTime = Date.now();\n const executionMode = this.detectExecutionMode();\n\n const result: DeepAnalysisResult = {\n success: false,\n agentsSpawned: 0,\n insightsCount: 0,\n documentsCreated: 0,\n results: [],\n duration: 0,\n errors: [],\n mode: executionMode.mode === 'unavailable' ? 'static' : executionMode.mode,\n };\n\n // Check availability\n if (executionMode.mode === 'unavailable') {\n result.errors.push(executionMode.reason);\n result.duration = Date.now() - startTime;\n logger.error('Deep analysis unavailable', new Error(executionMode.reason));\n return result;\n }\n\n logger.info(`Starting deep analysis`, { mode: executionMode.mode, reason: executionMode.reason });\n\n // Ensure output directory exists\n if (!existsSync(this.outputDir)) {\n mkdirSync(this.outputDir, { recursive: true });\n }\n\n // Define agents\n const agents: AgentConfig[] = [\n {\n name: 'Pattern Researcher',\n type: 'researcher',\n task: 'Analyze codebase architecture, patterns, and design decisions',\n outputFile: 'architecture-patterns.md',\n },\n {\n name: 'Code Analyst',\n type: 'analyst',\n task: 'Identify code quality issues, complexity hotspots, and improvement opportunities',\n outputFile: 'code-analysis.md',\n },\n {\n name: 'Implementation Reviewer',\n type: 'coder',\n task: 'Review implementation patterns, naming conventions, and code style',\n outputFile: 'implementation-review.md',\n },\n {\n name: 'Test Analyzer',\n type: 'tester',\n task: 'Analyze test coverage, testing patterns, and testing gaps',\n outputFile: 'testing-analysis.md',\n },\n ];\n\n logger.info('Executing analysis agents', { agents: agents.length, mode: 'sequential' });\n\n // Execute agents sequentially\n for (const agent of agents) {\n const agentResult = await this.executeAgent(agent, executionMode.mode as 'cli' | 'api');\n result.results.push(agentResult);\n }\n\n // Calculate totals\n result.agentsSpawned = result.results.length;\n result.insightsCount = result.results.reduce((sum, r) => sum + r.insights.length, 0);\n result.documentsCreated = result.results.reduce((sum, r) => sum + r.documents.length, 0);\n result.success = result.results.some(r => r.success); // Success if at least one agent succeeded\n result.duration = Date.now() - startTime;\n\n // Collect errors\n for (const agentResult of result.results) {\n if (agentResult.error) {\n result.errors.push(`${agentResult.name}: ${agentResult.error}`);\n }\n }\n\n logger.info('Deep analysis complete', {\n success: result.success,\n insights: result.insightsCount,\n documents: result.documentsCreated,\n duration: result.duration,\n });\n\n return result;\n }\n\n /**\n * Execute a single agent\n */\n private async executeAgent(agent: AgentConfig, mode: 'cli' | 'api'): Promise<AgentResult> {\n const startTime = Date.now();\n const outputPath = join(this.outputDir, agent.outputFile);\n\n const result: AgentResult = {\n name: agent.name,\n type: agent.type,\n success: false,\n insights: [],\n documents: [],\n duration: 0,\n };\n\n try {\n logger.info(`Executing agent: ${agent.name}`, { type: agent.type, mode });\n\n const prompt = this.buildPrompt(agent);\n let output: string;\n\n if (mode === 'cli') {\n output = await this.runWithCli(prompt);\n } else {\n output = await this.runWithApi(prompt);\n }\n\n // Parse output for insights\n result.insights = this.extractInsights(output);\n\n // Write output to file\n writeFileSync(outputPath, this.formatOutput(agent, output));\n result.documents.push({ path: outputPath, title: agent.name });\n\n result.success = true;\n\n if (this.verbose) {\n logger.debug(`Agent completed: ${agent.name}`, { insights: result.insights.length });\n }\n } catch (error) {\n result.error = error instanceof Error ? error.message : String(error);\n logger.error(`Agent failed: ${agent.name}`, error instanceof Error ? error : new Error(String(error)));\n }\n\n result.duration = Date.now() - startTime;\n return result;\n }\n\n /**\n * Build context-aware prompt for analysis\n */\n private buildPrompt(agent: AgentConfig): string {\n // Gather project context\n const context = this.gatherProjectContext();\n\n return `You are analyzing a codebase. Here is the project context:\n\n${context}\n\nTask: ${agent.task}\n\nProvide your findings in markdown format with:\n1. Key observations (prefix with \"Observation:\")\n2. Specific recommendations (prefix with \"Recommendation:\")\n3. Any potential issues found (prefix with \"Finding:\")\n\nBe specific and actionable in your analysis.`;\n }\n\n /**\n * Gather project context for analysis\n */\n private gatherProjectContext(): string {\n const lines: string[] = [];\n\n // Check for package.json\n const packageJsonPath = join(this.projectRoot, 'package.json');\n if (existsSync(packageJsonPath)) {\n try {\n const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\n lines.push(`Project: ${pkg.name || 'Unknown'} v${pkg.version || '0.0.0'}`);\n lines.push(`Description: ${pkg.description || 'No description'}`);\n\n if (pkg.dependencies) {\n const deps = Object.keys(pkg.dependencies).slice(0, 10);\n lines.push(`Key dependencies: ${deps.join(', ')}`);\n }\n } catch {\n // Ignore parse errors\n }\n }\n\n // List top-level directories\n try {\n const entries = readdirSync(this.projectRoot, { withFileTypes: true });\n const dirs = entries\n .filter(e => e.isDirectory() && !e.name.startsWith('.') && e.name !== 'node_modules')\n .map(e => e.name)\n .slice(0, 10);\n\n if (dirs.length > 0) {\n lines.push(`Project structure: ${dirs.join(', ')}`);\n }\n } catch {\n // Ignore errors\n }\n\n // Check for common config files\n const configFiles = [\n 'tsconfig.json',\n 'vite.config.ts',\n 'vitest.config.ts',\n '.eslintrc.js',\n 'Dockerfile',\n ];\n\n const foundConfigs = configFiles.filter(f => existsSync(join(this.projectRoot, f)));\n if (foundConfigs.length > 0) {\n lines.push(`Config files: ${foundConfigs.join(', ')}`);\n }\n\n return lines.join('\\n');\n }\n\n /**\n * Run analysis using Claude CLI\n */\n private async runWithCli(prompt: string): Promise<string> {\n // Sanitize prompt - escape double quotes and remove dangerous chars\n const sanitizedPrompt = prompt\n .replace(/\"/g, '\\\\\"')\n .replace(/[`$]/g, '');\n\n try {\n const result = execSync(`claude -p \"${sanitizedPrompt}\"`, {\n cwd: this.projectRoot,\n encoding: 'utf8',\n timeout: this.agentTimeout,\n maxBuffer: 10 * 1024 * 1024, // 10MB buffer\n });\n return result;\n } catch (error) {\n if (error instanceof Error) {\n const execError = error as { stderr?: string; stdout?: string; killed?: boolean };\n if (execError.killed) {\n // Timeout - return partial output if available\n if (execError.stdout && execError.stdout.length > 100) {\n return execError.stdout;\n }\n throw new Error(`Claude CLI timed out after ${this.agentTimeout / 1000}s`);\n }\n throw new Error(execError.stderr || error.message);\n }\n throw error;\n }\n }\n\n /**\n * Run analysis using Anthropic API directly\n */\n private async runWithApi(prompt: string): Promise<string> {\n const apiKey = process.env.ANTHROPIC_API_KEY;\n if (!apiKey) {\n throw new Error('ANTHROPIC_API_KEY not set');\n }\n\n try {\n // Dynamic import to avoid bundling issues\n const { default: Anthropic } = await import('@anthropic-ai/sdk');\n\n const client = new Anthropic({ apiKey });\n\n const response = await client.messages.create({\n model: 'claude-sonnet-4-20250514',\n max_tokens: 4096,\n messages: [\n {\n role: 'user',\n content: prompt,\n },\n ],\n });\n\n // Extract text from response\n const textBlock = response.content.find(block => block.type === 'text');\n if (textBlock && textBlock.type === 'text') {\n return textBlock.text;\n }\n\n throw new Error('No text content in API response');\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`API call failed: ${error.message}`);\n }\n throw error;\n }\n }\n\n /**\n * Extract insights from agent output\n */\n private extractInsights(output: string): string[] {\n const insights: string[] = [];\n\n // Look for patterns like \"- Insight:\", \"Observation:\", \"Finding:\", \"Recommendation:\"\n const patterns = [\n /[-*]?\\s*(?:insight|finding|observation|recommendation):\\s*(.+)/gi,\n /##\\s*(?:insight|finding|observation|recommendation):\\s*(.+)/gi,\n /(?:key\\s+)?(?:insight|finding|observation|recommendation):\\s*(.+)/gi,\n ];\n\n for (const pattern of patterns) {\n const matches = output.matchAll(pattern);\n for (const match of matches) {\n if (match[1]) {\n insights.push(match[1].trim());\n }\n }\n }\n\n // Deduplicate\n return [...new Set(insights)];\n }\n\n /**\n * Format output for documentation\n */\n private formatOutput(agent: AgentConfig, output: string): string {\n const timestamp = new Date().toISOString();\n\n return `---\ntitle: \"${agent.name} Analysis\"\ntype: analysis\ngenerator: deep-analyzer\nagent: ${agent.type}\ncreated: ${timestamp}\n---\n\n# ${agent.name} Analysis\n\n> Generated by DeepAnalyzer\n\n## Overview\n\n${agent.task}\n\n## Analysis\n\n${output}\n\n---\n\n*Generated on ${new Date().toLocaleString()}*\n`;\n }\n}\n\n/**\n * Create a deep analyzer instance\n */\nexport function createDeepAnalyzer(options: DeepAnalyzerOptions): DeepAnalyzer {\n return new DeepAnalyzer(options);\n}\n\n/**\n * Run deep analysis on a project\n */\nexport async function analyzeDeep(\n projectRoot: string,\n docsPath?: string\n): Promise<DeepAnalysisResult> {\n const analyzer = new DeepAnalyzer({ projectRoot, docsPath });\n return analyzer.analyze();\n}\n"],"names":[],"mappings":";;;;AAgBA,MAAM,SAAS,aAAa,eAAe;AAgGpC,MAAM,aAAa;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,SAA8B;AACxC,SAAK,cAAc,QAAQ,QAAQ,WAAW;AAC9C,SAAK,WAAW,QAAQ,YAAY;AACpC,SAAK,YAAY,QAAQ,aAAa,KAAK,KAAK,aAAa,KAAK,UAAU,UAAU;AACtF,SAAK,UAAU,QAAQ,WAAW;AAClC,SAAK,YAAY,QAAQ,aAAa;AACtC,SAAK,YAAY,QAAQ,aAAa;AAEtC,SAAK,eAAe,QAAQ,gBAAgB;AAC5C,SAAK,cAAc,QAAQ,eAAe;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKQ,qBAA8B;AACpC,WAAO,QAAQ,IAAI,eAAe,OAAO,QAAQ,IAAI,gBAAgB;AAAA,EACvE;AAAA;AAAA;AAAA;AAAA,EAKQ,YAAqB;AAC3B,WAAO,CAAC,CAAC,QAAQ,IAAI;AAAA,EACvB;AAAA;AAAA;AAAA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OAAoB,QAAwB;AAC/D,UAAM,aAAY,oBAAI,KAAA,GAAO,YAAA;AAE7B,WAAO;AAAA,UACD,MAAM,IAAI;AAAA;AAAA;AAAA,SAGX,MAAM,IAAI;AAAA,WACR,SAAS;AAAA;AAAA;AAAA,IAGhB,MAAM,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMZ,MAAM,IAAI;AAAA;AAAA;AAAA;AAAA,EAIV,MAAM;AAAA;AAAA;AAAA;AAAA,iBAIQ,oBAAI,QAAO,gBAAgB;AAAA;AAAA,EAEzC;AACF;AAKO,SAAS,mBAAmB,SAA4C;AAC7E,SAAO,IAAI,aAAa,OAAO;AACjC;AAKA,eAAsB,YACpB,aACA,UAC6B;AAC7B,QAAM,WAAW,IAAI,aAAa,EAAE,aAAa,UAAU;AAC3D,SAAO,SAAS,QAAA;AAClB;"}
@@ -1,4 +1,4 @@
1
- import { __exports as dist } from "../../../../_virtual/index8.js";
1
+ import { __exports as dist } from "../../../../_virtual/index7.js";
2
2
  import { __require as requireCreateProjectService } from "./createProjectService.js";
3
3
  var hasRequiredDist;
4
4
  function requireDist() {
@@ -1,4 +1,4 @@
1
- import { __exports as dist } from "../../../../_virtual/index5.js";
1
+ import { __exports as dist } from "../../../../_virtual/index6.js";
2
2
  import { __require as requireAstSpec } from "./generated/ast-spec.js";
3
3
  import { __require as requireLib } from "./lib.js";
4
4
  import { __require as requireParserOptions } from "./parser-options.js";
@@ -1,4 +1,4 @@
1
- import { __exports as dist } from "../../../../_virtual/index6.js";
1
+ import { __exports as dist } from "../../../../_virtual/index5.js";
2
2
  import { __require as requireGetKeys } from "./get-keys.js";
3
3
  import { __require as requireVisitorKeys } from "./visitor-keys.js";
4
4
  var hasRequiredDist;
@@ -1,4 +1,4 @@
1
- import { __exports as dist } from "../../../_virtual/index7.js";
1
+ import { __exports as dist } from "../../../_virtual/index8.js";
2
2
  import require$$1 from "fs";
3
3
  import path__default from "path";
4
4
  import require$$2 from "url";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weavelogic/knowledge-graph-agent",
3
- "version": "0.10.3",
3
+ "version": "0.10.4",
4
4
  "description": "Knowledge graph agent for Claude Code - generates knowledge graphs, initializes docs, and integrates with claude-flow",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",