simbiot-harness/venv/lib/python3.12/site-packages/strands/injection/_xml.py
Simbiot Harness b60439152b Simbiot Harness v0.1: тактовая лестница на Strands + CQRS/ES-спина
- harness/es.py: append-only event store + проекции (образец — кооп-портал)
- harness/levels.py: уровни 1с/1м/1ч/1д, контекст ∝ масштабу
- harness/scheduler.py: уровневые потоки, идемпотентные тики, absorbed-стабы
- harness/isolated_runner.py + _llm_worker.py: LLM-тик в сабпроцессе
  (глобальный asyncio-рантайм Strands не переживает 2+ create_harness)
- cli.py: init/task/tasks/status/events + requeue (написан самим минутным агентом)
- 9router: отдельный ключ sk-simbiot, модель auto (glm-5.3 первым)
2026-09-29 15:28:50 +00:00

37 lines
1.3 KiB
Python

"""Minimal XML escaping for folding untrusted text into an XML-shaped block.
Memory entries and other injected content are frequently user-derived, so interpolating them
raw into ``<entry>…</entry>`` both breaks the block structurally (a stray ``</entry>`` or
``"``) and opens a stored-prompt-injection surface. These helpers are deliberately tiny —
enough to keep a ``<memory>`` block well-formed, not a general-purpose serializer.
"""
from __future__ import annotations
def _escape_xml_text(value: str) -> str:
"""Escape text content for placement between XML tags.
Escapes ``&`` first (so later replacements are not double-escaped), then ``<`` and ``>``.
Args:
value: The raw text to escape.
Returns:
The escaped text, safe to place in element content.
"""
return value.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
def _escape_xml_attr(value: str) -> str:
"""Escape a value for placement inside a double-quoted XML attribute.
Applies the :func:`_escape_xml_text` rules plus ``"`` and ``'``.
Args:
value: The raw attribute value to escape.
Returns:
The escaped value, safe to place inside a quoted attribute.
"""
return _escape_xml_text(value).replace('"', "&quot;").replace("'", "&#39;")