diff --git a/demo/demo2-templates-generation/demo-config.yaml b/demo/demo2-templates-generation/demo-config.yaml deleted file mode 100644 index 98f257b5..00000000 --- a/demo/demo2-templates-generation/demo-config.yaml +++ /dev/null @@ -1,20 +0,0 @@ -project_root: '%DOC_GEN_LIB_PATH%' -templates_dir: '%WORKING_DIR%/demo/demo2-templates-generation/templates' -cache_dir: '%WORKING_DIR%/demo/demo2-templates-generation/__cache' -language_handlers: - php: - class: \BumbleDocGen\LanguageHandler\Php\PhpHandler - settings: - file_source_base_url: '#' - async_source_loading_enabled: true -source_locators: - - class: \BumbleDocGen\Core\Parser\SourceLocator\RecursiveDirectoriesSourceLocator - arguments: - directories: - - "%project_root%/src" - -ai: - data_dir: '%WORKING_DIR%/demo/demo2-templates-generation/ai_data' -# api_key: - handler: "open_ai" - model: "gpt-4" diff --git a/demo/demo2-templates-generation/demoScript.php b/demo/demo2-templates-generation/demoScript.php deleted file mode 100644 index 03e3c5a4..00000000 --- a/demo/demo2-templates-generation/demoScript.php +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env php - InitDocsStructureCommand::NAME, - '--config' => 'demo/demo2-templates-generation/demo-config.yaml', - '--provider' => 'openai', - '--model' => 'gpt-4', - ]); - $application->run($input); -} catch (\Exception $e) { - die($e->getMessage()); -} diff --git a/demo/demo7-template-content/ai_data/structure.json b/demo/demo7-template-content/ai_data/structure.json deleted file mode 100644 index c055bc50..00000000 --- a/demo/demo7-template-content/ai_data/structure.json +++ /dev/null @@ -1,106 +0,0 @@ -{ - "/AI/": { - "name": "Artificial Intelligence", - "namespaces": [ - "BumbleDocGen\\AI\\Console", - "BumbleDocGen\\AI\\Generators", - "BumbleDocGen\\AI", - "BumbleDocGen\\AI\\Providers\\OpenAI", - "BumbleDocGen\\AI\\Traits" - ] - }, - "/Console/": { - "name": "Console Operations", - "namespaces": [ - "BumbleDocGen\\Console", - "BumbleDocGen\\Console\\Command", - "BumbleDocGen\\Console\\ProgressBar" - ] - }, - "/Core/Cache/": { - "name": "Core Cache", - "namespaces": [ - "BumbleDocGen\\Core\\Cache", - "BumbleDocGen\\Core\\Cache\\LocalCache", - "BumbleDocGen\\Core\\Cache\\LocalCache\\Exception" - ] - }, - "/Core/Configuration/": { - "name": "Core Configuration", - "namespaces": [ - "BumbleDocGen\\Core\\Configuration", - "BumbleDocGen\\Core\\Configuration\\Exception", - "BumbleDocGen\\Core\\Configuration\\ValueResolver", - "BumbleDocGen\\Core\\Configuration\\ValueTransformer" - ] - }, - "/Core/Logger/": { - "name": "Core Logger", - "namespaces": ["BumbleDocGen\\Core\\Logger\\Handler"] - }, - "/Core/Parser/": { - "name": "Core Parser", - "namespaces": [ - "BumbleDocGen\\Core\\Parser", - "BumbleDocGen\\Core\\Parser\\Entity", - "BumbleDocGen\\Core\\Parser\\Entity\\Cache", - "BumbleDocGen\\Core\\Parser\\Entity\\Cache\\CacheKey", - "BumbleDocGen\\Core\\Parser\\Entity\\CollectionLogOperation", - "BumbleDocGen\\Core\\Parser\\FilterCondition", - "BumbleDocGen\\Core\\Parser\\FilterCondition\\CommonFilterCondition", - "BumbleDocGen\\Core\\Parser\\SourceLocator" - ] - }, - "/Core/Plugin/": { - "name": "Core Plugin", - "namespaces": [ - "BumbleDocGen\\Core\\Plugin", - "BumbleDocGen\\Core\\Plugin\\CorePlugin\\LastPageCommitter", - "BumbleDocGen\\Core\\Plugin\\CorePlugin\\PageLinker", - "BumbleDocGen\\Core\\Plugin\\Event\\Parser", - "BumbleDocGen\\Core\\Plugin\\Event\\Renderer" - ] - }, - "/Core/Renderer/": { - "name": "Core Renderer", - "namespaces": [ - "BumbleDocGen\\Core\\Renderer", - "BumbleDocGen\\Core\\Renderer\\Breadcrumbs", - "BumbleDocGen\\Core\\Renderer\\Context", - "BumbleDocGen\\Core\\Renderer\\Context\\Dependency", - "BumbleDocGen\\Core\\Renderer\\EntityDocRenderer", - "BumbleDocGen\\Core\\Renderer\\PageLinkProcessor", - "BumbleDocGen\\Core\\Renderer\\Twig", - "BumbleDocGen\\Core\\Renderer\\Twig\\Filter", - "BumbleDocGen\\Core\\Renderer\\Twig\\Function" - ] - }, - "/LanguageHandler/": { - "name": "Language Handler", - "namespaces": ["BumbleDocGen\\LanguageHandler"] - }, - "/LanguageHandler/Php/": { - "name": "PHP Language Handler", - "namespaces": [ - "BumbleDocGen\\LanguageHandler\\Php", - "BumbleDocGen\\LanguageHandler\\Php\\Parser", - "BumbleDocGen\\LanguageHandler\\Php\\Parser\\Entity", - "BumbleDocGen\\LanguageHandler\\Php\\Parser\\Entity\\Cache", - "BumbleDocGen\\LanguageHandler\\Php\\Parser\\Entity\\Exception", - "BumbleDocGen\\LanguageHandler\\Php\\Parser\\Entity\\Reflection", - "BumbleDocGen\\LanguageHandler\\Php\\Parser\\FilterCondition\\ClassConstantFilterCondition", - "BumbleDocGen\\LanguageHandler\\Php\\Parser\\FilterCondition\\ClassFilterCondition", - "BumbleDocGen\\LanguageHandler\\Php\\Parser\\FilterCondition\\MethodFilterCondition", - "BumbleDocGen\\LanguageHandler\\Php\\Parser\\FilterCondition\\PropertyFilterCondition", - "BumbleDocGen\\LanguageHandler\\Php\\Parser\\SourceLocator", - "BumbleDocGen\\LanguageHandler\\Php\\Parser\\SourceLocator\\Internal", - "BumbleDocGen\\LanguageHandler\\Php\\Plugin\\CorePlugin\\BasePhpStubber", - "BumbleDocGen\\LanguageHandler\\Php\\Plugin\\CorePlugin\\EntityDocUnifiedPlace", - "BumbleDocGen\\LanguageHandler\\Php\\Plugin\\Event\\Entity", - "BumbleDocGen\\LanguageHandler\\Php\\Plugin\\Event\\Parser", - "BumbleDocGen\\LanguageHandler\\Php\\Renderer\\EntityDocRenderer", - "BumbleDocGen\\LanguageHandler\\Php\\Renderer\\EntityDocRenderer\\PhpClassToMd", - "BumbleDocGen\\LanguageHandler\\Php\\Renderer\\Twig\\Function" - ] - } -} \ No newline at end of file diff --git a/demo/demo7-template-content/demo-config.yaml b/demo/demo7-template-content/demo-config.yaml deleted file mode 100644 index 5afa58a1..00000000 --- a/demo/demo7-template-content/demo-config.yaml +++ /dev/null @@ -1,20 +0,0 @@ -project_root: '%DOC_GEN_LIB_PATH%' -cache_dir: '%WORKING_DIR%/demo/demo7-template-content/__cache' -templates_dir: '%WORKING_DIR%/demo/demo7-template-content/templates' -output_dir: "%WORKING_DIR%/demo/demo7-template-content/docs" -output_dir_base_url: "/demo/demo7-template-content/docs" -language_handlers: - php: - class: \BumbleDocGen\LanguageHandler\Php\PhpHandler - settings: - async_source_loading_enabled: true -source_locators: - - class: \BumbleDocGen\Core\Parser\SourceLocator\RecursiveDirectoriesSourceLocator - arguments: - directories: - - "%project_root%/src" -ai: - data_dir: '%WORKING_DIR%/demo/demo7-template-content/ai_data' - api_key: - handler: "open_ai" - model: "gpt-4" diff --git a/demo/demo7-template-content/demoScript.php b/demo/demo7-template-content/demoScript.php deleted file mode 100644 index 806ef7d8..00000000 --- a/demo/demo7-template-content/demoScript.php +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env php - GenerateTemplatesContentCommand::NAME, - '--config' => 'demo/demo7-template-content/demo-config.yaml', - '--provider' => 'openai', - '--model' => 'gpt-4', - ]); - - $application->run($input); -} catch (\Exception $e) { - die($e->getMessage()); -} - -function generateStructureIfNotExists(App $application): void -{ - $finder = new Finder(); - $targetDir = __DIR__ . '/templates'; - $fileCount = 0; - - if (is_dir($targetDir)) { - $finder->files()->in($targetDir); - $fileCount = iterator_count($finder); - } - - if ($fileCount === 0) { - $input = new ArrayInput([ - 'command' => InitDocsStructureCommand::NAME, - '--config' => 'demo/demo7-template-content/demo-config.yaml', - '--provider' => 'openai', - '--model' => 'gpt-4', - ]); - $application->run($input); - } -} diff --git a/demo/demo7-template-content/templates/readme.md.twig b/demo/demo7-template-content/templates/readme.md.twig deleted file mode 100644 index ba63f40c..00000000 --- a/demo/demo7-template-content/templates/readme.md.twig +++ /dev/null @@ -1 +0,0 @@ -{% set title = 'About the project' %} diff --git a/demo/demo7-template-content/templates/tech/AI/index.md.twig b/demo/demo7-template-content/templates/tech/AI/index.md.twig deleted file mode 100644 index 0e08eef6..00000000 --- a/demo/demo7-template-content/templates/tech/AI/index.md.twig +++ /dev/null @@ -1,47 +0,0 @@ -{% set title = 'Artificial Intelligence' %} -{{ generatePageBreadcrumbs(title, _self) }} - -# Artificial Intelligence - -This page contains the documentation for the classes and methods in the AI namespace. The AI namespace is broken down into several sub-namespaces, including `Console`, `Generators`, `Providers\OpenAI`, and the base `AI` namespace. - -## Console - -The `Console` sub-namespace contains command classes used in the console for various tasks. These classes are: - -- \BumbleDocGen\AI\Console\AddDocBlocksCommand -- \BumbleDocGen\AI\Console\GenerateReadMeTemplateCommand -- \BumbleDocGen\AI\Console\GenerateTemplatesContentCommand -- \BumbleDocGen\AI\Console\InitDocsStructureCommand - -Each of these classes includes methods for managing console commands such as `addArgument`, `addOption`, `getAliases`, `getApplication`, and more. - -## Generators - -The `Generators` sub-namespace contains utility classes used for generating documentation. These classes include: - -- \BumbleDocGen\AI\Generators\MissingDocBlocksGenerator -- \BumbleDocGen\AI\Generators\ReadmeTemplateGenerator -- \BumbleDocGen\AI\Generators\TemplateGenerator -- \BumbleDocGen\AI\Generators\TemplatesStructureGenerator - -These classes host methods to compile and generate documentation blocks, README files, and template structures. - -## Providers - -The `Providers` sub-namespace comprises classes used to interface with external AI providers. Currently, the only AI provider implemented is `OpenAI`. - -- \BumbleDocGen\AI\Providers\OpenAI\Provider - -This class contains methods for interfacing with the OpenAI API, including methods for formatting data prompts, retrieving available models, and sending prompts to the AI. - -## Base AI Namespace - -The base AI namespace includes important classes for interacting with AI providers: - -- \BumbleDocGen\AI\ProviderFactory -- \BumbleDocGen\AI\ProviderInterface - -The `ProviderFactory` class is used to instantiate AI providers, while the `ProviderInterface` is an interface that all AI providers must implement. - -For detailed information about each class and its methods, refer to the specific class documentation page. \ No newline at end of file diff --git a/demo/demo7-template-content/templates/tech/Console/index.md.twig b/demo/demo7-template-content/templates/tech/Console/index.md.twig deleted file mode 100644 index 277b0659..00000000 --- a/demo/demo7-template-content/templates/tech/Console/index.md.twig +++ /dev/null @@ -1,34 +0,0 @@ -{% set title = 'Console Operations' %} -{{ generatePageBreadcrumbs(title, _self) }} - -# Console Operations - -## \BumbleDocGen\Console\Command - -### [BaseCommand](\Namespace\BaseCommand) - -This is the base class for all commands in the console application. It takes care of basic command operations such as argument and option manipulation, command description, and execution. - -### [AdditionalCommandCollection](\Namespace\AdditionalCommandCollection) - -This class manages a collection of additional commands. It provides methods for adding and iterating over the command objects. - -### [GenerateCommand](\Namespace\GenerateCommand) - -This class represents a specific console command that generates output based on provided arguments and options. - -## \BumbleDocGen\Console - -### [App](\Namespace\App) - -This class represents the console application itself. It provides a wide range of methods for command registration, execution, and lifecycle management. - -## \BumbleDocGen\Console\ProgressBar - -### [ProgressBarFactory](\Namespace\ProgressBarFactory) - -This class is a factory for creating stylized progress bars, which can be used to display progress information for long-running console commands. - -### [StylizedProgressBar](\Namespace\StylizedProgressBar) - -This class represents a stylized progress bar. It provides methods for managing the progress bar's appearance and updating its progress. diff --git a/demo/demo7-template-content/templates/tech/Core/Cache/index.md.twig b/demo/demo7-template-content/templates/tech/Core/Cache/index.md.twig deleted file mode 100644 index caa81c5e..00000000 --- a/demo/demo7-template-content/templates/tech/Core/Cache/index.md.twig +++ /dev/null @@ -1,25 +0,0 @@ -{% set title = 'Core Cache' %} -{{ generatePageBreadcrumbs(title, _self) }} - -``` -

