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
8 changes: 8 additions & 0 deletions app/Enums/DocumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ enum DocumentType: string
{
case Prd = 'prd';
case Tech = 'tech';

public function label(): string
{
return match ($this) {
self::Prd => 'PRD',
self::Tech => 'Technical Specification',
};
}
}
45 changes: 45 additions & 0 deletions app/Enums/FeedbackType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Enums;

enum FeedbackType: string
{
case Completeness = 'completeness';
case Clarity = 'clarity';
case Technical = 'technical';
case Stakeholder = 'stakeholder';
case Overall = 'overall';

public function label(): string
{
return match ($this) {
self::Completeness => 'Completeness',
self::Clarity => 'Clarity',
self::Technical => 'Technical Review',
self::Stakeholder => 'Stakeholder Ready',
self::Overall => 'Overall Assessment',
};
}

public function description(): string
{
return match ($this) {
self::Completeness => 'What\'s missing from this document?',
self::Clarity => 'What parts are unclear or ambiguous?',
self::Technical => 'What technical gaps exist?',
self::Stakeholder => 'What questions will stakeholders ask?',
self::Overall => 'Rate and suggest improvements',
};
}

public function icon(): string
{
return match ($this) {
self::Completeness => 'clipboard-document-check',
self::Clarity => 'eye',
self::Technical => 'cpu-chip',
self::Stakeholder => 'user-group',
self::Overall => 'star',
};
}
}
37 changes: 37 additions & 0 deletions app/Enums/TemplateCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Enums;

enum TemplateCategory: string
{
case Core = 'core';
case Technical = 'technical';
case Strategy = 'strategy';
case Research = 'research';
case Analysis = 'analysis';
case Community = 'community';

public function label(): string
{
return match ($this) {
self::Core => 'Core Templates',
self::Technical => 'Technical & Product Documentation',
self::Strategy => 'Product Planning & Strategy',
self::Research => 'Research, Testing & UX',
self::Analysis => 'Analysis & Reporting',
self::Community => 'Community Templates',
};
}

public function icon(): string
{
return match ($this) {
self::Core => '📄',
self::Technical => '🔧',
self::Strategy => '🎯',
self::Research => '🔬',
self::Analysis => '📊',
self::Community => '👥',
};
}
}
70 changes: 70 additions & 0 deletions app/Jobs/GenerateFeedbackJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace App\Jobs;

use App\Enums\FeedbackType;
use App\Jobs\Concerns\ResolvesAiProvider;
use App\Models\Document;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Middleware\RateLimited;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;
use Prism\Prism\Facades\Prism;

class GenerateFeedbackJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, ResolvesAiProvider, SerializesModels;

public int $tries = 3;

/** @var array<int, int> */
public array $backoff = [10, 30, 60];

public function __construct(
public string $documentId,
public FeedbackType $feedbackType,
public string $cacheKey,
) {
$this->afterCommit();
}

/**
* @return array<int, object>
*/
public function middleware(): array
{
return [new RateLimited('llm:requests')];
}

public function handle(): void
{
$document = Document::with(['currentVersion', 'project'])->findOrFail($this->documentId);
$project = $document->project;

$system = view('prompts.feedback.system')->render();
$prompt = view("prompts.feedback.{$this->feedbackType->value}", [
'content' => $document->currentVersion->content_md,
'documentType' => strtolower($document->type->label()),
])->render();

$provider = $this->resolveProvider($project->preferred_provider ?? 'anthropic');
$model = $project->preferred_model ?? 'claude-sonnet-4-20250514';

$response = Prism::text()
->using($provider, $model)
->withMaxTokens(2000)
->withSystemPrompt($system)
->withPrompt($prompt)
->withClientOptions(['timeout' => 60])
->asText();

Cache::put($this->cacheKey, [
'feedback' => $response->text,
'type' => $this->feedbackType->value,
'generated_at' => now()->toIso8601String(),
], now()->addHour());
}
}
19 changes: 17 additions & 2 deletions app/Jobs/GeneratePrdJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class GeneratePrdJob implements ShouldBeUnique, ShouldQueue

public int $tries = 5;

/** @var array<int, int> */
public array $backoff = [10, 30, 60, 120, 300];

