Files
patrickandClaude Sonnet 5.5 cdcf7f673a
test / pytest (3.11) (push) Canceled after 0s
test / pytest (3.13) (push) Canceled after 0s
fix: Härtung nach Referenz-Review, Phase-6d-Fallbacks vermerkt
Telegram: Plain-Text-Fallback bei Parse-Fehler, tag-sichere Kürzung auf 4096.
Matrix: bytebewusste Kürzung. Downtime: lesender Abgleich nach dem POST,
generische Fehlermeldung im Chat. Agent: Platzhalter für nicht ausgeführte
Tool-Calls, Text im letzten Schritt erzwingen, Zeitreserve, Kompaktierung,
Limit pro Antwort. CLAUDE.md: Fallbacks für Phase 6d.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-06 11:58:54 +01:00

46 lines
1.5 KiB
Python

from html import escape
from ..agent import ANSWER_MAX, validate_host, validate_service
from ..agent.tools import ToolArgumentError
from .constants import ASK_MAX, PREFIXES
from .context import CommandContext
from .models import Reply
from .render import plain
EXPLAIN_USAGE = '{p}explain <host> <service>, z.B. {p}explain web01 "CPU load"'
ASK_USAGE = "{p}ask <frage>"
def _escape_within_limit(text: str, limit: int) -> str:
escaped = escape(text)
while len(escaped) > limit and text:
text = text[:-1]
escaped = escape(text)
return escaped
def agent_reply(result) -> Reply:
text = result.text[:ANSWER_MAX]
return Reply(text, _escape_within_limit(text, ANSWER_MAX))
async def explain_command(ctx: CommandContext) -> Reply:
prefix = PREFIXES.get(ctx.message.backend, "/")
args = ctx.command.args
if len(args) < 2:
return plain("Verwendung: " + EXPLAIN_USAGE.format(p=prefix))
try:
host = validate_host(args[0])
service = validate_service(" ".join(args[1:]))
except ToolArgumentError as exc:
return plain(f"Ungültige Eingabe: {exc}")
return agent_reply(await ctx.deps.agent.explain(host, service))
async def ask_command(ctx: CommandContext) -> Reply:
prefix = PREFIXES.get(ctx.message.backend, "/")
question = ctx.command.rest.strip()[:ASK_MAX]
if not question:
return plain("Verwendung: " + ASK_USAGE.format(p=prefix))
return agent_reply(await ctx.deps.agent.ask(question))