Spaces:
Running
Running
SilverElixir commited on
Commit ·
3ffb23e
1
Parent(s): ef27b93
A2: lumen_security.py -> lumen/lumen_security.py + сгенерированная перебивка ссылок
Browse filesГенерация: cd <WORKTREE> && python a2_rewrite.py lumen_security lumen.lumen_security
(stdlib ast, побайтовая замена; содержимое перенесённого файла не менялось — R100)
Files changed (10)
1927 unmodified lines19281929193019311932193319341927 unmodified lines# ─────────────────── protection against provider/model leaks and prompt injection ───────────────────# Leak/injection detectors are pure functions in lumen_security.py (import only what# is used).from lumen_security import (_IDENTITY_LEAK_FALLBACK,)# (_INJECTION_PROBE_REPLY is no longer imported here: the response to provocations1927 unmodified lines19281929193019311932193319341927 unmodified lines# ─────────────────── protection against provider/model leaks and prompt injection ───────────────────# Leak/injection detectors are pure functions in lumen_security.py (import only what# is used).from lumen.lumen_security import (_IDENTITY_LEAK_FALLBACK,)# (_INJECTION_PROBE_REPLY is no longer imported here: the response to provocations
40 unmodified lines41424344454647449 unmodified lines49749849950050150250340 unmodified linesfrom lumen.lumen_errors import get_system_prompt # noqa: E402from lumen.lumen_router_config import _looks_like_heavy_query # noqa: E402from lumen_security import _LATIN_LETTERS_RE, _polish_answer # noqa: E402# Munito: the same default as bot.MUNITO_BASE_URL (the value comes from the environment/.env).MUNITO_BASE_URL = "https://api.munito.ai/inference/v1"449 unmodified linesleak, an emoji garland, a list where prose was requested, or a droppedterm). Question hints are in the style field; without them, general norms apply.Review 12.11.2026: the judge missed what is counted as a line here."""from lumen_security import _leak_spansstyle = question.get("style") or {}text = answer or ""40 unmodified lines41424344454647449 unmodified lines49749849950050150250340 unmodified linesfrom lumen.lumen_errors import get_system_prompt # noqa: E402from lumen.lumen_router_config import _looks_like_heavy_query # noqa: E402from lumen.lumen_security import _LATIN_LETTERS_RE, _polish_answer # noqa: E402# Munito: the same default as bot.MUNITO_BASE_URL (the value comes from the environment/.env).MUNITO_BASE_URL = "https://api.munito.ai/inference/v1"449 unmodified linesleak, an emoji garland, a list where prose was requested, or a droppedterm). Question hints are in the style field; without them, general norms apply.Review 12.11.2026: the judge missed what is counted as a line here."""from lumen.lumen_security import _leak_spansstyle = question.get("style") or {}text = answer or ""
254 unmodified lines255256257258259260261254 unmodified linesdef _clean_preamble(text: str) -> str:"""One status line: no provider artifacts, model or provider names, line breaks, or excess length. The reasoning field (an open model's raw chain of thought) is deliberately excluded: Claude shows a brief progress summary, not reasoning, and raw reasoning breaks the persona and exposes English in a Russian chat (measured 12.11.2026: the head's reasoning was 400+ characters per question)."""import lumen_securityfrom lumen.lumen_formatting import _strip_provider_artifactsline = " ".join((text or "").split())254 unmodified lines255256257258259260261254 unmodified linesdef _clean_preamble(text: str) -> str:"""One status line: no provider artifacts, model or provider names, line breaks, or excess length. The reasoning field (an open model's raw chain of thought) is deliberately excluded: Claude shows a brief progress summary, not reasoning, and raw reasoning breaks the persona and exposes English in a Russian chat (measured 12.11.2026: the head's reasoning was 400+ characters per question)."""from lumen import lumen_security as lumen_securityfrom lumen.lumen_formatting import _strip_provider_artifactsline = " ".join((text or "").split())
709 unmodified lines71071171271371471571696 unmodified lines813814815816817818819709 unmodified linesif _meta_refusal(answer):log.info("[draw] Description refused as text (len=%d) — keeping the user's words.", len(answer))return ""from lumen_security import _detect_identity_leakif _detect_identity_leak(answer):# A description containing a model name: do not let it out, and do not cancel generation.log.warning("[draw] Description leaked identity (len=%d) — ignored.", len(answer))96 unmodified lines# The preamble is removed before NONE/refusal: "Sure: NONE" otherwise reached the# image provider and charged the budget (review 30.11.2026).answer = _clean_draw_answer(answer)from lumen_security import _detect_identity_leakif not answer or _detect_identity_leak(answer):log.warning("[draw] Prompt translation leaked identity or became empty (len=%d) — keeping original.", len(answer))return prompt709 unmodified lines71071171271371471571696 unmodified lines813814815816817818819709 unmodified linesif _meta_refusal(answer):log.info("[draw] Description refused as text (len=%d) — keeping the user's words.", len(answer))return ""from lumen.lumen_security import _detect_identity_leakif _detect_identity_leak(answer):# A description containing a model name: do not let it out, and do not cancel generation.log.warning("[draw] Description leaked identity (len=%d) — ignored.", len(answer))96 unmodified lines# The preamble is removed before NONE/refusal: "Sure: NONE" otherwise reached the# image provider and charged the budget (review 30.11.2026).answer = _clean_draw_answer(answer)from lumen.lumen_security import _detect_identity_leakif not answer or _detect_identity_leak(answer):log.warning("[draw] Prompt translation leaked identity or became empty (len=%d) — keeping original.", len(answer))return prompt
81 unmodified lines8283848586878881 unmodified linesweb_search_max_results,web_search_timeout_sec,)from lumen_security import _looks_like_injection_probefrom lumen_status import StatusMessage, discard_status_startfrom lumen.lumen_rich import NO_LINK_PREVIEWfrom lumen import lumen_devtrace as lumen_devtrace81 unmodified lines8283848586878881 unmodified linesweb_search_max_results,web_search_timeout_sec,)from lumen.lumen_security import _looks_like_injection_probefrom lumen_status import StatusMessage, discard_status_startfrom lumen.lumen_rich import NO_LINK_PREVIEWfrom lumen import lumen_devtrace as lumen_devtrace
33 unmodified lines3435363738394033 unmodified lines_looks_like_heavy_query,)from lumen.lumen_search import _SearchRequested, search_marker_requested, strip_search_markerfrom lumen_security import _polish_answer, _detect_garbled_mix, _is_garbled_echofrom lumen.lumen_rich import NO_LINK_PREVIEW# Trim the long voice transcript from the top — otherwise, the downstream route hits model limits.33 unmodified lines3435363738394033 unmodified lines_looks_like_heavy_query,)from lumen.lumen_search import _SearchRequested, search_marker_requested, strip_search_markerfrom lumen.lumen_security import _polish_answer, _detect_garbled_mix, _is_garbled_echofrom lumen.lumen_rich import NO_LINK_PREVIEW# Trim the long voice transcript from the top — otherwise, the downstream route hits model limits.
36 unmodified lines3738394041424336 unmodified linessearch_marker_requested,strip_search_marker,)from lumen_security import (_LeakScanState,_IDENTITY_LEAK_FALLBACK,_INJECTED_PAYLOAD_ECHO_FALLBACK,36 unmodified lines3738394041424336 unmodified linessearch_marker_requested,strip_search_marker,)from lumen.lumen_security import (_LeakScanState,_IDENTITY_LEAK_FALLBACK,_INJECTED_PAYLOAD_ECHO_FALLBACK,
1436 unmodified lines1437143814391440144114421443113 unmodified lines15571558155915601561156215631436 unmodified linesdef test_identity_based_on_needs_first_person_in_the_same_sentence():import lumen_security as sectext = "I am a Gemini model. The transformer architecture is based on Google research."spans = sec._leak_spans(text)based_at = text.index("based on Google")113 unmodified linesdef test_scrub_ratio_counts_the_leading_separator():import lumen_security as secleak = "I am a Gemini model, honestly."leak = leak + " " * (51 - len(leak))text = leak + "x" * 501436 unmodified lines1437143814391440144114421443113 unmodified lines15571558155915601561156215631436 unmodified linesdef test_identity_based_on_needs_first_person_in_the_same_sentence():import lumen.lumen_security as sectext = "I am a Gemini model. The transformer architecture is based on Google research."spans = sec._leak_spans(text)based_at = text.index("based on Google")113 unmodified linesdef test_scrub_ratio_counts_the_leading_separator():import lumen.lumen_security as secleak = "I am a Gemini model, honestly."leak = leak + " " * (51 - len(leak))text = leak + "x" * 50
11 unmodified lines12131415161718659 unmodified lines67867968068168268368411 unmodified linesRun:pytest test_lumen_security.py -v"""import lumen_securityimport pytest659 unmodified lines# Measurement 12.11.2026 on a question about an emoji greeting: total# cleanup left ZERO icons despite an explicit request and glued together# sentences where an emoji held the boundary. In prose, only extra ones are removed.import lumen_securityprose = ("С днём рождения! Пусть год будет щедрым 🎉 Желаю, чтобы проблемы ""решались звонком 🚀 А планы срывались только в сторону хорошего 💪 ""Здоровья крепкого и сна сладкого 😴")11 unmodified lines12131415161718659 unmodified lines67867968068168268368411 unmodified linesRun:pytest test_lumen_security.py -v"""from lumen import lumen_security as lumen_securityimport pytest659 unmodified lines# Measurement 12.11.2026 on a question about an emoji greeting: total# cleanup left ZERO icons despite an explicit request and glued together# sentences where an emoji held the boundary. In prose, only extra ones are removed.from lumen import lumen_security as lumen_securityprose = ("С днём рождения! Пусть год будет щедрым 🎉 Желаю, чтобы проблемы ""решались звонком 🚀 А планы срывались только в сторону хорошего 💪 ""Здоровья крепкого и сна сладкого 😴")
bot.py+1-1
eval/persona_models.py+2-2
lumen/lumen_agent.py+1-1
lumen/lumen_commands.py+2-2
lumen/lumen_message_core.py+1-1
lumen/lumen_routes.py+1-1
lumen_security.py → lumen/lumen_security.pyRenamed
lumen_streaming.py+1-1
tests/test_audit_fixes_17_11.py+2-2
tests/test_lumen_security.py+2-2