Files
checkbot/app/chatops.py
T
patrickandClaude Sonnet 5.5 9c4f7366eb
test / pytest (3.11) (push) Waiting to run
test / pytest (3.13) (push) Waiting to run
feat: Phase 6 prompt versioning with test area, retention
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-06 02:17:01 +01:00

39 lines
1.9 KiB
Python

import time
from typing import Callable
from .agent_runs import AgentRunRepository, AgentService, configured_secrets
from .alerts import AlertRepository
from .chat import BACKEND_MATRIX, BACKEND_TELEGRAM
from .commands import (CallbackHandler, CommandDeps, CommandHandler, SettingsReader, command_audit)
from .constants import MATRIX_ALLOWLIST, TELEGRAM_ALLOWLIST
from .db import Database
from .downtime import DowntimeService, PendingStore
from .listeners import ListenerState, MatrixListener, TelegramListener
from .mutes import MuteService
from .poller import StateStore
ALLOWLIST_KEYS = {BACKEND_TELEGRAM: TELEGRAM_ALLOWLIST, BACKEND_MATRIX: MATRIX_ALLOWLIST}
class ChatOps:
def __init__(self, db: Database, store, state: StateStore, alerts: AlertRepository, mutes: MuteService,
agent_prompt: Callable[[], str | None] | None = None):
def allowlist(backend: str) -> str | None:
return store.get(ALLOWLIST_KEYS[backend]) if backend in ALLOWLIST_KEYS else None
bot_names: dict[str, str] = {}
self.agent_runs = AgentRunRepository(db)
self.agent = AgentService(store, db, self.agent_runs, state.recent_changes,
lambda: configured_secrets(store), prompt_provider=agent_prompt)
self.downtime = DowntimeService(store, db, PendingStore(time.monotonic), allowlist)
deps = CommandDeps(SettingsReader(store), self.agent, mutes=mutes, lookup=alerts, downtime=self.downtime)
audit_log = command_audit(db)
self.handler = CommandHandler(deps, allowlist, audit_log, bot_name=bot_names.get)
self.callbacks = CallbackHandler(deps, allowlist, audit_log)
listener_state = ListenerState(db)
self.telegram = TelegramListener(store, self.handler, self.callbacks, listener_state, bot_names)
self.matrix = MatrixListener(store, self.handler, listener_state)
def listener_runners(self):
return [self.telegram.run, self.matrix.run]