Some checks failed
CI / build (push) Failing after 3s
PHASE 2.3 (AUDIT-2026-Q3.md):
Task 1 — Wire-in Wave 3 (1 router mounted, 2 deferred):
- app.routers.unified_scanner_router mounted at /api/v2/scanner/* (2 routes:
POST /api/v2/scanner/token/scan, POST /api/v2/scanner/wallet/scan).
Refactored prefix from /api/v2 -> /api/v2/scanner to avoid future conflicts
with the v1 /api/v1/scanner/ stub.
- app.routers.unified_wallet_scanner DEFERRED (no router APIRouter attribute;
library module consumed by unified_scanner_router via get_wallet_scanner()).
- app.routers.admin_extensions DEFERRED (DORMANT per audit; 25 routes at
/api/v1/admin/* would shadow /api/v1/admin/alerts_webhook).
Task 2 — Archive 136 dead-code files to app/_archive/legacy_2026_07/:
- 73 routers in app/routers/ (reach graph showed zero reach into mount.py).
- 63 flat app/*.py (domain modules never imported by live code).
- 1 file RESTORED post-archive: app/routers/x402_bridge_health.py (caught by
tests/unit/test_bridge_health.py which directly imports it; reach graph
considered tests/ only as transitive reach — to be patched in next cycle).
Forced-LIVE (NOT archived per user directive):
- app/ai_pipeline_v3.py (3 importers in audit window, importers themselves DEAD)
- app/splade_bm25.py (LIVE via app.rag_service)
- app/wallet_manager_v2.py (LIVE via x402_enforcement, x402_tools, sweep_all, sweep_now)
- app/crypto_embeddings.py (NOT in audit ARCHIVE list; heavy import graph)
Verification (forward-import closure from mount.py + main.py + factory.py + lifespan.py):
- imports = 348 app.* modules
- reached = 194 files reachable from roots
- archive set = audit_dead (186) - reached - forced_live (4) - test_live (1) = 136
- Net delta: 136 files moved, 44,932 LOC reduction, 293->295 active routes (+2 from Wave 3)
pyproject.toml updates:
- setuptools.packages.find: added exclude for app._archive*
- ruff.extend-exclude: added "app/_archive/"
- mypy.exclude: added "app/_archive/"
Smoke test: pytest tests/ — 817 passed, 3 pre-existing failures unchanged
(0 new failures; 0 routes lost; all 4 forced-LIVE files still importable).
Restoration: git mv app/_archive/legacy_2026_07/<name>.py <original-path>
and add the import to app/mount.py ROUTER_MODULES.
Refs: AUDIT-2026-Q3.md /home/dev/pry/rmi-final-deadcode-2026-07-06.md
125 lines
4.1 KiB
Python
125 lines
4.1 KiB
Python
"""
|
|
RAG optimization endpoints - included via APIRouter for clean git history.
|
|
Confidence scoring, Solidity chunking, deployer reputation, cross-chain,
|
|
multi-modal, investigation narratives, graph RAG, streaming, email.
|
|
"""
|
|
|
|
import httpx
|
|
from fastapi import APIRouter, Request
|
|
|
|
router = APIRouter(prefix="/api/v1", tags=["rag-optimization"])
|
|
|
|
|
|
@router.post("/rag/confidence")
|
|
async def rag_confidence_score(request: Request, data: dict):
|
|
from app.confidence import score_confidence
|
|
|
|
return score_confidence(
|
|
data.get("results", []),
|
|
query=data.get("query", ""),
|
|
entity_matches=data.get("entity_matches", []),
|
|
)
|
|
|
|
|
|
@router.post("/rag/chunk-solidity")
|
|
async def rag_chunk_solidity(request: Request, data: dict):
|
|
source = data.get("source", "")
|
|
if not source:
|
|
return {"error": "source is required"}
|
|
from app.solidity_chunker import chunk_solidity_ast
|
|
|
|
chunks = chunk_solidity_ast(source)
|
|
return {"chunks": chunks, "count": len(chunks)}
|
|
|
|
|
|
@router.post("/scanner/deployer-risk")
|
|
async def scanner_deployer_risk(request: Request, data: dict):
|
|
from app.deployer_reputation import score_deployer_risk
|
|
|
|
return score_deployer_risk(
|
|
address=data.get("address", ""),
|
|
deployment_count=data.get("deployment_count", 0),
|
|
mixer_funded=data.get("mixer_funded", False),
|
|
source_verified=data.get("source_verified", False),
|
|
code_similarity=data.get("code_similarity", 0.0),
|
|
rapid_deploy=data.get("rapid_deploy", False),
|
|
funded_by_scammer=data.get("funded_by_scammer", False),
|
|
)
|
|
|
|
|
|
@router.post("/rag/cross-chain")
|
|
async def rag_cross_chain(request: Request, data: dict):
|
|
from app.cross_chain import resolve_cross_chain_identity
|
|
|
|
return resolve_cross_chain_identity(
|
|
address=data.get("address", ""),
|
|
chain=data.get("chain", "ethereum"),
|
|
funding_sources=data.get("funding_sources", []),
|
|
label_hints=data.get("label_hints", []),
|
|
)
|
|
|
|
|
|
@router.post("/rag/image-analysis")
|
|
async def rag_image_analysis(request: Request, data: dict):
|
|
from app.multimodal_rag import describe_image
|
|
|
|
return {
|
|
"task": data.get("task", "describe"),
|
|
"description": await describe_image(image_url=data.get("image_url", ""), task=data.get("task", "describe")),
|
|
}
|
|
|
|
|
|
@router.post("/rag/logo-check")
|
|
async def rag_logo_check(request: Request, data: dict):
|
|
url = data.get("image_url", "")
|
|
if not url:
|
|
return {"error": "image_url is required"}
|
|
r = await httpx.AsyncClient(timeout=15).get(url)
|
|
from app.multimodal_rag import compute_image_hash, get_logo_db
|
|
|
|
h = compute_image_hash(r.content)
|
|
return {**get_logo_db().check_theft(h), "computed_hash": h}
|
|
|
|
|
|
@router.post("/rag/investigate")
|
|
async def rag_investigate_endpoint(request: Request, data: dict):
|
|
q = data.get("query", "")
|
|
if not q:
|
|
return {"error": "query is required"}
|
|
from app.investigation_narratives import investigate
|
|
|
|
return await investigate(query=q, investigation_type=data.get("type", "auto"), max_hops=data.get("max_hops", 5))
|
|
|
|
|
|
@router.get("/rag/graph-communities")
|
|
async def rag_graph_communities(request: Request):
|
|
from app.graph_rag import graph_rag_search
|
|
|
|
return await graph_rag_search(query="")
|
|
|
|
|
|
@router.post("/rag/watch")
|
|
async def rag_create_watch(request: Request, data: dict):
|
|
from app.streaming_rag import create_watch
|
|
|
|
return await create_watch(token_address=data.get("token_address", ""), chain=data.get("chain", "ethereum"))
|
|
|
|
|
|
@router.get("/rag/watches")
|
|
async def rag_list_watches(request: Request):
|
|
from app.streaming_rag import list_active_watches
|
|
|
|
return await list_active_watches()
|
|
|
|
|
|
@router.get("/email/accounts")
|
|
async def email_accounts(request: Request):
|
|
return {
|
|
"accounts": [
|
|
{"id": "gmail", "email": "cryptorugmuncher@gmail.com", "type": "gmail"},
|
|
{"id": "rmi", "email": "admin@rugmunch.io", "type": "gmail"},
|
|
{"id": "rmi-local", "email": "admin@rugmunch.io", "type": "local"},
|
|
{"id": "biz", "email": "biz@rugmunch.io", "type": "local"},
|
|
],
|
|
"webmail_url": "https://webmail.rugmunch.io/",
|
|
}
|