mirror of
https://github.com/x1xhlol/system-prompts-and-models-of-ai-tools.git
synced 2026-06-18 23:39:34 +00:00
Governance layer (14 docs): - MASTER_OPERATING_PROMPT.md — operating constitution (five planes, six tracks, policy classes) - docs/ai-operating-model.md — five-plane architecture (Decision/Execution/Trust/Data/Operating) - docs/dealix-six-tracks.md — six strategic tracks (Revenue/Intelligence/Compliance/Expansion/Operations/Trust) - docs/governance/execution-fabric.md — OpenClaw execution plane deep dive - docs/governance/trust-fabric.md — trust plane with contradiction engine + evidence packs - docs/governance/saudi-compliance-and-ai-governance.md — PDPL/ZATCA/SDAIA/NCA live controls - docs/governance/technology-radar-tier1.md — Core/Strong/Pilot/Watch/Hold classification - docs/governance/partnership-os.md — alliance lifecycle management - docs/governance/ma-os.md — M&A corporate development lifecycle - docs/governance/expansion-os.md — geographic and vertical growth - docs/governance/pmi-os.md — post-merger integration framework - docs/governance/executive-board-os.md — executive decision surfaces - docs/execution-matrix-90d-tier1.md — 90-day sprint execution plan - docs/adr/0001-tier1-execution-policy-spikes.md — 8 architectural decisions Backend (3 models, 6 services, 8 API routes): - Contradiction Engine — detect/track system conflicts - Evidence Pack System — tamper-evident audit proof with SHA256 - Saudi Compliance Matrix — live PDPL/ZATCA/SDAIA/NCA controls - Executive Room — unified executive decision surface - Connector Governance — integration health monitoring - Model Routing Dashboard — LLM provider metrics - Forecast Control Center — actual vs forecast across tracks - Approval Center — enhanced approval queue with SLA Frontend (9 components): - Executive Room, Evidence Pack Viewer, Approval Center - Connector Governance Board, Saudi Compliance Dashboard - Actual vs Forecast Dashboard, Risk Heatmap - Policy Violations Board, Partner Pipeline Board Tooling: - scripts/architecture_brief.py — preflight validation (40/40 checks pass) - Updated CLAUDE.md and AGENTS.md with governance references https://claude.ai/code/session_01W1rJthWDkasijTdXCfxVHs
142 lines
4.2 KiB
Python
142 lines
4.2 KiB
Python
"""Contradiction Engine — detects and tracks conflicts across the platform."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime, timezone
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
from sqlalchemy import select, func
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.models.contradiction import (
|
|
Contradiction,
|
|
ContradictionSeverity,
|
|
ContradictionStatus,
|
|
ContradictionType,
|
|
)
|
|
|
|
|
|
class ContradictionEngine:
|
|
"""Manages contradiction lifecycle: detect → review → resolve."""
|
|
|
|
async def register(
|
|
self,
|
|
db: AsyncSession,
|
|
*,
|
|
tenant_id: str,
|
|
source_a: str,
|
|
source_b: str,
|
|
claim_a: str,
|
|
claim_b: str,
|
|
contradiction_type: str = "factual",
|
|
severity: str = "medium",
|
|
detected_by: str = "manual",
|
|
evidence: Optional[Dict[str, Any]] = None,
|
|
) -> Contradiction:
|
|
contradiction = Contradiction(
|
|
tenant_id=tenant_id,
|
|
source_a=source_a,
|
|
source_b=source_b,
|
|
claim_a=claim_a,
|
|
claim_b=claim_b,
|
|
contradiction_type=ContradictionType(contradiction_type),
|
|
severity=ContradictionSeverity(severity),
|
|
status=ContradictionStatus.DETECTED,
|
|
detected_by=detected_by,
|
|
evidence=evidence or {},
|
|
)
|
|
db.add(contradiction)
|
|
await db.commit()
|
|
await db.refresh(contradiction)
|
|
return contradiction
|
|
|
|
async def get_active(
|
|
self, db: AsyncSession, *, tenant_id: str
|
|
) -> List[Contradiction]:
|
|
stmt = (
|
|
select(Contradiction)
|
|
.where(Contradiction.tenant_id == tenant_id)
|
|
.where(
|
|
Contradiction.status.in_([
|
|
ContradictionStatus.DETECTED,
|
|
ContradictionStatus.REVIEWING,
|
|
])
|
|
)
|
|
.order_by(Contradiction.created_at.desc())
|
|
)
|
|
result = await db.execute(stmt)
|
|
return list(result.scalars().all())
|
|
|
|
async def get_by_id(
|
|
self, db: AsyncSession, *, tenant_id: str, contradiction_id: str
|
|
) -> Optional[Contradiction]:
|
|
stmt = (
|
|
select(Contradiction)
|
|
.where(Contradiction.tenant_id == tenant_id)
|
|
.where(Contradiction.id == contradiction_id)
|
|
)
|
|
result = await db.execute(stmt)
|
|
return result.scalar_one_or_none()
|
|
|
|
async def resolve(
|
|
self,
|
|
db: AsyncSession,
|
|
*,
|
|
tenant_id: str,
|
|
contradiction_id: str,
|
|
resolution: str,
|
|
resolved_by_id: str,
|
|
status: str = "resolved",
|
|
) -> Optional[Contradiction]:
|
|
contradiction = await self.get_by_id(
|
|
db, tenant_id=tenant_id, contradiction_id=contradiction_id
|
|
)
|
|
if not contradiction:
|
|
return None
|
|
contradiction.status = ContradictionStatus(status)
|
|
contradiction.resolution = resolution
|
|
contradiction.resolved_by_id = resolved_by_id
|
|
contradiction.resolved_at = datetime.now(timezone.utc)
|
|
await db.commit()
|
|
await db.refresh(contradiction)
|
|
return contradiction
|
|
|
|
async def get_stats(
|
|
self, db: AsyncSession, *, tenant_id: str
|
|
) -> Dict[str, Any]:
|
|
base = select(func.count()).where(Contradiction.tenant_id == tenant_id)
|
|
|
|
total_result = await db.execute(base)
|
|
total = total_result.scalar() or 0
|
|
|
|
active_result = await db.execute(
|
|
base.where(
|
|
Contradiction.status.in_([
|
|
ContradictionStatus.DETECTED,
|
|
ContradictionStatus.REVIEWING,
|
|
])
|
|
)
|
|
)
|
|
active = active_result.scalar() or 0
|
|
|
|
critical_result = await db.execute(
|
|
base.where(Contradiction.severity == ContradictionSeverity.CRITICAL)
|
|
.where(
|
|
Contradiction.status.in_([
|
|
ContradictionStatus.DETECTED,
|
|
ContradictionStatus.REVIEWING,
|
|
])
|
|
)
|
|
)
|
|
critical = critical_result.scalar() or 0
|
|
|
|
return {
|
|
"total": total,
|
|
"active": active,
|
|
"resolved": total - active,
|
|
"critical_active": critical,
|
|
}
|
|
|
|
|
|
contradiction_engine = ContradictionEngine()
|