compliance
Compliance Agent - Verify architectural principles and design patterns
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Compliance Agent - Verify architectural principles and design patterns
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Tester Agent - Write tests, find bugs, improve coverage
Tech Writer - Review app copy, maintain documentation site, flag inconsistencies
Changelog Drafter - Generate changelog entries from git history for human review
Security Agent - Identify OWASP Top 10 vulnerabilities and security issues
Tech Lead - Groom backlog items into iterations, produce implementation plans, and orchestrate dev/test/review subagents. Use when a backlog item is too large for a single /dev pass.
Dev Agent - Implement items from .claude/ISSUES.md (bugs first) and .claude/BACKLOG.md (features second)
| name | compliance |
| description | Compliance Agent - Verify architectural principles and design patterns |
Verify the codebase adheres to architectural principles and design patterns.
dev/compliance_check.py outputRead .claude/THOUGHT_ERRORS.md to avoid past mistakes.
Rule: "If there is a write, there is a log" - NO EXCEPTIONS
RequestingUser must call track_activity() at function startlog_event() after successful mutationuser_created, email_verified)All data access must be tenant-scoped via tenant_id parameter or UNSCOPED constant.
app/pages.py with appropriate PagePermissionrequesting_user["role"]ForbiddenErrorRequest → Router → Service → Database → PostgreSQL
app/database/All functionality achievable via RESTful API endpoints in app/routers/api/v1/.
Exceptions: Auth flows, SAML ACS/SLO, admin UI conveniences.
Documentation: API endpoint docstrings must accurately list all supported parameters and fields. When a PATCH/PUT endpoint accepts a schema, the docstring must document every field the schema exposes (not just a subset). Incomplete documentation misleads API consumers.
Rule: Every str field in Pydantic input schemas and every Form() str parameter must have max_length. Database TEXT columns must have matching constraints.
Standard limits: names/titles 255, descriptions 2000, URLs 2048, enum-like 50, subdomains 63, domains 253, IP addresses 45, passwords 255, emails 320, UUIDs/IDs 50, codes 100, timezone 50, locale 10.
max_length on every str fieldForm() str parameters must specify max_lengthField(default=None, max_length=N)CHECK (length(...) <= N) or VARCHAR(N) as backstopRule: Migrations must be safe to apply on a running instance without breaking the application.
High severity (immediate breakage):
DROP COLUMN / DROP TABLE / RENAME COLUMN / RENAME TABLE / DROP TYPEADD COLUMN ... NOT NULL without DEFAULT (fails on non-empty tables)Medium severity (lock contention or partial breakage):
ALTER COLUMN TYPE (acquires ACCESS EXCLUSIVE lock, may break queries)ALTER COLUMN SET NOT NULL (fails if existing NULLs, breaks inserts)CREATE INDEX without CONCURRENTLY (acquires write lock)DROP INDEX (may degrade query performance)Safe patterns:
ADD COLUMN (nullable or with DEFAULT)CREATE TABLE / CREATE TYPEADD CONSTRAINT (with or without NOT VALID)CREATE INDEX CONCURRENTLYALTER COLUMN SET DEFAULT / ALTER COLUMN DROP DEFAULTSuppression: Add -- migration-safety: ignore on its own line in a migration file to skip all safety checks for that file. Use this for intentional cleanup migrations where breaking changes have already been prepared by a prior code deploy.
Rule: Template href and action attributes must point to routes that exist in the application.
app/templates/**/*.html are matched against registered routes from app/routers/ and app/pages.py{{ }} segments in paths are treated as wildcards{% if %}) are skipped to avoid false positivesRule: All outbound HTTP/network calls must have explicit timeouts to prevent indefinite hangs.
httpx, requests, urllib, smtplib) must pass timeout=# outbound-timeout: ok on the call lineRule: Job handlers in app/jobs/ that call log_event() must use system_context().
log_event() without system_context() raises RuntimeError at runtimelog_event() in with system_context():Rule: Every table with ENABLE ROW LEVEL SECURITY must have a correct policy.
USING and WITH CHECK clauses (prevents write bypass)current_setting() must use the true parameter (prevents ERROR when unset)RLS_NO_WITH_CHECK_EXEMPT in the scannermake check # Full suite (lint, format, types, compliance)
python dev/compliance_check.py # Compliance only
Compliance-only options:
--check architecture # Router imports
--check activity # Activity/event logging
--check tenant # Tenant isolation
--check api-first # API coverage + endpoint docstring completeness
--check authorization # Route auth
--check input-length # Pydantic str fields without max_length
--check sql-length # SQL TEXT columns without length CHECK constraints
--check rls # RLS policies: USING + WITH CHECK, current_setting(true)
--check migration-safety # Backwards compatibility of migration files
--check template-links # Template href/action link validity
--check outbound-timeouts # Outbound HTTP calls must have timeouts
--check job-context # Job handlers must use system_context() for log_event()
--check api-auth # All API routes must require authentication
--check form-input-length # Form() str parameters must have max_length
--check template-xss # innerHTML with interpolation must use escapeHtml()
Focus on:
Request context (IP, user agent, device, session) is handled automatically by RequestContextMiddleware. You do NOT need to check for explicit request_metadata passing.
| Pattern | Violation |
|---|---|
Service with RequestingUser but no track_activity() | Activity Logging |
Mutation without log_event() | Activity Logging |
log_event() before mutation | Activity Logging |
SQL without tenant_id filter | Tenant Isolation |
| Router imports database | Architecture |
| Service operation without API endpoint | API-First |
| API docstring missing supported fields | API-First |
str field without max_length in input schema | Input Validation |
Field(default=None) without max_length | Input Validation |
TEXT/CITEXT column without CHECK (length(...) <= N) | SQL Length Validation |
RLS policy missing WITH CHECK clause | RLS Policy Consistency |
current_setting() without true parameter | RLS Policy Consistency |
DROP COLUMN / DROP TABLE in migration | Migration Safety |
RENAME COLUMN / RENAME TABLE in migration | Migration Safety |
ADD COLUMN NOT NULL without DEFAULT in migration | Migration Safety |
ALTER COLUMN TYPE in migration | Migration Safety |
CREATE INDEX without CONCURRENTLY in migration | Migration Safety |
Template href/action not matching any route | Template Links |
httpx.get/post(...) without timeout= | Outbound Timeouts |
urllib.request.urlopen(...) without timeout= | Outbound Timeouts |
smtplib.SMTP(...) without timeout= | Outbound Timeouts |
| SDK client constructor without timeout config | Outbound Timeouts |
Form() str parameter without max_length | Form Input Length |
innerHTML with ${...} without escapeHtml() | Template XSS Prevention |
| API handler without auth dependency | API Authentication |
See .claude/references/compliance-patterns.md for detailed patterns and checklists.
## [Principle Violated]: [Brief Description]
**Found in:** [File:line]
**Severity:** High
**Principle Violated:** [Activity Logging | Tenant Isolation | Authorization | Service Layer | API-First | Input Validation]
**Description:** [What's wrong]
**Evidence:** [Code snippet]
**Impact:** [Security, compliance, maintainability]
**Root Cause:** [Why this happened]
**Suggested fix:** [Specific code change]
Example:
```python
# Add after mutation at line 245:
log_event(
tenant_id=requesting_user["tenant_id"],
actor_user_id=requesting_user["id"],
event_type="user_inactivated",
artifact_type="user",
artifact_id=user_id,
)
/dev)/test)When invoked programmatically (via Agent tool), skip all interactive workflows:
Instead:
.claude/THOUGHT_ERRORS.md.claude/references/compliance-patterns.mdpython dev/compliance_check.py and report resultsReport back (for each finding):
Include compliance checker output (pass/fail). If no issues found, say so explicitly. Do not edit any files.
python dev/compliance_check.py