Skip to content
Open
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
22 changes: 19 additions & 3 deletions app/Commands/AnalyzeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ class AnalyzeCommand extends Command

protected $description = 'Send failures to Prefrontal Cortex for AI analysis';

private ?Client $httpClient = null;

private ?string $mockRepo = null;

private ?string $mockSha = null;

/** @internal For testing only */
public function withMocks(?Client $httpClient = null, ?string $repo = null, ?string $sha = null): self
{
$this->httpClient = $httpClient;
$this->mockRepo = $repo;
$this->mockSha = $sha;

return $this;
}

public function handle(): int
{
$apiUrl = $this->option('api-url') ?? getenv('PREFRONTAL_API_URL') ?: 'https://prefrontal.jordanpartridge.us';
Expand Down Expand Up @@ -52,7 +68,7 @@ public function handle(): int
$this->info('🧠 Sending failures to Prefrontal Cortex for analysis...');

try {
$client = new Client([
$client = $this->httpClient ?? new Client([
'base_uri' => $apiUrl,
'timeout' => 60,
]);
Expand All @@ -64,8 +80,8 @@ public function handle(): int
'Content-Type' => 'application/json',
],
'json' => [
'repo' => $this->detectRepo(),
'sha' => $this->detectSha(),
'repo' => $this->mockRepo ?? $this->detectRepo(),
'sha' => $this->mockSha ?? $this->detectSha(),
'failures' => $failures,
],
]);
Expand Down
3 changes: 1 addition & 2 deletions app/Commands/CertifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use App\Branding;
use App\Checks\CheckInterface;
use App\Checks\CheckResult;
use App\Checks\PestSyntaxValidator;
use App\Checks\SecurityScanner;
use App\Checks\TestRunner;
Expand Down Expand Up @@ -123,7 +122,7 @@ public function handle(): int
$checksClient->postCertificationComment($checkResults);
} else {
// Post actionable prompt with fix directions on failure
$assembler = new PromptAssembler();
$assembler = new PromptAssembler;
$assembled = $assembler->assemble($rawOutputs);

if ($assembled['prompt'] !== '') {
Expand Down
5 changes: 5 additions & 0 deletions app/GitHub/ChecksClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function createCheck(string $name, string $status = 'in_progress'): ?int
return $data['id'] ?? null;
} catch (GuzzleException $e) {
$this->logError('createCheck', $e);

return null;
}
}
Expand Down Expand Up @@ -119,6 +120,7 @@ public function completeCheck(
return true;
} catch (GuzzleException $e) {
$this->logError('completeCheck', $e);

return false;
}
}
Expand Down Expand Up @@ -155,6 +157,7 @@ public function reportCheck(
return true;
} catch (GuzzleException $e) {
$this->logError('reportCheck', $e);

return false;
}
}
Expand Down Expand Up @@ -199,6 +202,7 @@ public function postCertificationComment(array $checkResults): bool
return true;
} catch (GuzzleException $e) {
$this->logError('postCertificationComment', $e);

return false;
}
}
Expand Down Expand Up @@ -234,6 +238,7 @@ public function postActionablePrompt(string $prompt): bool
return true;
} catch (GuzzleException $e) {
$this->logError('postActionablePrompt', $e);

return false;
}
}
Expand Down
8 changes: 4 additions & 4 deletions app/Services/PromptAssembler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ final class PromptAssembler
public function __construct()
{
$this->transformers = [
new PhpStanPromptTransformer(),
new TestFailurePromptTransformer(),
new PhpStanPromptTransformer,
new TestFailurePromptTransformer,
];
}

Expand Down Expand Up @@ -94,7 +94,7 @@ public function transform(string $checkName, string $output): array
private function buildCombinedPrompt(array $failedChecks): string
{
$count = count($failedChecks);
$prompt = "# 🔧 Synapse Sentinel: {$count} check" . ($count === 1 ? '' : 's') . " need attention\n\n";
$prompt = "# 🔧 Synapse Sentinel: {$count} check".($count === 1 ? '' : 's')." need attention\n\n";
$prompt .= "The following issues must be resolved before this PR can be merged:\n\n";

foreach ($failedChecks as $checkName => $section) {
Expand All @@ -117,6 +117,6 @@ private function truncate(string $text, int $maxLength = 2000): string
return $text;
}

return substr($text, 0, $maxLength) . "\n... (truncated)";
return substr($text, 0, $maxLength)."\n... (truncated)";
}
}
2 changes: 1 addition & 1 deletion app/Transformers/PhpStanPromptTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private function buildPrompt(array $data): array
$relativePath = $this->relativePath($filePath);
$errorCount = $fileData['errors'] ?? 0;

$prompt .= "### {$relativePath} ({$errorCount} error" . ($errorCount === 1 ? '' : 's') . ")\n\n";
$prompt .= "### {$relativePath} ({$errorCount} error".($errorCount === 1 ? '' : 's').")\n\n";

foreach ($fileData['messages'] ?? [] as $index => $message) {
$prompt .= $this->formatError($index + 1, $message);
Expand Down
3 changes: 1 addition & 2 deletions app/Transformers/TestFailurePromptTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ private function parseJunitXml(string $xml): array
/**
* Extract test cases from a test suite.
*
* @param \SimpleXMLElement $suite
* @param array<array<string, mixed>> $failures
* @param array<array<string, mixed>> $errors
*/
Expand Down Expand Up @@ -246,7 +245,7 @@ private function cleanMessage(string $message): string

// Truncate if too long
if (strlen($clean) > 500) {
$clean = substr($clean, 0, 500) . '... (truncated)';
$clean = substr($clean, 0, 500).'... (truncated)';
}

return trim($clean);
Expand Down
Loading
Loading