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
128 changes: 128 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Changelog

All notable changes to Gate will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.0] - 2026-01-05

### Added

- **Attribution Check** - Automatically detects and removes Claude Code attribution from commits
- New `AttributionCheck` class for `gate certify`
- New `gate check:attribution` command with `--fix` option
- Enforces clean commit messages without AI co-authorship

- **Logic & Atomicity Validation** - AI-powered commit analysis using Ollama
- New `LogicCheck` class validates commits are atomic (single purpose)
- Ensures all changes in a commit are related
- Detects logic issues and incomplete implementations
- Uses `llama3.2:3b` model for fast local analysis (3-8 seconds)
- New `gate check:logic` command

- **PR Cohesion Analysis** - Cross-file relationship validation
- New `CohesionCheck` class analyzes PRs holistically
- Detects missing files (tests, migrations, etc.)
- Validates MVC architecture coherence
- Checks cross-file dependencies make sense
- New `gate check:cohesion` command

- **Git Hooks Installation** - Easy hook setup for any repository
- New `gate install` command
- Automatically installs pre-commit hooks
- Creates `.gate/config.php` for customization
- Hooks call `gate certify` before each commit

- **AI-Powered GitHub Actions Workflows**
- Layer 3: AI Code Review with Ollama (qwen2.5-coder:7b)
- Pattern analysis (N+1 queries, fat controllers, anti-patterns)
- Security analysis (SQL injection, XSS, CSRF, mass assignment)
- Test suggestions with specific scenarios
- Model caching reduces CI time from 5min to 30sec
- Layer 4: Semantic Release Automation
- Auto-versioning based on conventional commits
- Automatic CHANGELOG.md generation
- GitHub release creation with release notes
- Runs on merge to main/master

### Changed

- **CertifyCommand** - Now includes all new checks in order:
1. Attribution Check
2. Logic & Atomicity (Ollama)
3. Tests & Coverage
4. Security Audit
5. Pest Syntax
6. PR Cohesion (Ollama)

- **Check Architecture** - Expanded CheckInterface pattern to support AI validation
- All checks now follow consistent CheckResult pattern
- Better error reporting with detailed failure messages
- Compact mode shows single-line status for all checks

- **README** - Comprehensive rewrite documenting all new features
- Phase-based validation architecture
- AI model information and configuration
- Updated quick start guide
- New command examples

### Technical Details