public int $uniqueFor = 3600; // 1 hour
public int $uniqueFor = 3600;

public function __construct(public string $planRunId)
{
Expand All @@ -42,6 +43,9 @@ public function uniqueId(): string
return $this->planRunId.':prd';
}

/**
* @return array<int, object>
*/
public function middleware(): array
{
return [new RateLimited('llm:requests')];
Expand All @@ -68,9 +72,15 @@ public function handle(): void
]);

try {
// Load template if set
$template = $run->project->prdTemplate;

$providerEnum = $this->resolveProvider($run->provider);
$system = view('prompts.prd.system')->render();
$prompt = view('prompts.prd.user', ['project' => $run->project])->render();
$prompt = view('prompts.prd.user', [
'project' => $run->project,
'template' => $template,
])->render();

$response = Prism::text()
->using($providerEnum, $run->model)
Expand Down Expand Up @@ -109,6 +119,11 @@ public function handle(): void
// Point document to new version
$doc->update(['current_version_id' => $version->id]);

// Record template usage
if ($template) {
$template->recordUsage();
}

// Mark step as succeeded
$step->update([
'status' => PlanRunStepStatus::Succeeded,
Expand Down
10 changes: 5 additions & 5 deletions app/Jobs/GenerateTasksJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Prism\Prism\Enums\Provider;
use Prism\Prism\Exceptions\PrismRateLimitedException;
use Prism\Prism\Facades\Prism;
use Relaticle\Flowforge\Services\Rank;
use Relaticle\Flowforge\Services\DecimalPosition;
use Throwable;

class GenerateTasksJob implements ShouldBeUnique, ShouldQueue
Expand Down Expand Up @@ -146,8 +146,8 @@ private function persistTasks(string $projectId, TaskSet $taskSet, array $struct
$tasks = $structured['tasks'] ?? [];
$tempIdMap = [];

// Generate lexicographic positions for proper Flowforge ordering
$currentRank = Rank::forEmptySequence();
// Generate decimal positions for Flowforge ordering
$currentPosition = DecimalPosition::forEmptyColumn();

foreach ($tasks as $data) {
$task = Task::create([
Expand All @@ -165,11 +165,11 @@ private function persistTasks(string $projectId, TaskSet $taskSet, array $struct
'source_refs' => $data['source_refs'] ?? [],
'labels' => $data['labels'] ?? [],
'depends_on' => [],
'position' => $currentRank->get(),
'position' => $currentPosition,
]);

// Generate next position
$currentRank = Rank::after($currentRank);
$currentPosition = DecimalPosition::after($currentPosition);

if (isset($data['temp_id'])) {
$tempIdMap[$data['temp_id']] = $task->id;
Expand Down
15 changes: 14 additions & 1 deletion app/Jobs/GenerateTechSpecJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class GenerateTechSpecJob implements ShouldBeUnique, ShouldQueue

public int $tries = 5;

/** @var array<int, int> */
public array $backoff = [10, 30, 60, 120, 300];

public int $uniqueFor = 3600; // 1 hour
public int $uniqueFor = 3600;

public function __construct(public string $planRunId)
{
Expand All @@ -42,6 +43,9 @@ public function uniqueId(): string
return $this->planRunId.':tech';
}

/**
* @return array<int, object>
*/
public function middleware(): array
{
return [new RateLimited('llm:requests')];
Expand Down Expand Up @@ -72,11 +76,15 @@ public function handle(): void

$prdText = $prdDoc?->currentVersion?->content_md ?? '';

// Load template if set
$template = $run->project->techTemplate;

$providerEnum = $this->resolveProvider($run->provider);
$system = view('prompts.tech.system')->render();
$prompt = view('prompts.tech.user', [
'project' => $run->project,
'prd' => $prdText,
'template' => $template,
])->render();

$response = Prism::text()
Expand Down Expand Up @@ -116,6 +124,11 @@ public function handle(): void
// Point document to new version
$doc->update(['current_version_id' => $version->id]);

// Record template usage
if ($template) {
$template->recordUsage();
}

// Mark step as succeeded
$step->update([
'status' => PlanRunStepStatus::Succeeded,
Expand Down
Loading
Loading