Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions context.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ documents:
- '*Interface.php'
showTreeView: true

- description: Project Templates
outputPath: core/templates.md
sources:
- type: file
sourcePaths:
- src/Template
- vendor/spiral/files/src/FilesInterface.php
showTreeView: true

- description: "Changes in the Project"
outputPath: "changes.md"
sources:
Expand Down
80 changes: 80 additions & 0 deletions docs/template-system.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Template System Usage

The CTX template system provides intelligent project analysis and template-based configuration generation.

## Commands

### List Templates
```bash
# Show all available templates
ctx template:list

# Show detailed template information
ctx template:list --detailed

# Filter by tags
ctx template:list --tag php --tag laravel

# Combine options
ctx template:list --detailed --tag php
```

### Initialize with Template
```bash
# Auto-detect project type and use appropriate template
ctx init

# Use specific template
ctx init laravel
ctx init generic-php

# Specify custom config filename
ctx init laravel --config-file=custom-context.yaml
```

## Available Templates

### Laravel Template (`laravel`)
- **Priority**: 100 (high)
- **Tags**: php, laravel, web, framework
- **Detection**: Looks for `composer.json`, `artisan` file, and Laravel directories
- **Generated Documents**:
- `docs/laravel-overview.md` - Application overview
- `docs/laravel-structure.md` - Directory structure with tree view

### Generic PHP Template (`generic-php`)
- **Priority**: 10 (low)
- **Tags**: php, generic
- **Detection**: Looks for `composer.json` and `src` directory
- **Generated Documents**:
- `docs/php-overview.md` - Project overview
- `docs/php-structure.md` - Directory structure with tree view

## Analysis Process

When you run `ctx init` without specifying a template:

1. **Project Analysis**: Scans the current directory for project indicators
2. **Template Matching**: Matches detected patterns to available templates
3. **Confidence Scoring**: Calculates confidence levels for matches
4. **Auto-Selection**: Uses high-confidence matches automatically
5. **Manual Selection**: Shows options for lower-confidence matches

### Analysis Output Example
```
$ ctx init
Analyzing project...
✅ Detected: laravel (confidence: 95%)
Using template: Laravel PHP Framework project template
✅ Config context.yaml created
```

## Extending the System

The template system is designed to be extensible:

- **Custom Analyzers**: Implement `ProjectAnalyzerInterface`
- **Custom Templates**: Implement `TemplateProviderInterface`
- **Custom Template Sources**: File-based, remote, or database templates

Templates automatically integrate with the existing CTX configuration system, supporting all source types, modifiers, and features.
2 changes: 0 additions & 2 deletions src/Application/Bootloader/CoreBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Butschster\ContextGenerator\Application\Bootloader;

use Butschster\ContextGenerator\Console\GenerateCommand;
use Butschster\ContextGenerator\Console\InitCommand;
use Butschster\ContextGenerator\Console\SchemaCommand;
use Butschster\ContextGenerator\Console\SelfUpdateCommand;
use Butschster\ContextGenerator\Console\VersionCommand;
Expand Down Expand Up @@ -58,7 +57,6 @@ public function boot(ConsoleBootloader $console): void
{
$console->addCommand(
VersionCommand::class,
InitCommand::class,
SchemaCommand::class,
SelfUpdateCommand::class,
GenerateCommand::class,
Expand Down
4 changes: 4 additions & 0 deletions src/Application/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Butschster\ContextGenerator\Application\Bootloader\SourceFetcherBootloader;
use Butschster\ContextGenerator\Application\Bootloader\VariableBootloader;
use Butschster\ContextGenerator\McpServer\McpServerBootloader;
use Butschster\ContextGenerator\Template\TemplateSystemBootloader;
use Butschster\ContextGenerator\Modifier\PhpContentFilter\PhpContentFilterBootloader;
use Butschster\ContextGenerator\Modifier\PhpDocs\PhpDocsModifierBootloader;
use Butschster\ContextGenerator\Modifier\PhpSignature\PhpSignatureModifierBootloader;
Expand Down Expand Up @@ -70,6 +71,9 @@ protected function defineBootloaders(): array
SourceRegistryBootloader::class,
SchemaMapperBootloader::class,

// Template System
TemplateSystemBootloader::class,

// Sources
TextSourceBootloader::class,
FileSourceBootloader::class,
Expand Down
105 changes: 0 additions & 105 deletions src/Console/InitCommand.php

This file was deleted.

10 changes: 10 additions & 0 deletions src/Console/context.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ documents:
filePattern: '*.php'
showTreeView: true

- description: Init command
outputPath: console/init.md
sources:
- type: file
sourcePaths:
- ./InitCommand.php
- ../DirectoriesInterface.php
- ../Application/FSPath.php
- ../Application/Bootloader/ConsoleBootloader.php

42 changes: 42 additions & 0 deletions src/Template/Analysis/AnalysisResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Butschster\ContextGenerator\Template\Analysis;

/**
* Result of project analysis
*/
final readonly class AnalysisResult
{
/**
* @param string $analyzerName Name of the analyzer that produced this result
* @param string $detectedType Type of project detected (e.g., 'laravel', 'generic-php')
* @param float $confidence Confidence level (0.0 to 1.0)
* @param array<string> $suggestedTemplates List of template names that match this analysis
* @param array<string, mixed> $metadata Additional metadata discovered during analysis
*/
public function __construct(
public string $analyzerName,
public string $detectedType,
public float $confidence,
public array $suggestedTemplates = [],
public array $metadata = [],
) {}

/**
* Check if this result has high confidence (>= 0.8)
*/
public function hasHighConfidence(): bool
{
return $this->confidence >= 0.8;
}

/**
* Get the primary suggested template (first in the list)
*/
public function getPrimaryTemplate(): ?string
{
return $this->suggestedTemplates[0] ?? null;
}
}
Loading
Loading