style: apply ruff-format to entire codebase

First-time run of ruff-format via pre-commit hook normalises quote
style, trailing commas, and whitespace across 188 Python files.
No logic changes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
James Smith
2026-07-05 14:48:11 +01:00
parent 82e64104fe
commit 96172ca593
189 changed files with 19883 additions and 19552 deletions
+76 -60
View File
@@ -13,9 +13,9 @@ from typing import Any
from utils.database import get_db
logger = logging.getLogger('intercept.recording')
logger = logging.getLogger("intercept.recording")
RECORDING_ROOT = Path(__file__).parent.parent / 'instance' / 'recordings'
RECORDING_ROOT = Path(__file__).parent.parent / "instance" / "recordings"
@dataclass
@@ -35,7 +35,7 @@ class RecordingSession:
def open(self) -> None:
self.file_path.parent.mkdir(parents=True, exist_ok=True)
self._file_handle = self.file_path.open('a', encoding='utf-8')
self._file_handle = self.file_path.open("a", encoding="utf-8")
def close(self) -> None:
if self._file_handle:
@@ -46,12 +46,12 @@ class RecordingSession:
def write_event(self, record: dict) -> None:
if not self._file_handle:
self.open()
line = json.dumps(record, ensure_ascii=True) + '\n'
line = json.dumps(record, ensure_ascii=True) + "\n"
with self._lock:
self._file_handle.write(line)
self._file_handle.flush()
self.event_count += 1
self.size_bytes += len(line.encode('utf-8'))
self.size_bytes += len(line.encode("utf-8"))
class RecordingManager:
@@ -85,20 +85,23 @@ class RecordingManager:
self._active_by_id[session_id] = session
with get_db() as conn:
conn.execute('''
conn.execute(
"""
INSERT INTO recording_sessions
(id, mode, label, started_at, file_path, event_count, size_bytes, metadata)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
''', (
session.id,
session.mode,
session.label,
session.started_at.isoformat(),
str(session.file_path),
session.event_count,
session.size_bytes,
json.dumps(session.metadata or {}),
))
""",
(
session.id,
session.mode,
session.label,
session.started_at.isoformat(),
str(session.file_path),
session.event_count,
session.size_bytes,
json.dumps(session.metadata or {}),
),
)
return session
@@ -120,30 +123,33 @@ class RecordingManager:
self._active_by_id.pop(session.id, None)
with get_db() as conn:
conn.execute('''
conn.execute(
"""
UPDATE recording_sessions
SET stopped_at = ?, event_count = ?, size_bytes = ?
WHERE id = ?
''', (
session.stopped_at.isoformat(),
session.event_count,
session.size_bytes,
session.id,
))
""",
(
session.stopped_at.isoformat(),
session.event_count,
session.size_bytes,
session.id,
),
)
return session
def record_event(self, mode: str, event: dict, event_type: str | None = None) -> None:
if event_type in ('keepalive', 'ping'):
if event_type in ("keepalive", "ping"):
return
session = self._active_by_mode.get(mode)
if not session:
return
record = {
'timestamp': datetime.now(timezone.utc).isoformat(),
'mode': mode,
'event_type': event_type,
'event': event,
"timestamp": datetime.now(timezone.utc).isoformat(),
"mode": mode,
"event_type": event_type,
"event": event,
}
try:
session.write_event(record)
@@ -152,61 +158,71 @@ class RecordingManager:
def list_recordings(self, limit: int = 50) -> list[dict]:
with get_db() as conn:
cursor = conn.execute('''
cursor = conn.execute(
"""
SELECT id, mode, label, started_at, stopped_at, file_path, event_count, size_bytes, metadata
FROM recording_sessions
ORDER BY started_at DESC
LIMIT ?
''', (limit,))
""",
(limit,),
)
rows = []
for row in cursor:
rows.append({
'id': row['id'],
'mode': row['mode'],
'label': row['label'],
'started_at': row['started_at'],
'stopped_at': row['stopped_at'],
'file_path': row['file_path'],
'event_count': row['event_count'],
'size_bytes': row['size_bytes'],
'metadata': json.loads(row['metadata']) if row['metadata'] else {},
})
rows.append(
{
"id": row["id"],
"mode": row["mode"],
"label": row["label"],
"started_at": row["started_at"],
"stopped_at": row["stopped_at"],
"file_path": row["file_path"],
"event_count": row["event_count"],
"size_bytes": row["size_bytes"],
"metadata": json.loads(row["metadata"]) if row["metadata"] else {},
}
)
return rows
def get_recording(self, session_id: str) -> dict | None:
with get_db() as conn:
cursor = conn.execute('''
cursor = conn.execute(
"""
SELECT id, mode, label, started_at, stopped_at, file_path, event_count, size_bytes, metadata
FROM recording_sessions
WHERE id = ?
''', (session_id,))
""",
(session_id,),
)
row = cursor.fetchone()
if not row:
return None
return {
'id': row['id'],
'mode': row['mode'],
'label': row['label'],
'started_at': row['started_at'],
'stopped_at': row['stopped_at'],
'file_path': row['file_path'],
'event_count': row['event_count'],
'size_bytes': row['size_bytes'],
'metadata': json.loads(row['metadata']) if row['metadata'] else {},
"id": row["id"],
"mode": row["mode"],
"label": row["label"],
"started_at": row["started_at"],
"stopped_at": row["stopped_at"],
"file_path": row["file_path"],
"event_count": row["event_count"],
"size_bytes": row["size_bytes"],
"metadata": json.loads(row["metadata"]) if row["metadata"] else {},
}
def get_active(self) -> list[dict]:
with self._lock:
sessions = []
for session in self._active_by_mode.values():
sessions.append({
'id': session.id,
'mode': session.mode,
'label': session.label,
'started_at': session.started_at.isoformat(),
'event_count': session.event_count,
'size_bytes': session.size_bytes,
})
sessions.append(
{
"id": session.id,
"mode": session.mode,
"label": session.label,
"started_at": session.started_at.isoformat(),
"event_count": session.event_count,
"size_bytes": session.size_bytes,
}
)
return sessions