- Uses [Ollama](https://ollama.com) for local AI models (free, no API costs)
- Models auto-download on first use
- Graceful degradation when Ollama not available (skips AI checks)
- Compatible with existing v1.x workflows
- All new checks implement `CheckInterface`
- Uses `SymfonyProcessRunner` for command execution

### Migration Guide

#### From v1.x to v2.0.0

**No breaking changes** - v2.0.0 is backwards compatible with v1.x

Optional: Install new git hooks for pre-commit validation:

```bash
cd your-repo
gate install
```

Optional: Add Ollama for AI validation:

```bash
# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh

# Models will auto-download on first use
# Or manually pull:
ollama pull llama3.2:3b
ollama pull qwen2.5-coder:7b
```

Update GitHub Actions (optional):

```yaml
# Change from v1 to v2
- uses: synapse-sentinel/gate@v2
```

Add AI review workflow (optional):

```bash
# Copy from prototypes/gate-v1/
cp prototypes/gate-v1/layer-3-ai-review.yml .github/workflows/gate-ai-review.yml
cp prototypes/gate-v1/layer-4-release.yml .github/workflows/gate-release.yml
```

## [1.4.1] - 2024-12-XX
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Placeholder date needs to be filled in.

The v1.4.1 release date shows 2024-12-XX which appears to be a placeholder that should be replaced with the actual release date.

🤖 Prompt for AI Agents
In @CHANGELOG.md around line 119, The CHANGELOG entry for version identifier
[1.4.1] currently uses a placeholder date "2024-12-XX"; update that header line
to replace "2024-12-XX" with the actual release date (e.g., "2024-12-15") so the
line reads "## [1.4.1] - YYYY-MM-DD" using the correct release date for v1.4.1.


### Previous Release
- Tests & Coverage validation
- Security Audit
- Pest Syntax checking
- GitHub Checks API integration

[2.0.0]: https://github.com/synapse-sentinel/gate/compare/v1.4.1...v2.0.0
[1.4.1]: https://github.com/synapse-sentinel/gate/releases/tag/v1.4.1
92 changes: 79 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
# Synapse Sentinel Gate

Universal code quality gate for the Jordan ecosystem. Enforces consistent standards across all repositories.
Universal code quality gate with AI-powered validation. Enforces consistent standards across all repositories using local Ollama models.

## Quick Start

Add to your repository's workflow:
Install gate hooks in your repository:

```bash
# Install gate globally
composer global require synapse-sentinel/gate

# Install hooks in your repository
cd /path/to/your/repo
gate install
```

Or use in GitHub Actions:

```yaml
name: Gate
Expand All @@ -19,9 +30,9 @@ jobs:
pull-requests: write # Required for PR comments
steps:
- uses: actions/checkout@v4
- uses: synapse-sentinel/gate@v1
- uses: synapse-sentinel/gate@v2
with:
coverage-threshold: 100
coverage-threshold: 80
```

### Required Permissions
Expand All @@ -36,15 +47,26 @@ Without these permissions, the action will run successfully but features will si

## What It Checks

### Technical Gate (Phase 1)
### Phase 1: Pre-Commit Validation (Local, <10s)
- **Attribution Check**: Removes Claude Code attribution from commits
- **Logic & Atomicity**: AI validation that commits are atomic and coherent (Ollama)
- **Syntax Check**: Fast syntax validation

### Phase 2: CI/CD Validation (GitHub Actions, 2-5min)
- **Tests & Coverage**: Runs `pest --coverage --min=X`
- **Security Audit**: Runs `composer audit` for vulnerabilities
- **Pest Syntax**: Validates all tests use `describe()/it()` blocks
- **PR Cohesion**: Cross-file analysis for missing files and MVC coherence (Ollama)

### Phase 3: AI Code Review (GitHub Actions, 30s with caching)
- **Pattern Analysis**: Detects Laravel anti-patterns (N+1 queries, fat controllers)
- **Security Analysis**: Identifies SQL injection, XSS, mass assignment issues
- **Test Suggestions**: Generates specific test recommendations

### Business Logic Gate (Phase 2 - Coming Soon)
- Issue intent matching
- Architectural compliance
- Over/under-engineering detection
### Phase 4: Semantic Release (On merge to main)
- **Auto-versioning**: Based on conventional commits (feat, fix, BREAKING)
- **Changelog Generation**: Automatic CHANGELOG.md updates
- **GitHub Releases**: Automated release creation with notes

## Inputs

Expand All @@ -69,11 +91,55 @@ Without these permissions, the action will run successfully but features will si
## Local Usage

```bash
# Run gate on current directory
php gate run --coverage=100
# Install gate globally
composer global require synapse-sentinel/gate

# Install hooks in your repository
gate install

# Run full certification
gate certify --coverage=80

# Run individual checks
gate check:attribution # Check for Claude Code attribution
gate check:attribution --fix # Remove attribution automatically
gate check:logic # Validate commit atomicity (Ollama)
gate check:cohesion # Analyze PR cohesion (Ollama)

# Compact output mode
gate certify --compact
```

## AI Models

Gate uses [Ollama](https://ollama.com) for local AI validation:

- **llama3.2:3b** - Fast atomicity and logic checks (3-8 seconds)
- **qwen2.5-coder:7b** - Deep code review in CI (with caching)

Models are automatically downloaded when first needed. Ollama is optional - gate works without it but skips AI checks.

## Configuration

After running `gate install`, edit `.gate/config.php`:

# Run with lower threshold
php gate run --coverage=80
```php
return [
'pre_commit' => [
'attribution' => true, // Remove Claude attribution
'logic' => true, // Ollama atomicity check
'syntax' => true, // Fast syntax validation
],
'ci_checks' => [
'tests' => true,
'security' => true,
'cohesion' => true, // PR cross-file analysis
],
'ollama' => [
'model' => 'llama3.2:3b',
'timeout' => 30,
],
];
```

## Development
Expand Down
70 changes: 70 additions & 0 deletions app/Checks/AttributionCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace App\Checks;

use App\Contracts\ProcessRunner;
use App\Services\SymfonyProcessRunner;

final class AttributionCheck implements CheckInterface
{
private array $attributionPatterns = [
'/🤖 Generated with \[Claude Code\]/i',
'/Generated with Claude Code/i',
'/Co-Authored-By: Claude/i',
'/Co-authored-by: Claude/i',
'/noreply@anthropic\.com/i',
];

public function __construct(
private readonly ProcessRunner $processRunner = new SymfonyProcessRunner,
) {}

public function name(): string
{
return 'Attribution Check';
}

public function run(string $workingDirectory): CheckResult
{
$result = $this->processRunner->run(
['git', 'log', '-1', '--pretty=%B'],
$workingDirectory,
timeout: 5,
);

if (! $result->successful || empty(trim($result->output))) {
return CheckResult::pass('No commit to check');
}

$commitMessage = trim($result->output);

if (! $this->hasAttribution($commitMessage)) {
return CheckResult::pass('No Claude attribution found');
}

$foundPatterns = [];
foreach ($this->attributionPatterns as $pattern) {
if (preg_match($pattern, $commitMessage)) {
$foundPatterns[] = str_replace(['/', 'i'], '', $pattern);
}
}
Comment on lines +47 to +52
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Pattern sanitization incorrectly removes literal 'i' characters.

The str_replace(['/', 'i'], '', $pattern) approach is too aggressive. For example, the pattern /noreply@anthropic\.com/i becomes noreply@anthropc\.com (missing the 'i' in "anthropic").

🔎 Proposed fix using regex to strip only delimiters and modifiers
         foreach ($this->attributionPatterns as $pattern) {
             if (preg_match($pattern, $commitMessage)) {
-                $foundPatterns[] = str_replace(['/', 'i'], '', $pattern);
+                $foundPatterns[] = preg_replace('#^/|/[a-z]*$#', '', $pattern);
             }
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$foundPatterns = [];
foreach ($this->attributionPatterns as $pattern) {
if (preg_match($pattern, $commitMessage)) {
$foundPatterns[] = str_replace(['/', 'i'], '', $pattern);
}
}
$foundPatterns = [];
foreach ($this->attributionPatterns as $pattern) {
if (preg_match($pattern, $commitMessage)) {
$foundPatterns[] = preg_replace('#^/|/[a-z]*$#', '', $pattern);
}
}


return CheckResult::fail(
'Claude Code attribution detected in commit',
$foundPatterns
);
}

private function hasAttribution(string $message): bool
{
foreach ($this->attributionPatterns as $pattern) {
if (preg_match($pattern, $message)) {
return true;
}
}

return false;
}
}
Loading
Loading