Compare commits
7 Commits
claude/aud
...
claude/ado
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b4e3f0450 | ||
|
|
a60ca84dc0 | ||
|
|
b580f9e2e1 | ||
|
|
8e59f8ff36 | ||
|
|
3cb9ffb70d | ||
|
|
0b247646ca | ||
|
|
1dfd926437 |
147
.github/workflows/ci.yml
vendored
147
.github/workflows/ci.yml
vendored
@@ -1,134 +1,27 @@
|
|||||||
name: CI — Lint & Test
|
##
|
||||||
|
# Thin CI caller — peptide-news-plugin
|
||||||
|
#
|
||||||
|
# Delegates all lint/test/file-size jobs to the estate reusable workflow.
|
||||||
|
# Per estate standard: workflow_call is required so deploy.yml can gate on it.
|
||||||
|
# See: peptiderepo/peptide-e2e/.github/workflows/ci.yml@main for job definitions.
|
||||||
|
##
|
||||||
|
name: CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
pull_request: {}
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [main]
|
||||||
pull_request:
|
workflow_call: {}
|
||||||
branches: [ main ]
|
|
||||||
workflow_call:
|
|
||||||
|
|
||||||
|
# Required: calling workflow must declare contents: write so the reusable
|
||||||
|
# phpcs job can commit phpcbf auto-fixes back to the PR branch.
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# ── PHP Syntax Check ─────────────────────────────────────────────
|
ci:
|
||||||
lint-php:
|
uses: peptiderepo/peptide-e2e/.github/workflows/ci.yml@main
|
||||||
name: PHP Lint (${{ matrix.php }})
|
with:
|
||||||
runs-on: ubuntu-latest
|
tests: stubs
|
||||||
strategy:
|
has_js: true
|
||||||
matrix:
|
secrets: inherit
|
||||||
php: ['8.1', '8.2', '8.3']
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up PHP ${{ matrix.php }}
|
|
||||||
uses: shivammathur/setup-php@v2
|
|
||||||
with:
|
|
||||||
php-version: ${{ matrix.php }}
|
|
||||||
tools: composer
|
|
||||||
|
|
||||||
- name: Syntax check all PHP files
|
|
||||||
run: find . -name '*.php' -not -path './vendor/*' -print0 | xargs -0 -n1 php -l
|
|
||||||
|
|
||||||
# ── Security Audit ───────────────────────────────────────────────
|
|
||||||
security-audit:
|
|
||||||
name: Security Audit
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Check for common PHP security issues
|
|
||||||
run: |
|
|
||||||
echo ":: Checking for direct SQL queries without prepare..."
|
|
||||||
# Exclude uninstall.php (DROP TABLE is standard WP pattern), activator (table DDL),
|
|
||||||
# and logger (TRUNCATE) — these use $wpdb->prefix which is safe internal state.
|
|
||||||
if grep -r "query\s*(\s*['\"].*\$" --include="*.php" --exclude-dir=vendor . 2>/dev/null \
|
|
||||||
| grep -v "\\\$wpdb->prepare" \
|
|
||||||
| grep -v "uninstall\.php" \
|
|
||||||
| grep -v "class-peptide-news-activator\.php" \
|
|
||||||
| grep -v "class-peptide-news-logger\.php" \
|
|
||||||
| grep -v "DROP TABLE" \
|
|
||||||
| grep -v "TRUNCATE" \
|
|
||||||
&& [ \${PIPESTATUS[0]} -eq 0 ]; then
|
|
||||||
echo "WARNING: Found potential unescaped SQL queries. Use wpdb->prepare() for all dynamic SQL."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ":: Checking for eval() usage..."
|
|
||||||
if grep -r "eval\s*(" --include="*.php" --exclude-dir=vendor . 2>/dev/null; then
|
|
||||||
echo "ERROR: eval() found. This is a critical security risk."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ":: Checking for base64_decode without validation..."
|
|
||||||
if grep -r "base64_decode\s*(" --include="*.php" --exclude-dir=vendor . 2>/dev/null; then
|
|
||||||
echo "WARNING: Found base64_decode(). Ensure the input is properly validated."
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ":: Checking for file_get_contents with user input..."
|
|
||||||
if grep -r "file_get_contents\s*(\s*\$" --include="*.php" --exclude-dir=vendor . 2>/dev/null; then
|
|
||||||
echo "WARNING: Found file_get_contents with variable. Ensure input is validated and restricted."
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "All security checks passed."
|
|
||||||
|
|
||||||
# ── PHPCS Coding Standards ───────────────────────────────────────
|
|
||||||
phpcs:
|
|
||||||
name: PHPCS
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up PHP
|
|
||||||
uses: shivammathur/setup-php@v2
|
|
||||||
with:
|
|
||||||
php-version: '8.3'
|
|
||||||
tools: composer
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: composer install --prefer-dist --no-progress
|
|
||||||
|
|
||||||
- name: Run PHPCS
|
|
||||||
run: vendor/bin/phpcs --standard=.phpcs.xml.dist
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
# ── PHPUnit Tests ────────────────────────────────────────────────
|
|
||||||
phpunit:
|
|
||||||
name: PHPUnit (${{ matrix.php }})
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
php: ['8.1', '8.2', '8.3']
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up PHP ${{ matrix.php }}
|
|
||||||
uses: shivammathur/setup-php@v2
|
|
||||||
with:
|
|
||||||
php-version: ${{ matrix.php }}
|
|
||||||
tools: composer
|
|
||||||
coverage: xdebug
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: composer install --prefer-dist --no-progress
|
|
||||||
|
|
||||||
- name: Run PHPUnit
|
|
||||||
run: vendor/bin/phpunit --testdox
|
|
||||||
|
|
||||||
# ── JavaScript Lint ──────────────────────────────────────────────
|
|
||||||
lint-js:
|
|
||||||
name: JS Lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Node
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: '20'
|
|
||||||
|
|
||||||
- name: Check JS syntax
|
|
||||||
run: |
|
|
||||||
for f in $(find . -name '*.js' -not -path './vendor/*' -not -path './node_modules/*' -not -path '*/vendor/*'); do
|
|
||||||
node --check "$f" || exit 1
|
|
||||||
done
|
|
||||||
|
|||||||
314
.github/workflows/cto-review.yml
vendored
314
.github/workflows/cto-review.yml
vendored
@@ -1,20 +1,17 @@
|
|||||||
name: CTO Review
|
name: CTO Review
|
||||||
|
|
||||||
# Automated PR review powered by Claude + DeepSeek + Kimi (via OpenRouter)
|
# Automated PR review powered by Claude Haiku (via OpenRouter).
|
||||||
# plus Neurometric PR-Summarizer (a Qwen3-4B task-specialist SLM).
|
|
||||||
#
|
#
|
||||||
# During the A/B window (until further notice), every PR gets reviewed by FOUR models
|
# A/B panel decision 2026-06-12: panel dropped to Haiku-only.
|
||||||
# in parallel. The PR comment shows each model's verdict side-by-side so we can compare
|
# Evidence: convo/cto/threads/2026-06-qa-ab-review/02-analyst-findings.md
|
||||||
# quality/cost on real PRs before picking a permanent default.
|
# DeepSeek: high false-positive rate (absint()="code exec", PLUGIN_DIR="dir traversal").
|
||||||
|
# Kimi: ~60% model failure rate across 13 PRs sampled.
|
||||||
|
# Neurometric: summarizer only, zero unique-real findings, unreliable heuristic verdict.
|
||||||
|
# Haiku: 0 failures, lowest noise, equivalent real-signal catch rate vs 4-voice panel.
|
||||||
#
|
#
|
||||||
# Neurometric is a "prose voice": it does not support OpenAI tool-calling, so its
|
# Does NOT merge. Posts formal APPROVE/REQUEST_CHANGES/COMMENT reviews.
|
||||||
# contribution is raw markdown + a heuristic verdict. It is never the primary voice.
|
|
||||||
#
|
#
|
||||||
# Does NOT merge. Does NOT post formal APPROVE/REQUEST_CHANGES reviews — always COMMENT
|
# Requires repo secret: OPENROUTER_API_KEY
|
||||||
# (GITHUB_TOKEN can't formally approve PRs without repo-setting toggle).
|
|
||||||
#
|
|
||||||
# Requires repo secrets: OPENROUTER_API_KEY, NEUROMETRIC_API_KEY (optional; the
|
|
||||||
# Neurometric voice self-skips with an inline error note if the key is missing).
|
|
||||||
#
|
#
|
||||||
# Cost cap: tracked in Repository Variables (CTO_REVIEW_SPEND_CENTS, CTO_REVIEW_CAP_CENTS).
|
# Cost cap: tracked in Repository Variables (CTO_REVIEW_SPEND_CENTS, CTO_REVIEW_CAP_CENTS).
|
||||||
# Default cap is 1000 cents ($10/month). Auto-resets on the 1st of each month.
|
# Default cap is 1000 cents ($10/month). Auto-resets on the 1st of each month.
|
||||||
@@ -123,17 +120,18 @@ jobs:
|
|||||||
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=50
|
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=50
|
||||||
BASE_SHA="${{ github.event.pull_request.base.sha }}"
|
BASE_SHA="${{ github.event.pull_request.base.sha }}"
|
||||||
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
|
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
|
||||||
DIFF=$(git diff --no-color "$BASE_SHA" "$HEAD_SHA" | head -c 400000)
|
# Write the diff to a file, not a step output / env var. Passing a
|
||||||
|
# ~400KB diff through the process env (execve argv+envp) exceeds the
|
||||||
|
# runner ARG_MAX and fails the next step with "Argument list too long".
|
||||||
|
# File transport also sidesteps the ~1MB step-output cap.
|
||||||
|
git diff --no-color "$BASE_SHA" "$HEAD_SHA" | head -c 400000 > /tmp/cto-review-diff.txt
|
||||||
FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
|
FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
|
||||||
SIZE=$(echo -n "$DIFF" | wc -c)
|
SIZE=$(wc -c < /tmp/cto-review-diff.txt)
|
||||||
{
|
{
|
||||||
echo "size=$SIZE"
|
echo "size=$SIZE"
|
||||||
echo "files<<EOF_FILES"
|
echo "files<<EOF_FILES"
|
||||||
echo "$FILES"
|
echo "$FILES"
|
||||||
echo "EOF_FILES"
|
echo "EOF_FILES"
|
||||||
echo "diff<<EOF_DIFF"
|
|
||||||
echo "$DIFF"
|
|
||||||
echo "EOF_DIFF"
|
|
||||||
} >> "$GITHUB_OUTPUT"
|
} >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Load repo conventions
|
- name: Load repo conventions
|
||||||
@@ -150,18 +148,17 @@ jobs:
|
|||||||
echo "EOF_CONV"
|
echo "EOF_CONV"
|
||||||
} >> "$GITHUB_OUTPUT"
|
} >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Call 4 models in parallel (OpenRouter + Neurometric)
|
- name: Call Haiku via OpenRouter
|
||||||
if: steps.budget.outputs.skip != 'true'
|
if: steps.budget.outputs.skip != 'true'
|
||||||
id: review
|
id: review
|
||||||
env:
|
env:
|
||||||
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
|
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
|
||||||
NEUROMETRIC_API_KEY: ${{ secrets.NEUROMETRIC_API_KEY }}
|
|
||||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||||
PR_BODY: ${{ github.event.pull_request.body }}
|
PR_BODY: ${{ github.event.pull_request.body }}
|
||||||
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
|
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
|
||||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
REPO_NAME: ${{ github.event.repository.name }}
|
REPO_NAME: ${{ github.event.repository.name }}
|
||||||
DIFF: ${{ steps.diff.outputs.diff }}
|
DIFF_PATH: /tmp/cto-review-diff.txt
|
||||||
DIFF_SIZE: ${{ steps.diff.outputs.size }}
|
DIFF_SIZE: ${{ steps.diff.outputs.size }}
|
||||||
CHANGED_FILES: ${{ steps.diff.outputs.files }}
|
CHANGED_FILES: ${{ steps.diff.outputs.files }}
|
||||||
CONVENTIONS: ${{ steps.conventions.outputs.content }}
|
CONVENTIONS: ${{ steps.conventions.outputs.content }}
|
||||||
@@ -183,24 +180,17 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
python3 - <<'PY'
|
python3 - <<'PY'
|
||||||
import json, os, sys, urllib.request, concurrent.futures
|
import json, os, sys, urllib.request
|
||||||
|
|
||||||
api_key = os.environ["OPENROUTER_API_KEY"]
|
api_key = os.environ["OPENROUTER_API_KEY"]
|
||||||
|
|
||||||
# A/B harness: four models. Each gets the same prompt.
|
# Haiku-only reviewer. A/B panel dropped 2026-06-12 per QA data:
|
||||||
# Primary model's verdict drives the heading. Others are labeled.
|
# DeepSeek high false-positive rate, Kimi ~60% failure rate,
|
||||||
# Edit this list to change the roster (or drop to 1 after A/B window closes).
|
# Neurometric zero unique-real findings. Haiku retained as sole voice.
|
||||||
#
|
MODEL_SLUG = "anthropic/claude-haiku-4.5"
|
||||||
# provider_type semantics:
|
MODEL_DISPLAY = "Claude Haiku 4.5"
|
||||||
# - "openrouter_tools": OpenAI tool-calling via OpenRouter; structured verdict.
|
INPUT_PER_M_USD = 1.00
|
||||||
# - "neurometric_prose": Neurometric marketplace SLM; prose output + heuristic verdict.
|
OUTPUT_PER_M_USD = 5.00
|
||||||
MODELS = [
|
|
||||||
# (slug, display name, input_per_M_USD, output_per_M_USD, is_primary, provider_type)
|
|
||||||
("anthropic/claude-haiku-4.5", "Claude Haiku 4.5", 1.00, 5.00, True, "openrouter_tools"),
|
|
||||||
("deepseek/deepseek-chat-v3.1", "DeepSeek V3.1", 0.15, 0.75, False, "openrouter_tools"),
|
|
||||||
("moonshotai/kimi-k2-thinking", "Kimi K2 Thinking", 0.60, 2.50, False, "openrouter_tools"),
|
|
||||||
("neurometric/pr-summarizer", "Neurometric PR-Summarizer (Qwen3-4B)", 0.00, 0.00, False, "neurometric_prose"),
|
|
||||||
]
|
|
||||||
|
|
||||||
system = """You are the CTO and lead reviewer for the peptiderepo project. You are reviewing a pull request opened by an autonomous agent or human contributor.
|
system = """You are the CTO and lead reviewer for the peptiderepo project. You are reviewing a pull request opened by an autonomous agent or human contributor.
|
||||||
|
|
||||||
@@ -229,7 +219,9 @@ jobs:
|
|||||||
user_blocks.append(f"**Changed files:**\n```\n{os.environ['CHANGED_FILES']}\n```\n")
|
user_blocks.append(f"**Changed files:**\n```\n{os.environ['CHANGED_FILES']}\n```\n")
|
||||||
if os.environ.get("CONVENTIONS", "").strip():
|
if os.environ.get("CONVENTIONS", "").strip():
|
||||||
user_blocks.append(f"# Repo CONVENTIONS.md\n{os.environ['CONVENTIONS']}\n")
|
user_blocks.append(f"# Repo CONVENTIONS.md\n{os.environ['CONVENTIONS']}\n")
|
||||||
user_blocks.append(f"# Diff\n```diff\n{os.environ['DIFF']}\n```\n")
|
with open(os.environ["DIFF_PATH"], encoding="utf-8", errors="replace") as _df:
|
||||||
|
_diff_text = _df.read()
|
||||||
|
user_blocks.append(f"# Diff\n```diff\n{_diff_text}\n```\n")
|
||||||
user_message = "\n\n".join(user_blocks)
|
user_message = "\n\n".join(user_blocks)
|
||||||
|
|
||||||
tools = [{
|
tools = [{
|
||||||
@@ -261,218 +253,100 @@ jobs:
|
|||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
|
||||||
PER_MODEL_TIMEOUT = 60 # seconds; one hung model should not block siblings
|
body = {
|
||||||
|
"model": MODEL_SLUG,
|
||||||
|
"max_tokens": 2048,
|
||||||
|
"messages": [
|
||||||
|
{"role": "system", "content": system},
|
||||||
|
{"role": "user", "content": user_message}
|
||||||
|
],
|
||||||
|
"tools": tools,
|
||||||
|
"tool_choice": {"type": "function", "function": {"name": "submit_review"}}
|
||||||
|
}
|
||||||
|
req = urllib.request.Request(
|
||||||
|
"https://openrouter.ai/api/v1/chat/completions",
|
||||||
|
data=json.dumps(body).encode(),
|
||||||
|
headers={
|
||||||
|
"Authorization": f"Bearer {api_key}",
|
||||||
|
"content-type": "application/json",
|
||||||
|
"HTTP-Referer": "https://github.com/peptiderepo",
|
||||||
|
"X-Title": f"peptiderepo CTO reviewer ({MODEL_DISPLAY})"
|
||||||
|
},
|
||||||
|
method="POST"
|
||||||
|
)
|
||||||
|
|
||||||
# Heuristic verdict inference for prose-voice models that can't do tool-calling.
|
error = None
|
||||||
# Keyword order matters: block markers beat approve markers.
|
review = None
|
||||||
PROSE_BLOCK_MARKERS = [
|
cost_cents = 0.0
|
||||||
"do not merge", "do not approve", "should not be merged", "reject this",
|
ptok = 0
|
||||||
"critical security", "critical issue", "critical vulnerability",
|
ctok = 0
|
||||||
"blocker", "blocking issue", "request_changes", "request changes",
|
|
||||||
"**critical**", "sql injection", "must be addressed before",
|
|
||||||
]
|
|
||||||
PROSE_APPROVE_MARKERS = [
|
|
||||||
"safe to merge", "ready to merge", "no blocking issues", "lgtm",
|
|
||||||
"approve this", "looks good to merge", "no concerns",
|
|
||||||
]
|
|
||||||
|
|
||||||
def infer_verdict_from_prose(text):
|
try:
|
||||||
t = (text or "").lower()
|
with urllib.request.urlopen(req, timeout=60) as resp:
|
||||||
if any(m in t for m in PROSE_BLOCK_MARKERS):
|
data = json.loads(resp.read())
|
||||||
return "REQUEST_CHANGES"
|
except Exception as e:
|
||||||
if any(m in t for m in PROSE_APPROVE_MARKERS):
|
error = str(e)[:300]
|
||||||
return "APPROVE"
|
data = {}
|
||||||
return "COMMENT"
|
|
||||||
|
|
||||||
def call_openrouter_tools(slug, display, in_rate, out_rate, is_primary):
|
|
||||||
body = {
|
|
||||||
"model": slug,
|
|
||||||
"max_tokens": 2048,
|
|
||||||
"messages": [
|
|
||||||
{"role": "system", "content": system},
|
|
||||||
{"role": "user", "content": user_message}
|
|
||||||
],
|
|
||||||
"tools": tools,
|
|
||||||
"tool_choice": {"type": "function", "function": {"name": "submit_review"}}
|
|
||||||
}
|
|
||||||
req = urllib.request.Request(
|
|
||||||
"https://openrouter.ai/api/v1/chat/completions",
|
|
||||||
data=json.dumps(body).encode(),
|
|
||||||
headers={
|
|
||||||
"Authorization": f"Bearer {api_key}",
|
|
||||||
"content-type": "application/json",
|
|
||||||
"HTTP-Referer": "https://github.com/peptiderepo",
|
|
||||||
"X-Title": f"peptiderepo CTO reviewer ({display})"
|
|
||||||
},
|
|
||||||
method="POST"
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
with urllib.request.urlopen(req, timeout=PER_MODEL_TIMEOUT) as resp:
|
|
||||||
data = json.loads(resp.read())
|
|
||||||
except Exception as e:
|
|
||||||
return {
|
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
|
||||||
"provider_type": "openrouter_tools",
|
|
||||||
"error": str(e)[:300],
|
|
||||||
"cost_cents": 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if not error:
|
||||||
choice = data.get("choices", [{}])[0].get("message", {})
|
choice = data.get("choices", [{}])[0].get("message", {})
|
||||||
tool_calls = choice.get("tool_calls", [])
|
tool_calls = choice.get("tool_calls", [])
|
||||||
if not tool_calls:
|
if not tool_calls:
|
||||||
return {
|
error = f"No tool_call in response. Raw content: {str(choice)[:300]}"
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
else:
|
||||||
"provider_type": "openrouter_tools",
|
try:
|
||||||
"error": f"No tool_call in response. Raw content: {str(choice)[:300]}",
|
review = json.loads(tool_calls[0]["function"]["arguments"])
|
||||||
"cost_cents": 0,
|
except Exception as e:
|
||||||
}
|
error = f"Malformed tool args: {e}"
|
||||||
|
|
||||||
try:
|
if not error:
|
||||||
review = json.loads(tool_calls[0]["function"]["arguments"])
|
usage = data.get("usage", {})
|
||||||
except Exception as e:
|
ptok = usage.get("prompt_tokens", 0)
|
||||||
return {
|
ctok = usage.get("completion_tokens", 0)
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
cost_usd = (ptok * INPUT_PER_M_USD / 1_000_000) + (ctok * OUTPUT_PER_M_USD / 1_000_000)
|
||||||
"provider_type": "openrouter_tools",
|
cost_cents = cost_usd * 100
|
||||||
"error": f"Malformed tool args: {e}",
|
|
||||||
"cost_cents": 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
usage = data.get("usage", {})
|
# Build comment
|
||||||
ptok = usage.get("prompt_tokens", 0)
|
if error:
|
||||||
ctok = usage.get("completion_tokens", 0)
|
heading_verdict = "ERROR"
|
||||||
cost_usd = (ptok * in_rate / 1_000_000) + (ctok * out_rate / 1_000_000)
|
lines = [f"## CTO Review — {heading_verdict}", ""]
|
||||||
cost_cents = cost_usd * 100
|
lines.append(f"Model failed: `{error}`")
|
||||||
return {
|
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
|
||||||
"provider_type": "openrouter_tools",
|
|
||||||
"review": review, "prompt_tokens": ptok, "completion_tokens": ctok,
|
|
||||||
"cost_cents": cost_cents,
|
|
||||||
}
|
|
||||||
|
|
||||||
def call_neurometric_prose(slug, display, is_primary):
|
|
||||||
nm_key = os.environ.get("NEUROMETRIC_API_KEY", "")
|
|
||||||
if not nm_key:
|
|
||||||
return {
|
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
|
||||||
"provider_type": "neurometric_prose",
|
|
||||||
"error": "NEUROMETRIC_API_KEY secret not set on this repo",
|
|
||||||
"cost_cents": 0,
|
|
||||||
}
|
|
||||||
body = {
|
|
||||||
"model": slug,
|
|
||||||
"max_tokens": 2048,
|
|
||||||
"messages": [
|
|
||||||
{"role": "system", "content": system},
|
|
||||||
{"role": "user", "content": user_message},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
req = urllib.request.Request(
|
|
||||||
"https://api.neurometric.ai/v1/chat/completions",
|
|
||||||
data=json.dumps(body).encode(),
|
|
||||||
headers={
|
|
||||||
"Authorization": f"Bearer {nm_key}",
|
|
||||||
"content-type": "application/json",
|
|
||||||
},
|
|
||||||
method="POST",
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
with urllib.request.urlopen(req, timeout=PER_MODEL_TIMEOUT) as resp:
|
|
||||||
data = json.loads(resp.read())
|
|
||||||
except Exception as e:
|
|
||||||
return {
|
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
|
||||||
"provider_type": "neurometric_prose",
|
|
||||||
"error": str(e)[:300],
|
|
||||||
"cost_cents": 0,
|
|
||||||
}
|
|
||||||
prose = data.get("choices", [{}])[0].get("message", {}).get("content") or ""
|
|
||||||
verdict = infer_verdict_from_prose(prose)
|
|
||||||
return {
|
|
||||||
"slug": slug, "display": display, "is_primary": is_primary,
|
|
||||||
"provider_type": "neurometric_prose",
|
|
||||||
"review": {"verdict": verdict, "prose": prose},
|
|
||||||
"prompt_tokens": 0, "completion_tokens": 0,
|
|
||||||
"cost_cents": 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
def call_model(slug, display, in_rate, out_rate, is_primary, provider_type="openrouter_tools"):
|
|
||||||
if provider_type == "neurometric_prose":
|
|
||||||
return call_neurometric_prose(slug, display, is_primary)
|
|
||||||
return call_openrouter_tools(slug, display, in_rate, out_rate, is_primary)
|
|
||||||
|
|
||||||
results = []
|
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=len(MODELS)) as pool:
|
|
||||||
futures = [pool.submit(call_model, *m) for m in MODELS]
|
|
||||||
for f in concurrent.futures.as_completed(futures):
|
|
||||||
results.append(f.result())
|
|
||||||
|
|
||||||
# Order: primary first, then alphabetical for stable comparison
|
|
||||||
results.sort(key=lambda r: (not r.get("is_primary"), r["display"]))
|
|
||||||
|
|
||||||
# Build combined comment
|
|
||||||
primary = next((r for r in results if r.get("is_primary") and "review" in r), None)
|
|
||||||
heading_verdict = primary["review"]["verdict"] if primary else "MIXED"
|
|
||||||
|
|
||||||
lines = [f"## CTO Review — {heading_verdict}", ""]
|
|
||||||
lines.append(f"_A/B harness active: {len(results)} models reviewing in parallel. Primary verdict drives heading; others are advisory._")
|
|
||||||
lines.append("")
|
|
||||||
|
|
||||||
total_cents = 0.0
|
|
||||||
for r in results:
|
|
||||||
lines.append(f"---")
|
|
||||||
primary_tag = " (primary)" if r.get("is_primary") else ""
|
|
||||||
lines.append(f"### {r['display']}{primary_tag}")
|
|
||||||
if "error" in r:
|
|
||||||
lines.append("")
|
|
||||||
lines.append(f"⚠️ Model failed: `{r['error']}`")
|
|
||||||
lines.append("")
|
|
||||||
continue
|
|
||||||
rev = r["review"]
|
|
||||||
lines.append("")
|
lines.append("")
|
||||||
if r.get("provider_type") == "neurometric_prose":
|
lines.append(f"_reviewer: {MODEL_DISPLAY}_")
|
||||||
lines.append(f"**Verdict:** {rev['verdict']} _(heuristic, inferred from prose)_")
|
else:
|
||||||
lines.append("")
|
heading_verdict = review.get("verdict", "COMMENT")
|
||||||
# Cap at 6KB to keep PR comments readable; 4B model output is rarely over this
|
lines = [f"## CTO Review — {heading_verdict}", ""]
|
||||||
prose = rev.get("prose", "")
|
lines.append(f"**Verdict:** {heading_verdict}")
|
||||||
if len(prose) > 6000:
|
|
||||||
prose = prose[:6000] + "\n\n_…output truncated for comment length…_"
|
|
||||||
lines.append(prose)
|
|
||||||
lines.append("")
|
|
||||||
lines.append("_free tier; per-call token usage not tracked_")
|
|
||||||
lines.append("")
|
|
||||||
continue
|
|
||||||
lines.append(f"**Verdict:** {rev.get('verdict', 'COMMENT')}")
|
|
||||||
lines.append("")
|
lines.append("")
|
||||||
lines.append(rev.get("summary") or "_(model returned no summary)_")
|
lines.append(review.get("summary") or "_(model returned no summary)_")
|
||||||
lines.append("")
|
lines.append("")
|
||||||
if rev.get("concerns"):
|
if review.get("concerns"):
|
||||||
lines.append("**Concerns:**")
|
lines.append("**Concerns:**")
|
||||||
for c in rev["concerns"]:
|
for c in review["concerns"]:
|
||||||
sev = c["severity"].upper()
|
sev = c.get("severity", "UNKNOWN").upper()
|
||||||
f = f"`{c['file']}`" if c.get("file") else ""
|
f = f"`{c['file']}`" if c.get("file") else ""
|
||||||
lines.append(f"- **{sev}** {f} — {c['issue']}")
|
lines.append(f"- **{sev}** {f} — {c['issue']}")
|
||||||
lines.append("")
|
lines.append("")
|
||||||
if rev.get("positives"):
|
if review.get("positives"):
|
||||||
lines.append("**Positives:** " + "; ".join(rev["positives"]))
|
lines.append("**Positives:** " + "; ".join(review["positives"]))
|
||||||
lines.append("")
|
lines.append("")
|
||||||
lines.append(f"_tokens in/out: {r['prompt_tokens']}/{r['completion_tokens']} · cost: ${r['cost_cents']/100:.4f}_")
|
lines.append(f"_tokens in/out: {ptok}/{ctok} · cost: ${cost_cents/100:.4f}_")
|
||||||
total_cents += r["cost_cents"]
|
|
||||||
lines.append("")
|
lines.append("")
|
||||||
|
|
||||||
lines.append("---")
|
lines.append("---")
|
||||||
lines.append(f"_Total review cost: **${total_cents/100:.4f}**. A/B roster configured in `.github/workflows/cto-review.yml`._")
|
lines.append(f"_Total review cost: **${cost_cents/100:.4f}**. Reviewer: {MODEL_DISPLAY}. Roster configured in `.github/workflows/cto-review.yml`._")
|
||||||
|
|
||||||
with open("/tmp/review-body.md", "w") as f:
|
with open("/tmp/review-body.md", "w") as f:
|
||||||
f.write("\n".join(lines))
|
f.write("\n".join(lines))
|
||||||
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
|
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
|
||||||
f.write(f"added_cents={int(round(total_cents))}\n")
|
f.write(f"added_cents={int(round(cost_cents))}\n")
|
||||||
f.write(f"skipped=0\n")
|
f.write(f"skipped=0\n")
|
||||||
f.write(f"primary_verdict={heading_verdict}\n")
|
f.write(f"primary_verdict={heading_verdict}\n")
|
||||||
PY
|
PY
|
||||||
|
|
||||||
- name: Post PR review (formal APPROVE / REQUEST_CHANGES / COMMENT)
|
- name: Post PR review (formal APPROVE / REQUEST_CHANGES / COMMENT)
|
||||||
# Uses primary model's verdict as the formal event. Falls back to COMMENT
|
# Uses Haiku's verdict as the formal event. Falls back to COMMENT
|
||||||
# if the primary model failed or returned something unexpected.
|
# if the model failed or returned something unexpected.
|
||||||
if: steps.budget.outputs.skip != 'true' && steps.review.outputs.skipped != '1'
|
if: steps.budget.outputs.skip != 'true' && steps.review.outputs.skipped != '1'
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
env:
|
env:
|
||||||
|
|||||||
100
.github/workflows/deploy.yml
vendored
100
.github/workflows/deploy.yml
vendored
@@ -4,8 +4,12 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
|
||||||
|
# contents: write required so the ci.yml caller can pass write permission
|
||||||
|
# through to the phpcbf auto-commit step in the reusable workflow.
|
||||||
|
# (phpcbf commit only fires on pull_request events, but GH enforces caller
|
||||||
|
# permissions at token-grant time, not at step-execution time.)
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: write
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: deploy-peptide-news-plugin
|
group: deploy-peptide-news-plugin
|
||||||
@@ -16,92 +20,10 @@ jobs:
|
|||||||
name: Pre-deploy tests
|
name: Pre-deploy tests
|
||||||
uses: ./.github/workflows/ci.yml
|
uses: ./.github/workflows/ci.yml
|
||||||
|
|
||||||
deploy-staging:
|
deploy:
|
||||||
name: Deploy to Staging
|
name: Deploy (shared pipeline)
|
||||||
needs: test
|
needs: test
|
||||||
runs-on: ubuntu-latest
|
uses: peptiderepo/peptide-e2e/.github/workflows/deploy-app.yml@main
|
||||||
environment: staging
|
with:
|
||||||
steps:
|
target_path: wp-content/plugins/peptide-news-plugin
|
||||||
- uses: actions/checkout@v4
|
secrets: inherit
|
||||||
with:
|
|
||||||
ref: main
|
|
||||||
- name: Setup SSH key
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
|
|
||||||
chmod 600 ~/.ssh/deploy_key
|
|
||||||
ssh-keyscan -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts 2>/dev/null || true
|
|
||||||
- name: Deploy via rsync → staging
|
|
||||||
run: |
|
|
||||||
rsync -avz --delete \
|
|
||||||
--exclude='.git' --exclude='.github' \
|
|
||||||
--exclude='tests' --exclude='phpunit.xml.dist' \
|
|
||||||
--exclude='composer.json' --exclude='composer.lock' \
|
|
||||||
--exclude='vendor' --exclude='.phpcs.xml.dist' \
|
|
||||||
--exclude='ARCHITECTURE.md' --exclude='CONVENTIONS.md' --exclude='CHANGELOG.md' \
|
|
||||||
-e "ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=accept-new" \
|
|
||||||
./ ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/domains/peptiderepo.com/public_html/staging/wp-content/plugins/peptide-news-plugin/
|
|
||||||
- name: Staging health check
|
|
||||||
run: |
|
|
||||||
sleep 5
|
|
||||||
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://staging.peptiderepo.com/ || echo "000")
|
|
||||||
echo "Staging responded: HTTP $STATUS"
|
|
||||||
- name: Cleanup
|
|
||||||
if: always()
|
|
||||||
run: rm -f ~/.ssh/deploy_key
|
|
||||||
|
|
||||||
smoke:
|
|
||||||
name: Smoke tests (staging)
|
|
||||||
needs: deploy-staging
|
|
||||||
uses: peptiderepo/peptide-e2e/.github/workflows/smoke.yml@main
|
|
||||||
secrets:
|
|
||||||
STAGING_WP_ADMIN_USER: ${{ secrets.STAGING_WP_ADMIN_USER }}
|
|
||||||
STAGING_WP_ADMIN_PASSWORD: ${{ secrets.STAGING_WP_ADMIN_PASSWORD }}
|
|
||||||
|
|
||||||
deploy-production:
|
|
||||||
name: Deploy to Production
|
|
||||||
needs: [test, deploy-staging, smoke]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
environment: production
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Setup SSH key
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
|
|
||||||
chmod 600 ~/.ssh/deploy_key
|
|
||||||
ssh-keyscan -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts 2>/dev/null || true
|
|
||||||
- name: Deploy via rsync → production
|
|
||||||
run: |
|
|
||||||
rsync -avz --delete \
|
|
||||||
--exclude='.git' --exclude='.github' \
|
|
||||||
--exclude='tests' --exclude='phpunit.xml.dist' \
|
|
||||||
--exclude='composer.json' --exclude='composer.lock' \
|
|
||||||
--exclude='vendor' --exclude='.phpcs.xml.dist' \
|
|
||||||
--exclude='ARCHITECTURE.md' --exclude='CONVENTIONS.md' --exclude='CHANGELOG.md' \
|
|
||||||
-e "ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }}" \
|
|
||||||
./ ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/domains/peptiderepo.com/public_html/wp-content/plugins/peptide-news-plugin/
|
|
||||||
- name: Purge LiteSpeed Cache
|
|
||||||
run: |
|
|
||||||
ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }} \
|
|
||||||
${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} \
|
|
||||||
"cd ~/domains/peptiderepo.com/public_html && \
|
|
||||||
wp litespeed-purge all 2>/dev/null || \
|
|
||||||
(find wp-content/litespeed/ -type f -delete 2>/dev/null; touch .lscache_purge 2>/dev/null) || true"
|
|
||||||
- name: Production health check
|
|
||||||
run: |
|
|
||||||
sleep 5
|
|
||||||
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://peptiderepo.com)
|
|
||||||
if [ "$STATUS" != "200" ] && [ "$STATUS" != "403" ]; then
|
|
||||||
echo "ERROR: Site returned unexpected HTTP $STATUS after deploy"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "Production healthy (HTTP $STATUS)"
|
|
||||||
- name: Cleanup
|
|
||||||
if: always()
|
|
||||||
run: rm -f ~/.ssh/deploy_key
|
|
||||||
- name: Deploy summary
|
|
||||||
run: |
|
|
||||||
echo "## Deployment Complete" >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo "- **Commit:** \`${GITHUB_SHA::7}\`" >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo "- **Deployed to:** peptiderepo.com" >> $GITHUB_STEP_SUMMARY
|
|
||||||
|
|||||||
58
.github/workflows/security-audit.yml
vendored
Normal file
58
.github/workflows/security-audit.yml
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
##
|
||||||
|
# Security audit — peptide-news-plugin
|
||||||
|
#
|
||||||
|
# Standalone workflow kept separate from the estate CI caller so it can evolve
|
||||||
|
# independently and run on every PR without being bundled into the reusable pipeline.
|
||||||
|
# Checks for: unescaped SQL, eval(), base64_decode(), file_get_contents with user input.
|
||||||
|
##
|
||||||
|
name: Security Audit
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request: {}
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security-audit:
|
||||||
|
name: Security Audit
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Check for common PHP security issues
|
||||||
|
run: |
|
||||||
|
echo ":: Checking for direct SQL queries without prepare..."
|
||||||
|
# Exclude uninstall.php (DROP TABLE is standard WP pattern), activator (table DDL),
|
||||||
|
# and logger (TRUNCATE) — these use $wpdb->prefix which is safe internal state.
|
||||||
|
if grep -r "query\s*(\s*['\"].*\$" --include="*.php" --exclude-dir=vendor . 2>/dev/null \
|
||||||
|
| grep -v "\$wpdb->prepare" \
|
||||||
|
| grep -v "uninstall\.php" \
|
||||||
|
| grep -v "class-peptide-news-activator\.php" \
|
||||||
|
| grep -v "class-peptide-news-logger\.php" \
|
||||||
|
| grep -v "DROP TABLE" \
|
||||||
|
| grep -v "TRUNCATE" \
|
||||||
|
&& [ ${PIPESTATUS[0]} -eq 0 ]; then
|
||||||
|
echo "WARNING: Found potential unescaped SQL queries. Use wpdb->prepare() for all dynamic SQL."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ":: Checking for eval() usage..."
|
||||||
|
if grep -r "eval\s*(" --include="*.php" --exclude-dir=vendor . 2>/dev/null; then
|
||||||
|
echo "ERROR: eval() found. This is a critical security risk."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ":: Checking for base64_decode without validation..."
|
||||||
|
if grep -r "base64_decode\s*(" --include="*.php" --exclude-dir=vendor . 2>/dev/null; then
|
||||||
|
echo "WARNING: Found base64_decode(). Ensure the input is properly validated."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ":: Checking for file_get_contents with user input..."
|
||||||
|
if grep -r "file_get_contents\s*(\s*\$" --include="*.php" --exclude-dir=vendor . 2>/dev/null; then
|
||||||
|
echo "WARNING: Found file_get_contents with variable. Ensure input is validated and restricted."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "All security checks passed."
|
||||||
@@ -73,9 +73,13 @@
|
|||||||
<type>warning</type>
|
<type>warning</type>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<!-- PHP Compatibility — target PHP 7.4+ -->
|
<!--
|
||||||
<config name="testVersion" value="7.4-"/>
|
PHPCompatibilityWP removed: the estate CI reusable workflow installs
|
||||||
<rule ref="PHPCompatibilityWP"/>
|
only wp-coding-standards/wpcs + phpcsutils + phpcsextra via global
|
||||||
|
composer require. phpcompatibility/phpcompatibility-wp is not available
|
||||||
|
in that environment. PHP version targeting is covered by the lint-php
|
||||||
|
matrix job (8.1 / 8.2 / 8.3 syntax check).
|
||||||
|
-->
|
||||||
|
|
||||||
<!-- Allow long lines in SQL queries up to 200 chars -->
|
<!-- Allow long lines in SQL queries up to 200 chars -->
|
||||||
<rule ref="Generic.Files.LineLength">
|
<rule ref="Generic.Files.LineLength">
|
||||||
|
|||||||
30
CHANGELOG.md
Normal file
30
CHANGELOG.md
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to Peptide News Plugin are documented here.
|
||||||
|
Format: [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
Versioning: [Semantic Versioning](https://semver.org/).
|
||||||
|
|
||||||
|
## [2.5.0] — 2026-06-16
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- **CI standardization (estate wave 2):** Replace per-repo CI jobs in
|
||||||
|
`ci.yml` with a thin caller of `peptiderepo/peptide-e2e/.github/workflows/ci.yml@main`
|
||||||
|
(`tests: stubs`, `has_js: true`). Adds `workflow_call` trigger so `deploy.yml`
|
||||||
|
gate remains valid.
|
||||||
|
- Extract `security-audit` job from `ci.yml` into standalone
|
||||||
|
`.github/workflows/security-audit.yml` (kept as-is, unique to this repo).
|
||||||
|
- `deploy.yml`: elevate permissions to `contents: write` so the nested
|
||||||
|
phpcbf commit-back step in the reusable workflow receives the correct token scope.
|
||||||
|
- `composer.json`: pin `test` script to `vendor/bin/phpunit --configuration phpunit.xml.dist`
|
||||||
|
for explicit path resolution in CI; pin `lint` / `lint:fix` to `vendor/bin/`.
|
||||||
|
- `phpunit.xml.dist`: add XSD reference for PHPUnit 9.6; drop deprecated
|
||||||
|
`convertErrorsToExceptions`, `convertNoticesToExceptions`, `convertWarningsToExceptions`
|
||||||
|
attributes.
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
- `rollback.yml` and `cto-review.yml` and `main-push-audit.yml` unchanged — unique / estate-separate.
|
||||||
|
- No functional code changes in this commit.
|
||||||
|
|
||||||
|
## Prior history
|
||||||
|
|
||||||
|
Versions prior to 2.5.0 were not tracked in a CHANGELOG. See git log for details.
|
||||||
@@ -21,9 +21,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "phpunit",
|
"test": "vendor/bin/phpunit --configuration phpunit.xml.dist",
|
||||||
"lint": "phpcs",
|
"lint": "vendor/bin/phpcs",
|
||||||
"lint:fix": "phpcbf",
|
"lint:fix": "vendor/bin/phpcbf",
|
||||||
"check": [
|
"check": [
|
||||||
"@lint",
|
"@lint",
|
||||||
"@test"
|
"@test"
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class Peptide_News_Content_Filter_Rules {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( false !== strpos( $body_text, $keyword ) ) {
|
if ( false !== strpos( $body_text, $keyword ) ) {
|
||||||
$body_matches++;
|
++$body_matches;
|
||||||
$matched_keys[] = $keyword;
|
$matched_keys[] = $keyword;
|
||||||
$score += 15;
|
$score += 15;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class Peptide_News_Content_Filter {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ( 'promotional' === $result['verdict'] ) {
|
if ( 'promotional' === $result['verdict'] ) {
|
||||||
$removed++;
|
++$removed;
|
||||||
self::log( sprintf( 'Blocked (rule: %s, score: %d): %s', $result['rule'], $result['score'], $article['title'] ) );
|
self::log( sprintf( 'Blocked (rule: %s, score: %d): %s', $result['rule'], $result['score'], $article['title'] ) );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -87,10 +87,10 @@ class Peptide_News_Content_Filter {
|
|||||||
// Borderline articles go to LLM for a second opinion.
|
// Borderline articles go to LLM for a second opinion.
|
||||||
if ( 'borderline' === $result['verdict'] && self::is_llm_filter_enabled() ) {
|
if ( 'borderline' === $result['verdict'] && self::is_llm_filter_enabled() ) {
|
||||||
$llm_verdict = self::classify_with_llm( $article );
|
$llm_verdict = self::classify_with_llm( $article );
|
||||||
$llm_checked++;
|
++$llm_checked;
|
||||||
|
|
||||||
if ( 'promotional' === $llm_verdict ) {
|
if ( 'promotional' === $llm_verdict ) {
|
||||||
$removed++;
|
++$removed;
|
||||||
self::log( sprintf( 'Blocked (LLM confirmed borderline): %s', $article['title'] ) );
|
self::log( sprintf( 'Blocked (LLM confirmed borderline): %s', $article['title'] ) );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class Peptide_News_Fetcher {
|
|||||||
$stored = 0;
|
$stored = 0;
|
||||||
foreach ( $articles as $article ) {
|
foreach ( $articles as $article ) {
|
||||||
if ( $this->store_article( $article ) ) {
|
if ( $this->store_article( $article ) ) {
|
||||||
$stored++;
|
++$stored;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ class Peptide_News_LLM_Client {
|
|||||||
$retry_after = wp_remote_retrieve_header( $response, 'retry-after' );
|
$retry_after = wp_remote_retrieve_header( $response, 'retry-after' );
|
||||||
$wait = $retry_after ? min( (int) $retry_after, 30 ) : $backoff;
|
$wait = $retry_after ? min( (int) $retry_after, 30 ) : $backoff;
|
||||||
sleep( $wait );
|
sleep( $wait );
|
||||||
$retries++;
|
++$retries;
|
||||||
$backoff *= 2;
|
$backoff *= 2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ class Peptide_News_LLM {
|
|||||||
$result = self::process_article( $article );
|
$result = self::process_article( $article );
|
||||||
|
|
||||||
if ( ! empty( $result['success'] ) ) {
|
if ( ! empty( $result['success'] ) ) {
|
||||||
$processed++;
|
++$processed;
|
||||||
}
|
}
|
||||||
if ( ! empty( $result['errors'] ) ) {
|
if ( ! empty( $result['errors'] ) ) {
|
||||||
$last_errors = $result['errors'];
|
$last_errors = $result['errors'];
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ class Peptide_News_Rest_API {
|
|||||||
if ( ! preg_match( '/^\\d{4}-\\d{2}-\\d{2}$/', $value ) ) {
|
if ( ! preg_match( '/^\\d{4}-\\d{2}-\\d{2}$/', $value ) ) {
|
||||||
return new WP_Error(
|
return new WP_Error(
|
||||||
'rest_invalid_date',
|
'rest_invalid_date',
|
||||||
|
/* translators: %s: REST API parameter name */
|
||||||
sprintf( __( 'Invalid date format for %s. Expected Y-m-d.', 'peptide-news' ), $param ),
|
sprintf( __( 'Invalid date format for %s. Expected Y-m-d.', 'peptide-news' ), $param ),
|
||||||
array( 'status' => 400 )
|
array( 'status' => 400 )
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class Peptide_News_Source_Resolver {
|
|||||||
|
|
||||||
if ( ! empty( $new_source ) && $new_source !== $article->source ) {
|
if ( ! empty( $new_source ) && $new_source !== $article->source ) {
|
||||||
$wpdb->update( $table, array( 'source' => $new_source ), array( 'id' => $article->id ), array( '%s' ), array( '%d' ) );
|
$wpdb->update( $table, array( 'source' => $new_source ), array( 'id' => $article->id ), array( '%s' ), array( '%d' ) );
|
||||||
$updated++;
|
++$updated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Plugin Name: Peptide News Aggregator
|
* Plugin Name: Peptide News Aggregator
|
||||||
* Plugin URI: https://github.com/peptiderepo/peptide-news-plugin
|
* Plugin URI: https://github.com/peptiderepo/peptide-news-plugin
|
||||||
* Description: Aggregates and displays the latest peptide research news from multiple sources with click analytics and trend reporting.
|
* Description: Aggregates and displays the latest peptide research news from multiple sources with click analytics and trend reporting.
|
||||||
* Version: 2.4.1
|
* Version: 2.5.0
|
||||||
* Author: peptiderepo
|
* Author: peptiderepo
|
||||||
* Author URI: https://github.com/peptiderepo
|
* Author URI: https://github.com/peptiderepo
|
||||||
* License: GPL-2.0+
|
* License: GPL-2.0+
|
||||||
@@ -24,7 +24,7 @@ if ( ! defined( 'WPINC' ) ) {
|
|||||||
/**
|
/**
|
||||||
* Current plugin version — follows SemVer.
|
* Current plugin version — follows SemVer.
|
||||||
*/
|
*/
|
||||||
define( 'PEPTIDE_NEWS_VERSION', '2.4.0' );
|
define( 'PEPTIDE_NEWS_VERSION', '2.5.0' );
|
||||||
define( 'PEPTIDE_NEWS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
define( 'PEPTIDE_NEWS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
||||||
define( 'PEPTIDE_NEWS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
define( 'PEPTIDE_NEWS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||||
define( 'PEPTIDE_NEWS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
define( 'PEPTIDE_NEWS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<phpunit
|
<phpunit
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
|
||||||
bootstrap="tests/bootstrap.php"
|
bootstrap="tests/bootstrap.php"
|
||||||
backupGlobals="false"
|
backupGlobals="false"
|
||||||
colors="true"
|
colors="true"
|
||||||
convertErrorsToExceptions="true"
|
|
||||||
convertNoticesToExceptions="true"
|
|
||||||
convertWarningsToExceptions="true"
|
|
||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="unit">
|
<testsuite name="unit">
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
declare( strict_types=1 );
|
declare( strict_types=1 );
|
||||||
|
|
||||||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$prefix = $wpdb->prefix;
|
$prefix = $wpdb->prefix;
|
||||||
@@ -16,12 +16,12 @@ $wpdb->query( "DROP TABLE IF EXISTS {$prefix}peptide_news_articles" );
|
|||||||
|
|
||||||
// Delete all plugin options.
|
// Delete all plugin options.
|
||||||
$wpdb->query(
|
$wpdb->query(
|
||||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE 'peptide\_news\_%'"
|
"DELETE FROM {$wpdb->options} WHERE option_name LIKE 'peptide\_news\_%'"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove transient caches.
|
// Remove transient caches.
|
||||||
$wpdb->query(
|
$wpdb->query(
|
||||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_peptide\_news\_%' OR option_name LIKE '_transient_timeout_peptide\_news\_%'"
|
"DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_peptide\_news\_%' OR option_name LIKE '_transient_timeout_peptide\_news\_%'"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Clear scheduled events.
|
// Clear scheduled events.
|
||||||
|
|||||||
Reference in New Issue
Block a user