Core Cache

- -

The Core Cache namespace consists of classes responsible for managing cache in the BumbleDocGen application. These classes provide functionality for persisting, retrieving, and removing cache items.

- -

Classes:

- -

EntityCacheItemPool

-

This class manages a collection of cache items. It provides methods for adding, deleting, and retrieving cache items, as well as for committing any deferred cache operations.

- -

SharedCompressedDocumentFileCache

-

This class is responsible for caching document files. It provides methods for getting, setting, and saving the cache, as well as for removing unused keys.

- -

SourceLocatorCacheItemPool

-

This class manages a collection of source locator cache items. Similar to the EntityCacheItemPool, it provides methods for adding, deleting, and retrieving cache items, and committing deferred cache operations.

- -

ObjectNotFoundException

-

This class defines an exception to be thrown when a requested object is not found in the cache. It extends the base PHP Exception class.

- -

LocalObjectCache

-

This class provides methods for caching and retrieving the results of method calls. This can help improve performance by avoiding the need for expensive or duplicate method calls.

-``` diff --git a/demo/demo7-template-content/templates/tech/Core/Configuration/index.md.twig b/demo/demo7-template-content/templates/tech/Core/Configuration/index.md.twig deleted file mode 100644 index 8263468a..00000000 --- a/demo/demo7-template-content/templates/tech/Core/Configuration/index.md.twig +++ /dev/null @@ -1,2 +0,0 @@ -{% set title = 'Core Configuration' %} -{{ generatePageBreadcrumbs(title, _self) }} diff --git a/demo/demo7-template-content/templates/tech/Core/Logger/index.md.twig b/demo/demo7-template-content/templates/tech/Core/Logger/index.md.twig deleted file mode 100644 index aed6b562..00000000 --- a/demo/demo7-template-content/templates/tech/Core/Logger/index.md.twig +++ /dev/null @@ -1,2 +0,0 @@ -{% set title = 'Core Logger' %} -{{ generatePageBreadcrumbs(title, _self) }} diff --git a/demo/demo7-template-content/templates/tech/Core/Parser/index.md.twig b/demo/demo7-template-content/templates/tech/Core/Parser/index.md.twig deleted file mode 100644 index 9bdfa8fe..00000000 --- a/demo/demo7-template-content/templates/tech/Core/Parser/index.md.twig +++ /dev/null @@ -1,2 +0,0 @@ -{% set title = 'Core Parser' %} -{{ generatePageBreadcrumbs(title, _self) }} diff --git a/demo/demo7-template-content/templates/tech/Core/Plugin/index.md.twig b/demo/demo7-template-content/templates/tech/Core/Plugin/index.md.twig deleted file mode 100644 index 94089fdd..00000000 --- a/demo/demo7-template-content/templates/tech/Core/Plugin/index.md.twig +++ /dev/null @@ -1,2 +0,0 @@ -{% set title = 'Core Plugin' %} -{{ generatePageBreadcrumbs(title, _self) }} diff --git a/demo/demo7-template-content/templates/tech/Core/Renderer/index.md.twig b/demo/demo7-template-content/templates/tech/Core/Renderer/index.md.twig deleted file mode 100644 index c95e7b4a..00000000 --- a/demo/demo7-template-content/templates/tech/Core/Renderer/index.md.twig +++ /dev/null @@ -1,2 +0,0 @@ -{% set title = 'Core Renderer' %} -{{ generatePageBreadcrumbs(title, _self) }} diff --git a/demo/demo7-template-content/templates/tech/LanguageHandler/Php/index.md.twig b/demo/demo7-template-content/templates/tech/LanguageHandler/Php/index.md.twig deleted file mode 100644 index b52ecc33..00000000 --- a/demo/demo7-template-content/templates/tech/LanguageHandler/Php/index.md.twig +++ /dev/null @@ -1,2 +0,0 @@ -{% set title = 'PHP Language Handler' %} -{{ generatePageBreadcrumbs(title, _self) }} diff --git a/demo/demo7-template-content/templates/tech/LanguageHandler/index.md.twig b/demo/demo7-template-content/templates/tech/LanguageHandler/index.md.twig deleted file mode 100644 index 9943ec78..00000000 --- a/demo/demo7-template-content/templates/tech/LanguageHandler/index.md.twig +++ /dev/null @@ -1,2 +0,0 @@ -{% set title = 'Language Handler' %} -{{ generatePageBreadcrumbs(title, _self) }} diff --git a/demo/demo7-template-content/templates/tech/index.md.twig b/demo/demo7-template-content/templates/tech/index.md.twig deleted file mode 100644 index b5239b81..00000000 --- a/demo/demo7-template-content/templates/tech/index.md.twig +++ /dev/null @@ -1,2 +0,0 @@ -{% set title = 'Technical Overview' %} -{{ generatePageBreadcrumbs(title, _self) }} diff --git a/src/AI/Console/GenerateTemplatesContentCommand.php b/src/AI/Console/GenerateTemplatesContentCommand.php deleted file mode 100644 index 9bcfabd0..00000000 --- a/src/AI/Console/GenerateTemplatesContentCommand.php +++ /dev/null @@ -1,73 +0,0 @@ - 'Path to the directory of the documented project', - 'templates_dir' => 'Path to directory with documentation templates', - 'cache_dir' => 'Configuration parameter: Path to the directory where the documentation generator cache will be saved', - ]; - } - - protected function configure(): void - { - $this->setName(self::NAME) - ->setDescription('Leverage AI to generate content for doc templates.'); - $this->addSharedCommandOptions(); - } - - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return int - * @throws DependencyException - * @throws GuzzleException - * @throws JsonException - * @throws NotFoundException - * @throws InvalidConfigurationParameterException - * @throws ReflectionException - */ - protected function execute( - InputInterface $input, - OutputInterface $output - ): int { - $configuration = $this->getConfigurationFromInput($input); - - $provider = $this->getAIProvider($input, $configuration); - $apiKey = $this->getAIApiKey($input, $output, $configuration, $provider); - $model = $this->getAIModel($input, $output, $configuration, $provider, $apiKey); - - $systemPrompt = $this->getValueFromOptionOrConfig($input, $configuration, 'system-prompt'); - $nonInteractive = (bool)$this->getValueFromOptionOrConfig( - $input, - $configuration, - 'non-interactive' - ); - - $docGen = $this->createDocGenInstance($input, $output); - $docGen->generateTemplatesContent($provider, $apiKey, $model, $nonInteractive, $systemPrompt); - return Command::SUCCESS; - } -} diff --git a/src/AI/Console/InitDocsStructureCommand.php b/src/AI/Console/InitDocsStructureCommand.php deleted file mode 100644 index 786c0ba0..00000000 --- a/src/AI/Console/InitDocsStructureCommand.php +++ /dev/null @@ -1,75 +0,0 @@ - 'Path to the directory of the documented project', - 'templates_dir' => 'Path to directory with documentation templates', - 'cache_dir' => 'Configuration parameter: Path to the directory where the documentation generator cache will be saved', - ]; - } - - protected function configure(): void - { - $this->setName(self::NAME) - ->setDescription('Leverage AI to establish a documentation structure with empty files.'); - $this->addSharedCommandOptions(); - } - - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return int - * @throws DependencyException - * @throws InvalidConfigurationParameterException - * @throws NotFoundException - * @throws GuzzleException - * @throws JsonException - */ - protected function execute( - InputInterface $input, - OutputInterface $output - ): int { - $configuration = $this->getConfigurationFromInput($input); - - $provider = $this->getAIProvider($input, $configuration); - $apiKey = $this->getAIApiKey($input, $output, $configuration, $provider); - $model = $this->getAIModel($input, $output, $configuration, $provider, $apiKey); - - $systemPrompt = $this->getValueFromOptionOrConfig($input, $configuration, 'system-prompt'); - $nonInteractive = (bool)$this->getValueFromOptionOrConfig( - $input, - $configuration, - 'non-interactive' - ); - $this->createDocGenInstance($input, $output)->initDocsStructure( - $provider, - $apiKey, - $model, - $nonInteractive, - $systemPrompt - ); - return self::SUCCESS; - } -} diff --git a/src/AI/Generators/TemplateContentGenerator.php b/src/AI/Generators/TemplateContentGenerator.php deleted file mode 100644 index bafb70dc..00000000 --- a/src/AI/Generators/TemplateContentGenerator.php +++ /dev/null @@ -1,152 +0,0 @@ -getMethodStubs($fileNamespaces, $entitiesCollection); - $prompts[] = $this->aiHandler->formatDataPrompt( - 'Method Stubs', - $methodStubs - ); - - if ($additionalPrompt) { - $prompts[] = $this->aiHandler->formatDataPrompt('Additional Information', $additionalPrompt); - } - - $prompts[] = ' Produce content for an "index.twig" file titled "' . $fileName . '"'; - - if ($systemPrompt === null) { - $systemPrompt = $this->aiHandler->getSystemPrompt('templateContentGeneration'); - } else { - $systemPrompt = file_get_contents($systemPrompt); - } - - $aiContent = $this->aiHandler->sendPrompts($prompts, $systemPrompt); - - return $fileContent . "\n" . $aiContent; - } - - /** - * @throws ReflectionException - * @throws InvalidConfigurationParameterException - */ - private function getEntities(ClassEntityCollection|array $entitiesCollection): \Generator - { - foreach ($entitiesCollection as $classEntity) { - /**@var ClassEntity $classEntity */ - if ( - !$classEntity->entityDataCanBeLoaded() || array_key_exists( - $classEntity->getName(), - $this->alreadyProcessedEntities - ) - ) { - continue; - } - $interfaces = $classEntity->getInterfacesEntities(); - if ($interfaces) { - yield from $this->getEntities($interfaces); - } - $parentClass = $classEntity->getParentClass(); - if ($parentClass) { - yield from $this->getEntities([$parentClass]); - } - $this->alreadyProcessedEntities[$classEntity->getName()] = 1; - yield $classEntity; - } - } - - /** - * @throws ReflectionException - * @throws DependencyException - * @throws NotFoundException - * @throws InvalidConfigurationParameterException - */ - private function getMethodStubs( - array $fileNamespaces, - ?ClassEntityCollection $entitiesCollection - ): string { - $tree = []; - $this->alreadyProcessedEntities = []; - - foreach ($this->getEntities($entitiesCollection) as $entity) { - $nsCheck = in_array($entity->getNamespaceName(), $fileNamespaces, true); - if ($nsCheck) { - $methods = $entity->getMethodEntityCollection(); - $simpleEntityName = $this->getSimpleEntityName($entity->getName()); - foreach ($methods as $method) { - /** @var MethodEntity $method */ - $methodString = $method->getName() . '(' . $method->getParametersString() . ')'; - $description = $method->getDescription(); - - if (!isset($tree[$entity->getNamespaceName()])) { - $tree[$entity->getNamespaceName()] = []; - } - - if (!isset($tree[$entity->getNamespaceName()][$simpleEntityName])) { - $tree[$entity->getNamespaceName()][$simpleEntityName] = []; - } - - $tree[$entity->getNamespaceName()][$simpleEntityName][$methodString] = $description; - } - } - } - return $this->treeToText($tree); - } - - private function getSimpleEntityName(string $fullEntityName): string - { - $parts = explode('\\', $fullEntityName); - return end($parts); - } - - private function treeToText(array $tree, $indentLevel = 0): string - { - $text = ''; - $indent = str_repeat(' ', $indentLevel); - - foreach ($tree as $key => $value) { - if (is_array($value)) { - $text .= $indent . $key . ":\n"; - $text .= $this->treeToText($value, $indentLevel + 1); - } else { - $text .= $indent . $key . ": " . $value . "\n"; - } - } - - return $text; - } -} diff --git a/src/AI/Generators/TemplateStructureGenerator.php b/src/AI/Generators/TemplateStructureGenerator.php deleted file mode 100644 index 85b4217e..00000000 --- a/src/AI/Generators/TemplateStructureGenerator.php +++ /dev/null @@ -1,74 +0,0 @@ - $e->getNamespaceName(), - iterator_to_array($rootEntityCollection) - ); - $namespacesList = array_unique($namespacesList); - - $prompts = []; - $prompts[] = $this->aiHandler->formatDataPrompt( - 'Namespaces', - implode( - "\n", - $namespacesList - ) - ); - - if ($systemPrompt === null) { - $systemPrompt = $this->aiHandler->getSystemPrompt('templateStructureGeneration'); - } - - if ($additionalPrompt) { - $prompts[] = $this->aiHandler->formatDataPrompt('Additional Information', $additionalPrompt); - } - - $content = $this->aiHandler->sendPrompts($prompts, $systemPrompt); - - file_put_contents($this->aiConfigDirectory . '/structure.json', $content); - - $structure = json_decode($content, true, 512, JSON_THROW_ON_ERROR); - - $finalStructure = [ - "/readme.md.twig" => "About the project", - ]; - - foreach ($structure as $dir => $info) { - $finalStructure["/tech{$dir}index.md.twig"] = $info['name']; - } - - $finalStructure["/tech/index.md.twig"] = "Technical Overview"; - return $finalStructure; - } -} diff --git a/src/AI/Prompts/templateContentGeneration b/src/AI/Prompts/templateContentGeneration deleted file mode 100644 index e29cfae1..00000000 --- a/src/AI/Prompts/templateContentGeneration +++ /dev/null @@ -1 +0,0 @@ -You're tasked with generating an overview of the technical documentation from class names within a namespace. For each class, provide a brief high-level description of its purpose and responsibilities. Do not delve into specific methods or properties. Link to detailed class documentation using: \Namespace\ClassName. diff --git a/src/AI/Prompts/templateStructureGeneration b/src/AI/Prompts/templateStructureGeneration deleted file mode 100644 index 6771727b..00000000 --- a/src/AI/Prompts/templateStructureGeneration +++ /dev/null @@ -1,18 +0,0 @@ -Given a list of PHP namespaces, generate a JSON representation of a condensed documentation file structure based on the criteria below: - - Group related namespaces. - - Exclude the top-level namespace. - - Represent each path with associated metadata: a human-readable name and a list of related namespaces. - -Return the response in pure JSON format only, without any markdown or additional context. - -Example Output: -{ - "/tech/": { - "name": "Technical description", - "namespaces": ["\Namespace\Tech"] - }, - "/tech/events/": { - "name": "Events to call", - "namespaces": ["\Namespace\Tech\Events", "\Namespace\Tech\Events\Listener"] - } -} diff --git a/src/Console/App.php b/src/Console/App.php index 58819ef8..4dfc8606 100644 --- a/src/Console/App.php +++ b/src/Console/App.php @@ -6,8 +6,6 @@ use BumbleDocGen\AI\Console\AddDocBlocksCommand; use BumbleDocGen\AI\Console\GenerateReadMeTemplateCommand; -use BumbleDocGen\AI\Console\InitDocsStructureCommand; -use BumbleDocGen\AI\Console\GenerateTemplatesContentCommand; use BumbleDocGen\Console\Command\GenerateCommand; use BumbleDocGen\DocGeneratorFactory; use Symfony\Component\Console\Application; @@ -36,8 +34,6 @@ public function __construct() $this->add(new GenerateCommand()); $this->add(new GenerateReadMeTemplateCommand()); $this->add(new AddDocBlocksCommand()); - $this->add(new InitDocsStructureCommand()); - $this->add(new GenerateTemplatesContentCommand()); $this->setExtraCommands(); } diff --git a/src/DocGenerator.php b/src/DocGenerator.php index 5af60242..1adb4a05 100644 --- a/src/DocGenerator.php +++ b/src/DocGenerator.php @@ -6,8 +6,6 @@ use BumbleDocGen\AI\Generators\DocBlocksGenerator; use BumbleDocGen\AI\Generators\ReadmeTemplateGenerator; -use BumbleDocGen\AI\Generators\TemplateContentGenerator; -use BumbleDocGen\AI\Generators\TemplateStructureGenerator; use BumbleDocGen\AI\ProviderFactory; use BumbleDocGen\Core\Configuration\Configuration; use BumbleDocGen\Core\Configuration\Exception\InvalidConfigurationParameterException; @@ -75,76 +73,6 @@ public function parseAndGetRootEntityCollectionsGroup(): RootEntityCollectionsGr return $this->rootEntityCollectionsGroup; } - /** - * Generate documentation structure with blank templates using AI tools - * - * @throws InvalidConfigurationParameterException - */ - public function initDocsStructure( - string $aiHandler, - string $aiApiKey, - string $aiModel, - bool $nonInteractive = false, - ?string $systemPrompt = null, - ): void { - $this->parser->parse(); - $entitiesCollection = $this->rootEntityCollectionsGroup->get(ClassEntityCollection::NAME); - - $aiProvider = ProviderFactory::create($aiHandler, $aiApiKey, $aiModel); - $aiDirectory = $this->configuration->getAiDataDir(); - - $templatesStructureGenerator = new TemplateStructureGenerator($aiProvider, $aiDirectory); - - do { - if ($nonInteractive) { - $additionalPrompt = null; - } else { - $additionalPrompt = $this->io->ask( - 'Write instructions for more accurate template structure generation ( or just skip this step )' - ) ?: null; - } - $this->io->note("Sending " . $aiProvider->getName() . " request"); - $structure = $templatesStructureGenerator->generateStructureByEntityCollection( - $entitiesCollection, - $additionalPrompt, - $systemPrompt - ); - $structureAsString = implode( - "\n", - array_map(fn($v, $k) => "{$k} => {$v}", $structure, array_keys($structure)) - ); - if ($nonInteractive) { - $action = 'Save'; - } else { - $action = $this->io->choice( - "The proposed documentation structure is as follows:\n\n{$structureAsString}", - ['Save', 'Regenerate', 'Cancel'] - ); - } - } while ($action === 'Regenerate'); - - if ($action === 'Save') { - $templatesDir = $this->configuration->getTemplatesDir(); - $finder = new Finder(); - $finder->files()->in($this->configuration->getTemplatesDir()); - if ( - $finder->hasResults() && - $this->io->confirm("Directory `{$templatesDir}` already contains files. Clean before saving new ones?") - ) { - $this->fs->remove([$templatesDir]); - } - - foreach ($structure as $fileName => $title) { - $fileName = $templatesDir . $fileName; - $this->fs->appendToFile($fileName, "{% set title = '{$title}' %}\n"); - if (!str_ends_with($fileName, 'readme.md.twig')) { - $this->fs->appendToFile($fileName, "{{ generatePageBreadcrumbs(title, _self) }}\n"); - } - $this->logger->notice("Creating `{$fileName}` template"); - } - } - } - /** * Generate missing docBlocks with ChatGPT for project class methods that are available for documentation * @@ -327,78 +255,6 @@ public function generateReadmeTemplate( } } - /** - * @throws ReflectionException - * @throws DependencyException - * @throws JsonException - * @throws NotFoundException - * @throws InvalidConfigurationParameterException - */ - public function generateTemplatesContent( - string $aiHandler, - string $aiApiKey, - string $aiModel, - bool $nonInteractive = false, - ?string $systemPrompt = null, - ): void { - $this->parser->parse(); - $entitiesCollection = $this->rootEntityCollectionsGroup->get(ClassEntityCollection::NAME); - - $aiProvider = ProviderFactory::create($aiHandler, $aiApiKey, $aiModel); - $aiConfigDirectory = $this->configuration->getAiDataDir(); - $templateGenerator = new TemplateContentGenerator($aiProvider); - $aiStructure = file_get_contents($aiConfigDirectory . '/structure.json'); - $aiStructure = json_decode($aiStructure, true, 512, JSON_THROW_ON_ERROR); - - foreach ($aiStructure as $path => $data) { - $template = $this->configuration->getTemplatesDir() . '/tech' . $path . 'index.md.twig'; - do { - $this->io->note( - 'Creating template for ' . $template - ); - if ($nonInteractive) { - $additionalPrompt = null; - } else { - $processThisTemplate = $this->io->choice( - 'Do you want to create this template?', - ['Yes', 'No'], - 'Yes' - ); - if ($processThisTemplate === 'No') { - continue(2); - } - $additionalPrompt = $this->io->ask( - 'Add additional information about this ( or just skip this step )' - ) ?: null; - } - $this->io->note("Sending " . $aiProvider->getName() . " request"); - $content = $templateGenerator->generate( - $template, - $data['name'], - $data['namespaces'], - $entitiesCollection, - $additionalPrompt, - $systemPrompt, - ); - if (!$nonInteractive) { - $action = $this->io->choice( - "The proposed documentation is as follows:\n\n{$content}", - ['Save', 'Regenerate', 'Cancel'] - ); - } else { - $action = 'Save'; - } - } while ($action === 'Regenerate'); - - if ($action === 'Save') { - $this->logger->notice( - 'Saving file: .' . $template - ); - $this->fs->dumpFile($template, $content); - } - } - } - /** * Generates documentation using configuration *