G0~G8 성과·동맹 측정 OS 작업 일괄 고정
8월 7일까지 워킹트리에만 남아 있던 미커밋 작업을 커밋한다. 여러 사본 폴더(worktree·clone)에 흩어져 있던 중간 스냅샷을 정리하기 전에 원본을 git 이력으로 고정하는 것이 목적이다. - contracts/routes/services: measurement, outcome_trajectory, rupture_repair, deliberate_practice, calibration_transfer, supervision_research, multimodal_alliance, continuous_improvement 계열 신규 모듈과 테스트 - infra/db/init: 07~16 마이그레이션(측정 기반~calibration transfer 실행) - apps/web: 세션 리뷰 카드·관리 화면·E2E 스펙 추가 - docs/ops: G0~G8 라이브 통합·배포·롤백 증거 문서와 evidence JSON/PNG - scripts: smoke·ledger·릴리스 에이전트·NAS 프리뷰 운영 스크립트 engine.public 로그 .bak과 apps/web/test-results 산출물은 커밋에서 제외했다.
This commit is contained in:
parent
93dd8f82d7
commit
16e791e044
390 changed files with 243188 additions and 499 deletions
|
|
@ -163,6 +163,15 @@ _PII_PATTERNS: list[tuple[str, re.Pattern[str]]] = [
|
|||
("ADDR", re.compile(r"[가-힣]{2,}(?:시|도)\s?[가-힣]{1,4}(?:시|군|구)\s?[가-힣0-9]{1,}(?:동|읍|면|로|길)")),
|
||||
]
|
||||
|
||||
# Source/input text keeps the broad contextless-name heuristic above for recall.
|
||||
# Generated synthetic content has no user-originated text after source validation;
|
||||
# applying that heuristic there misclassifies ordinary words such as "서운함을".
|
||||
# Keep every high-confidence label/context/honorific pattern and all non-name PII.
|
||||
_SYNTHETIC_GENERATED_PII_PATTERNS = (
|
||||
*_PII_PATTERNS[:5],
|
||||
*_PII_PATTERNS[6:],
|
||||
)
|
||||
|
||||
# Presidio 지연 로드 캐시 (-1=미시도, None=미설치, 객체=설치됨)
|
||||
_PRESIDIO_ANALYZER: object = -1
|
||||
_PRESIDIO_ANONYMIZER: object = -1
|
||||
|
|
@ -216,7 +225,10 @@ class MaskResult:
|
|||
used_ko_recognizer: bool = False
|
||||
|
||||
|
||||
def _mask_regex_pii(text: str) -> tuple[str, list[str]]:
|
||||
def _mask_regex_pii(
|
||||
text: str,
|
||||
patterns: Iterable[tuple[str, re.Pattern[str]]] = _PII_PATTERNS,
|
||||
) -> tuple[str, list[str]]:
|
||||
masked = text
|
||||
found: list[str] = []
|
||||
|
||||
|
|
@ -235,7 +247,7 @@ def _mask_regex_pii(text: str) -> tuple[str, list[str]]:
|
|||
|
||||
return _replace
|
||||
|
||||
for label, pat in _PII_PATTERNS:
|
||||
for label, pat in patterns:
|
||||
masked = pat.sub(replace_match(label), masked)
|
||||
return masked, sorted(set(found))
|
||||
|
||||
|
|
@ -307,6 +319,50 @@ def mask_pii(text: str) -> MaskResult:
|
|||
)
|
||||
|
||||
|
||||
def mask_synthetic_generated_pii(text: str) -> MaskResult:
|
||||
"""PII gate for model-generated text from validated synthetic sources.
|
||||
|
||||
Explicit name labels, self-introductions, relationship/name contexts,
|
||||
honorifics, optional recognizers, Presidio and every non-name PII pattern stay
|
||||
enabled. Only the ambiguous contextless Korean surname heuristic is omitted.
|
||||
"""
|
||||
|
||||
if not text:
|
||||
return MaskResult(text_masked=text, entities=[], used_presidio=False)
|
||||
|
||||
analyzer, anonymizer = _try_load_presidio()
|
||||
if analyzer is not None and anonymizer is not None:
|
||||
try:
|
||||
results = analyzer.analyze(text=text, language="en")
|
||||
ents = sorted({r.entity_type for r in results})
|
||||
anonymized = anonymizer.anonymize(text=text, analyzer_results=results)
|
||||
ko_masked, ko_ents, used_ko = _mask_ko_recognizer_pii(anonymized.text)
|
||||
masked, regex_ents = _mask_regex_pii(
|
||||
ko_masked,
|
||||
_SYNTHETIC_GENERATED_PII_PATTERNS,
|
||||
)
|
||||
return MaskResult(
|
||||
text_masked=masked,
|
||||
entities=sorted(set(ents + ko_ents + regex_ents)),
|
||||
used_presidio=True,
|
||||
used_ko_recognizer=used_ko,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
ko_masked, ko_ents, used_ko = _mask_ko_recognizer_pii(text)
|
||||
masked, found = _mask_regex_pii(
|
||||
ko_masked,
|
||||
_SYNTHETIC_GENERATED_PII_PATTERNS,
|
||||
)
|
||||
return MaskResult(
|
||||
text_masked=masked,
|
||||
entities=sorted(set(ko_ents + found)),
|
||||
used_presidio=False,
|
||||
used_ko_recognizer=used_ko,
|
||||
)
|
||||
|
||||
|
||||
# ════════════════════════════════════════════════════════════════════════════
|
||||
# 2. 위기 분류 (입력 — 실제위기 vs 페르소나 연기 구분, R8)
|
||||
# ════════════════════════════════════════════════════════════════════════════
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue