@chrono-meta/fh-gate 3.30.0 → 3.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +4 -4
- package/CLAUDE.md +1 -1
- package/README.ja.md +6 -5
- package/README.ko.md +6 -5
- package/README.md +18 -5
- package/README.zh.md +6 -5
- package/docs/REFERENCE.md +6 -5
- package/docs/USER_GUIDE.md +3 -0
- package/knowledge/shared/harness-core/dispatch_conditional_prohibition.md +50 -0
- package/knowledge/shared/harness-core/sonnet_floor_doctrine.md +7 -0
- package/knowledge/shared/learnings/subagent_invocations_log.yaml +84 -0
- package/package.json +5 -1
- package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-meta/CHANGELOG.md +32 -0
- package/plugins/fh-meta/skills/install-wizard/SKILL.md +31 -0
- package/plugins/fh-meta/skills/install-wizard/SKILL_detail.md +24 -6
- package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
- package/scripts/abstract_consult_check.py +573 -0
- package/scripts/fh_detach.py +466 -0
- package/scripts/fh_session_load.sh +17 -0
- package/scripts/mutation_probe.py +16 -0
- package/scripts/selfcheck.sh +83 -6
- package/scripts/test_abstract_consult_check_lanes.sh +201 -0
- package/scripts/test_fh_detach_lanes.sh +302 -0
- package/scripts/test_fh_run_resolver_lanes.sh +16 -0
- package/scripts/test_mutation_probe_lanes.sh +62 -20
- package/scripts/test_ollama_panel_lanes.sh +107 -11
- package/scripts/test_prepush_real_fire_lanes.sh +1 -1
- package/scripts/test_selfcheck_state_lanes.sh +73 -1
- package/templates/CLAUDE.md +16 -0
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""abstract_consult_check.py — 바깥 모델에 보낼 «가린 질문» 의 송신 전 검사 + 로컬 원장 (거주 원칙의 세 번째 길, D1).
|
|
3
|
+
|
|
4
|
+
왜 있나 (2026-10-26, 운영자 «ㅇㅇ 설치하고 설계해보자» · «d1시작하면좋은데»):
|
|
5
|
+
회사 거주 원칙은 지금 «금지» 와 «폐포가 깨끗하면 송신»(residency_closure_scan.py) 두 칸뿐이다. 비공개 맥락이 섞인
|
|
6
|
+
코드에 대해 바깥 의견이 필요할 때 제3안 = 비공개 이름을 역할 · 유형으로 바꾼 질문만 보낸다(arXiv:2610.24824).
|
|
7
|
+
설계 = tracks/_meta/design_2026-10-26_residency-verified-abstraction.md (gitignored). 이 파일은 그 §3 ② 와 ⑥ 이다.
|
|
8
|
+
|
|
9
|
+
🟥 이 스크립트는 **보내지 않는다.** 송신기는 없다 — 검사 판정과 원장만 낸다. 기본으로 켜지는 곳도 없다(호출자 0).
|
|
10
|
+
🟥 보안 경계가 아니라 **위생 린트**다(outbound_query_guard.sh 와 같은 등급). 협조적인 로컬 모델이 실수로 넣는 이름을
|
|
11
|
+
잡는다. 의도적 우회(인코딩 · 쪼개 보내기 · 여러 질문에 나눠 모으기)와 의미 유출(역할만 남아도 회사가 드러나는 조합)은
|
|
12
|
+
못 막는다 — 그래서 송신은 사람 확인을 거친다(설계 §2-2). 자동 판정 혼자로 이 표면을 못 지나간다.
|
|
13
|
+
|
|
14
|
+
🟥 막기와 강조를 가른다 (2026-10-26 D2A 결과 — tracks/_meta/residency_d2/RESULTS_D2A.md):
|
|
15
|
+
«레포에 있는 사전 밖 낱말 = 비공개» 로 전부 막았더니 공개 라이브러리 위에서도 깨끗한 가린 질문 0/12 가 통과했다(STOP).
|
|
16
|
+
그래서 rc 1 은 **확실한 비공개 신호**에만 낸다 — 운영자 리터럴 · 불투명 이름(어느 공개 어휘에도 없는 조각) · 호스트 ·
|
|
17
|
+
작성자 · 메일 · 원문 조각. 공개 낱말로만 된 레포 식별자(processPayment)는 막지 않고 **flags** 로 올린다 — 사람 확인 화면이
|
|
18
|
+
강조할 자리다. 판정(rc)은 flags 에 안 묶인다.
|
|
19
|
+
|
|
20
|
+
검사 세 층 (전부 보내기 전 · 막는 신호가 하나라도 있으면 rc 1 · 하나라도 못 재면 rc 3):
|
|
21
|
+
L1 운영자 리터럴 — scripts/outbound_query_guard.sh 를 그대로 부른다(override 층 · 카나리 · fail-closed 는 그쪽 소유).
|
|
22
|
+
🟥 OUTBOUND_QUERY_OK 는 지우고 부른다 — 그 가드의 «봤고 괜찮다» 우회가 이 검사를 대신 통과시키면 안 된다.
|
|
23
|
+
L2 레포 식별자 — `git ls-files` 의 경로와 본문, `git log` 작성자에서 뽑는다. 낱말을 사전(+기술 어휘 · 언어 예약어)과 대조해
|
|
24
|
+
ⓐ 불투명(공개 어휘에 없는 조각이 있음: zqpayGw · pg-settle-01) → 대소문자 · 구분자 · 띄어쓰기 · 낱말 12개까지 이어 붙이기,
|
|
25
|
+
질문 쪽 낱말도 camel 조각으로 쪼개 대조(ZqpayClient · «z q p a y»)
|
|
26
|
+
공개 어휘 = 사전 + 굴절형 + 기술 낱말 + **파이썬 표준 라이브러리 본문 낱말**(기본 켜짐 · 캐시) + --public-corpus
|
|
27
|
+
ⓑ 낱말 합성(processPayment) → 코드 토큰 하나로 쓰였을 때 **flags**(막지 않음). 정규형 6자 미만 합성(bE · iT)은 안 본다
|
|
28
|
+
— 레포 시험 문자열의 대소문자 섞인 짧은 낱말이 질문의 be · it 을 막았다(D2A)
|
|
29
|
+
ⓒ 작성자 이름 · 메일 → 대소문자 무시 구절 일치
|
|
30
|
+
L3 원문 조각 — 레포 본문과 연속 토큰 8개(식별자 ≥ 3)가 겹치면 걸린다.
|
|
31
|
+
|
|
32
|
+
종료 코드: 0 = 깨끗함(보낼 수 있다 — 사람 확인 뒤) · 1 = 걸림 · 3 = 미측정(계기 불완전 → 막음) · 2 = 사용법 오류.
|
|
33
|
+
|
|
34
|
+
원장 (로컬 전용 · 기본 ${XDG_STATE_HOME:-~/.local/state}/fh-abstract-consult/ledger.jsonl):
|
|
35
|
+
🟥 tracks/_meta 를 기본값으로 두지 않는다 — 그 트리는 컴패니언 스토어로 동기화된다(비공개 유래 질문이 머신을 떠난다).
|
|
36
|
+
깨끗한 질문은 본문을 남긴다(감사 대상이 «무엇을 보냈나» 다). 걸린 질문은 sha256 만 남기고, 걸린 이름은 종류 · 층 · sha256 만.
|
|
37
|
+
decide <id> sent|edited|dropped — 사람 판정. 🟥 걸림 · 미측정 판정의 id 에 sent 를 기록하려 하면 거부한다(rc 1).
|
|
38
|
+
replay <id> <rc> — 같은 실행 상태에서 답을 적용한 숨긴 테스트 rc(쓸모 기록, 안전 장치 아님 — 설계 §2-3).
|
|
39
|
+
|
|
40
|
+
명명된 잔여(D2 측정 전 — 이름으로 남긴다):
|
|
41
|
+
· 레포에 없는 비공개 이름은 L1 override 층에 운영자가 넣은 것만 본다.
|
|
42
|
+
· 4자 미만 불투명 조각(pg · db1)은 단독으로 대조하지 않는다 — 과차단이 크다. 그것이 든 더 긴 식별자 · 호스트는 잡힌다.
|
|
43
|
+
· 사전이 고유명사를 담으면(/usr/share/dict/words 는 사람 이름 일부를 담는다) 그 낱말로만 된 식별자는 «합성» 으로 분류돼
|
|
44
|
+
산문 언급을 놓친다. 작성자는 ⓒ 가 따로 본다.
|
|
45
|
+
· 과차단(사전에 없는 공개 라이브러리 이름 등)은 --allow 파일 · --public-corpus 로 푼다. 과차단 비율은 D2 에서 잰다.
|
|
46
|
+
· 이진 파일 속 이름은 못 본다(통계 binary_skipped 에 수). 호스트는 끝 조각이 HOST_SUFFIX 에 있을 때만 호스트로 친다.
|
|
47
|
+
· 작성자는 이름 낱말이 다 나올 때만 — 성씨만 쓴 언급은 못 잡는다.
|
|
48
|
+
· 표준 라이브러리 어휘에서 못 읽은 파일은 건너뛴다 — 공개 어휘가 줄어 «더 막는» 쪽으로만 틀어진다(통과 쪽 아님, codex R2 기각 근거).
|
|
49
|
+
"""
|
|
50
|
+
import argparse
|
|
51
|
+
import hashlib
|
|
52
|
+
import json
|
|
53
|
+
import keyword
|
|
54
|
+
import os
|
|
55
|
+
import re
|
|
56
|
+
import subprocess
|
|
57
|
+
import sys
|
|
58
|
+
import time
|
|
59
|
+
import uuid
|
|
60
|
+
|
|
61
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
62
|
+
VERSION = "d1b-2026-10-26"
|
|
63
|
+
|
|
64
|
+
MAX_FILES = 20000
|
|
65
|
+
MAX_FILE_BYTES = 1 << 20
|
|
66
|
+
MAX_TOTAL_BYTES = 200 << 20
|
|
67
|
+
OPAQUE_MIN = 4 # 정규화 뒤 길이 — 이보다 짧은 불투명 조각은 단독 대조 안 함(잔여)
|
|
68
|
+
PROBE_MIN = 6 # 생사 탐침에 쓸 이름의 최소 길이
|
|
69
|
+
JOIN_WORDS = 12 # 질문의 이웃 낱말을 몇 개까지 이어 붙여 대조하나(«pg settle 01 shop internal» · 글자마다 띄어 쓴 이름, D2A)
|
|
70
|
+
JOIN_CHARS = 64
|
|
71
|
+
SHINGLE = 8
|
|
72
|
+
SHINGLE_MIN_IDENT = 3
|
|
73
|
+
COMPOUND_MIN = 6 # 정규형 길이 — 이보다 짧은 합성(bE · iT · tHe)은 flags 로도 안 올린다(D2A 과차단)
|
|
74
|
+
|
|
75
|
+
# 사전에 없지만 공개 기술 어휘인 것 — 이것만으로 된 식별자는 불투명으로 안 친다. 늘리는 것은 과차단 실측(D2) 뒤.
|
|
76
|
+
TECH_WORDS = frozenset("""
|
|
77
|
+
api apis app args argv async auth bool boolean buf bytes cfg cli cmd config const css csv ctx db dict dir dirs dns
|
|
78
|
+
enum env eof err errno fd fn func get gid git gpu html http https id ids impl init int io ip json jsx kwargs len lib
|
|
79
|
+
libs log md mkdir msg npm num obj os param params pid pkg ptr py regex repo req res rpc sdk sha sql src stderr stdin
|
|
80
|
+
stdout str sync tcp tmp toml ts tsx txt uid ui uri url urls utf utf8 uuid var vars xml yaml yml
|
|
81
|
+
makefile heredoc dockerfile gitignore readme changelog shebang localhost jsonl pytest
|
|
82
|
+
javascript typescript ipv4 ipv6 html5 utf16 utf32 ascii unicode
|
|
83
|
+
""".split())
|
|
84
|
+
|
|
85
|
+
IDENT_RE = re.compile(r"[A-Za-z_][A-Za-z0-9_]*(?:[-.][A-Za-z0-9_]+)*")
|
|
86
|
+
PART_RE = re.compile(r"[A-Z]+(?![a-z])|[A-Z]?[a-z]+|\d+")
|
|
87
|
+
TOKEN_RE = re.compile(r"[A-Za-z_][A-Za-z0-9_]*|\d+|[^\sA-Za-z0-9_]")
|
|
88
|
+
WORD_RE = re.compile(r"[A-Za-z0-9]+")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class NotScanned(Exception):
|
|
92
|
+
"""계기 불완전 — 깨끗함이 아니라 미측정."""
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _sha(s):
|
|
96
|
+
return hashlib.sha256(s.encode("utf-8", "surrogatepass")).hexdigest()
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _norm(s):
|
|
100
|
+
return re.sub(r"[^a-z0-9]", "", s.lower())
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def load_vocab(dict_path, allow_path, use_stdlib=True):
|
|
104
|
+
if not dict_path or not os.path.isfile(dict_path):
|
|
105
|
+
raise NotScanned("사전 없음: %s" % dict_path)
|
|
106
|
+
words = set()
|
|
107
|
+
with open(dict_path, encoding="utf-8", errors="replace") as f:
|
|
108
|
+
for line in f:
|
|
109
|
+
w = line.strip().lower()
|
|
110
|
+
if w.isalpha():
|
|
111
|
+
words.add(w)
|
|
112
|
+
if len(words) < 3:
|
|
113
|
+
raise NotScanned("사전이 비었다(%d 낱말): %s" % (len(words), dict_path))
|
|
114
|
+
words |= TECH_WORDS
|
|
115
|
+
if use_stdlib:
|
|
116
|
+
words |= stdlib_words()
|
|
117
|
+
words |= {k.lower() for k in keyword.kwlist}
|
|
118
|
+
import builtins
|
|
119
|
+
words |= {b.lower() for b in dir(builtins) if b.isalpha()}
|
|
120
|
+
allow = set()
|
|
121
|
+
if allow_path:
|
|
122
|
+
if not os.path.isfile(allow_path):
|
|
123
|
+
raise NotScanned("허용 목록 파일 없음: %s" % allow_path)
|
|
124
|
+
with open(allow_path, encoding="utf-8") as f:
|
|
125
|
+
allow = {_norm(l) for l in f if l.strip() and not l.lstrip().startswith("#")}
|
|
126
|
+
return words, allow
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _parts(ident):
|
|
130
|
+
out = []
|
|
131
|
+
for chunk in re.split(r"[_\-.]+", ident):
|
|
132
|
+
out += [p.lower() for p in PART_RE.findall(chunk)]
|
|
133
|
+
return [p for p in out if p]
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
_SUFFIXES = (("ies", "y"), ("es", ""), ("s", ""), ("ed", ""), ("ed", "e"), ("ing", ""), ("ing", "e"),
|
|
137
|
+
("er", ""), ("er", "e"), ("ers", ""), ("ers", "e"))
|
|
138
|
+
# 파생 접미(-ly · -ally · -ness)는 안 뗀다 — 지어낸 이름(mapness)이 공개 낱말로 둔갑했다(codex R1). 굴절형만 본다
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _is_word(p, words):
|
|
142
|
+
if p.isdigit() or len(p) <= 2 or p in words:
|
|
143
|
+
return True
|
|
144
|
+
# 사전(/usr/share/dict/words)은 굴절형을 거의 안 담는다 — requests · returns 를 비공개 이름으로 치면 과차단이 폭발한다.
|
|
145
|
+
# 어간 2자(using → use)와 자음 겹침(mapped → map)은 D2A 가 막은 낱말이다
|
|
146
|
+
for suf, add in _SUFFIXES:
|
|
147
|
+
if not p.endswith(suf):
|
|
148
|
+
continue
|
|
149
|
+
stem = p[:-len(suf)]
|
|
150
|
+
if len(stem) >= 2 and (stem + add) in words:
|
|
151
|
+
return True
|
|
152
|
+
# 자음 겹침은 -ed · -ing · -er(s) 에서만(mapped · mapping · mapper) — 다른 접미에 쓰면 지어낸 mappes 가 공개 낱말이 된다(codex R2)
|
|
153
|
+
if suf in ("ed", "ing", "er", "ers") and len(stem) >= 3 and stem[-1] == stem[-2] and stem[:-1] in words:
|
|
154
|
+
return True
|
|
155
|
+
return False
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _stdlib_cache_path(std):
|
|
159
|
+
base = os.environ.get("XDG_CACHE_HOME") or os.path.join(os.path.expanduser("~"), ".cache")
|
|
160
|
+
return os.path.join(base, "fh-abstract-consult", "stdlib-%s.json" % _sha(std + sys.version)[:16])
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def stdlib_words():
|
|
164
|
+
"""파이썬 표준 라이브러리의 .py · .txt · .rst 본문 낱말(소문자 · 알파벳만, test 디렉터리 제외) — 공개 기술 어휘.
|
|
165
|
+
한 번 지어 ${XDG_CACHE_HOME:-~/.cache}/fh-abstract-consult/ 에 둔다(경로 · 버전이 같으면 다시 읽는다). 못 지으면 미측정."""
|
|
166
|
+
import sysconfig
|
|
167
|
+
std = sysconfig.get_paths().get("stdlib") or ""
|
|
168
|
+
if not os.path.isdir(std):
|
|
169
|
+
raise NotScanned("표준 라이브러리 경로 없음: %s" % std)
|
|
170
|
+
cache = _stdlib_cache_path(std)
|
|
171
|
+
try:
|
|
172
|
+
with open(cache, encoding="utf-8") as f:
|
|
173
|
+
got = json.load(f)
|
|
174
|
+
ws = got.get("words") if isinstance(got, dict) else None
|
|
175
|
+
# 출처 · 내용 해시 · 서로 다른 낱말 수를 같이 본다 — 중복으로 부풀린 목록 · 다른 인터프리터의 캐시를 믿지 않는다(codex R1)
|
|
176
|
+
if (isinstance(ws, list) and got.get("std") == std and got.get("version") == sys.version
|
|
177
|
+
and len(set(ws)) == len(ws) > 1000 and got.get("sha") == _sha("\n".join(ws))):
|
|
178
|
+
return set(ws)
|
|
179
|
+
except (OSError, ValueError, AttributeError, TypeError):
|
|
180
|
+
pass
|
|
181
|
+
out = set()
|
|
182
|
+
for root, dirs, fnames in os.walk(std):
|
|
183
|
+
dirs[:] = [d for d in dirs if d not in ("site-packages", "test", "tests", "idlelib")]
|
|
184
|
+
for fn in fnames:
|
|
185
|
+
if not fn.endswith((".py", ".txt", ".rst")):
|
|
186
|
+
continue
|
|
187
|
+
try:
|
|
188
|
+
with open(os.path.join(root, fn), encoding="utf-8", errors="replace") as f:
|
|
189
|
+
out.update(w.lower() for w in re.findall(r"[A-Za-z]{3,}", f.read()))
|
|
190
|
+
except OSError:
|
|
191
|
+
continue
|
|
192
|
+
if len(out) < 1000:
|
|
193
|
+
raise NotScanned("표준 라이브러리 어휘가 너무 적다(%d) — 미측정" % len(out))
|
|
194
|
+
try:
|
|
195
|
+
ws = sorted(out)
|
|
196
|
+
os.makedirs(os.path.dirname(cache), exist_ok=True)
|
|
197
|
+
with open(cache, "w", encoding="utf-8") as f:
|
|
198
|
+
json.dump({"std": std, "version": sys.version, "sha": _sha("\n".join(ws)), "words": ws}, f)
|
|
199
|
+
except OSError:
|
|
200
|
+
pass # 캐시는 속도용 — 못 써도 판정은 같다
|
|
201
|
+
return out
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
HOST_RE = re.compile(r"[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+")
|
|
205
|
+
# 호스트로 칠 마지막 조각. 라벨 수가 아니라 끝으로 가른다 — 두 조각 호스트(settle.internal)를 놓치지 않고(codex R1),
|
|
206
|
+
# 파일 이름(jquery.min.js · settings.json)을 호스트로 치지 않는다. 목록 밖 끝은 잔여(이름으로).
|
|
207
|
+
HOST_SUFFIX = frozenset("""
|
|
208
|
+
com net org io ai dev app cloud co biz info me kr jp cn tw hk sg us uk de fr eu
|
|
209
|
+
internal intra intranet local localdomain lan corp home private svc cluster example test invalid
|
|
210
|
+
""".split())
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def _is_host(ident):
|
|
214
|
+
return bool(HOST_RE.fullmatch(ident)) and ident.rsplit(".", 1)[-1].lower() in HOST_SUFFIX
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def classify(ident, words, allow):
|
|
218
|
+
"""'opaque' · 'compound' · None(공개 낱말 하나 — 대조 안 함)."""
|
|
219
|
+
n = _norm(ident)
|
|
220
|
+
if not n or n in allow:
|
|
221
|
+
return None
|
|
222
|
+
if _is_host(ident):
|
|
223
|
+
return "opaque" # 호스트명은 낱말이 다 사전에 있어도(pg-settle-01.shop.internal) 이름 자체가 비공개 실체다
|
|
224
|
+
parts = _parts(ident)
|
|
225
|
+
if not parts:
|
|
226
|
+
return None
|
|
227
|
+
if all(_is_word(p, words) for p in parts):
|
|
228
|
+
return "compound" if len(parts) >= 2 else None
|
|
229
|
+
if len(n) < OPAQUE_MIN:
|
|
230
|
+
return None
|
|
231
|
+
return "opaque"
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _git(repo, *args):
|
|
235
|
+
r = subprocess.run(["git", "-C", repo, *args], capture_output=True, timeout=120)
|
|
236
|
+
if r.returncode != 0:
|
|
237
|
+
raise NotScanned("git %s 실패(rc=%d): %s" % (args[0], r.returncode, r.stderr.decode("utf-8", "replace")[:200]))
|
|
238
|
+
return r.stdout
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def public_vocab(dirs):
|
|
242
|
+
"""--public-corpus 디렉터리(공개 소스 — 예: 파이썬 표준 라이브러리)의 식별자 → 공개 어휘. 여기 있는 이름은 비공개 실체가 아니다."""
|
|
243
|
+
pub = set()
|
|
244
|
+
n = 0
|
|
245
|
+
for d in dirs or ():
|
|
246
|
+
if not os.path.isdir(d):
|
|
247
|
+
raise NotScanned("공개 말뭉치 디렉터리 없음: %s" % d)
|
|
248
|
+
for root, _dirs, fnames in os.walk(d):
|
|
249
|
+
for fn in fnames:
|
|
250
|
+
p = os.path.join(root, fn)
|
|
251
|
+
try:
|
|
252
|
+
if os.path.islink(p) or os.path.getsize(p) > MAX_FILE_BYTES:
|
|
253
|
+
continue
|
|
254
|
+
with open(p, "rb") as f:
|
|
255
|
+
raw = f.read()
|
|
256
|
+
except OSError:
|
|
257
|
+
continue
|
|
258
|
+
if b"\0" in raw[:8192]:
|
|
259
|
+
continue
|
|
260
|
+
n += 1
|
|
261
|
+
if n > MAX_FILES * 5:
|
|
262
|
+
raise NotScanned("공개 말뭉치가 상한을 넘었다 — 좁혀서 다시")
|
|
263
|
+
for ident in IDENT_RE.findall(raw.decode("utf-8", "replace")):
|
|
264
|
+
for cand in {ident, *re.split(r"[-.]", ident)}:
|
|
265
|
+
pub.add(cand)
|
|
266
|
+
pub.add(_norm(cand))
|
|
267
|
+
pub.update(x for x in _parts(cand) if len(x) >= OPAQUE_MIN)
|
|
268
|
+
return pub
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def inventory(repo, words, allow, public=frozenset()):
|
|
272
|
+
"""레포 → (불투명 정규형 집합, 합성 표기 집합, 작성자 구절 집합, 원문 조각 해시 집합, 통계)."""
|
|
273
|
+
if not os.path.isdir(repo):
|
|
274
|
+
raise NotScanned("레포 아님: %s" % repo)
|
|
275
|
+
files = [f for f in _git(repo, "ls-files", "-z").decode("utf-8", "surrogateescape").split("\0") if f]
|
|
276
|
+
if not files:
|
|
277
|
+
raise NotScanned("추적 파일 0 — 목록이 비면 «이름 없음» 을 말할 수 없다")
|
|
278
|
+
if len(files) > MAX_FILES:
|
|
279
|
+
raise NotScanned("파일 %d > 상한 %d — 일부만 읽은 목록은 미측정이다" % (len(files), MAX_FILES))
|
|
280
|
+
opaque, compound, shingles = set(), set(), set()
|
|
281
|
+
total = truncated = from_head = binary = 0
|
|
282
|
+
texts = ["\n".join(files)]
|
|
283
|
+
for rel in files:
|
|
284
|
+
p = os.path.join(repo, rel)
|
|
285
|
+
try:
|
|
286
|
+
if os.path.islink(p):
|
|
287
|
+
texts.append(os.readlink(p)) # 링크가 가리키는 경로 문자열에도 이름이 있다(codex R2) — 대상 파일은 따라가지 않는다
|
|
288
|
+
continue
|
|
289
|
+
if os.path.isfile(p):
|
|
290
|
+
with open(p, "rb") as f:
|
|
291
|
+
raw = f.read(MAX_FILE_BYTES + 1)
|
|
292
|
+
else:
|
|
293
|
+
# 작업 트리에서 지운 추적 파일 — 건너뛰면 그 안의 이름이 조용히 빠진다(codex R1). 마지막 커밋본을 읽는다
|
|
294
|
+
raw = _git(repo, "cat-file", "blob", "HEAD:" + rel)[:MAX_FILE_BYTES + 1]
|
|
295
|
+
from_head += 1
|
|
296
|
+
except OSError as e:
|
|
297
|
+
raise NotScanned("읽기 실패 %s: %s" % (rel, e))
|
|
298
|
+
if len(raw) > MAX_FILE_BYTES:
|
|
299
|
+
raw = raw[:MAX_FILE_BYTES] # 큰 파일은 앞부분만 — 건너뛰지 않는다(codex R1). 잘린 수는 통계에
|
|
300
|
+
truncated += 1
|
|
301
|
+
if b"\0" in raw[:8192]:
|
|
302
|
+
binary += 1 # 이진 파일 안 이름은 못 본다 — 잔여(통계에 수로 남긴다)
|
|
303
|
+
continue
|
|
304
|
+
total += len(raw)
|
|
305
|
+
if total > MAX_TOTAL_BYTES:
|
|
306
|
+
raise NotScanned("본문 합계 상한 %d 초과 — 일부만 읽은 목록은 미측정이다" % MAX_TOTAL_BYTES)
|
|
307
|
+
texts.append(raw.decode("utf-8", "replace"))
|
|
308
|
+
for t in texts:
|
|
309
|
+
for ident in IDENT_RE.findall(t):
|
|
310
|
+
for cand in {ident, *re.split(r"[-.]", ident)}:
|
|
311
|
+
if "." in cand and not _is_host(cand):
|
|
312
|
+
continue # 점 붙은 파일 이름(config.json)은 통째로 안 담는다 — 조각은 위 split 이 따로 본다(과차단 억제)
|
|
313
|
+
k = classify(cand, words, allow)
|
|
314
|
+
if k == "opaque":
|
|
315
|
+
opaque.add(_norm(cand))
|
|
316
|
+
# 사전에 없는 조각 자체도 이름이다(ZQPAY_HOST → zqpay). 질문이 조각만 쓰면 합친 형태로는 못 잡는다
|
|
317
|
+
for part in _parts(cand):
|
|
318
|
+
if len(part) >= OPAQUE_MIN and not _is_word(part, words) and part not in allow:
|
|
319
|
+
opaque.add(part)
|
|
320
|
+
elif k == "compound":
|
|
321
|
+
compound.add(cand)
|
|
322
|
+
toks = TOKEN_RE.findall(t)
|
|
323
|
+
for i in range(len(toks) - SHINGLE + 1):
|
|
324
|
+
win = toks[i:i + SHINGLE]
|
|
325
|
+
if sum(1 for x in win if IDENT_RE.fullmatch(x)) >= SHINGLE_MIN_IDENT:
|
|
326
|
+
shingles.add(_sha("\x1f".join(win)))
|
|
327
|
+
authors = set()
|
|
328
|
+
for line in _git(repo, "log", "--format=%an%n%ae", "--all").decode("utf-8", "replace").splitlines():
|
|
329
|
+
line = line.strip()
|
|
330
|
+
if "@" in line:
|
|
331
|
+
authors.add(line.lower()) # 메일 전체
|
|
332
|
+
local = line.split("@", 1)[0]
|
|
333
|
+
if classify(local, words, allow) == "opaque":
|
|
334
|
+
opaque.add(_norm(local))
|
|
335
|
+
elif len(line.split()) >= 2:
|
|
336
|
+
authors.add(" ".join(line.lower().split())) # 여러 낱말 이름 = 구절
|
|
337
|
+
elif classify(line, words, allow) == "opaque":
|
|
338
|
+
opaque.add(_norm(line)) # 한 낱말 이름은 사전에 없을 때만(«t» · «test» 는 과차단)
|
|
339
|
+
for pub in public:
|
|
340
|
+
opaque.discard(pub)
|
|
341
|
+
compound.discard(pub)
|
|
342
|
+
if not opaque and not compound:
|
|
343
|
+
raise NotScanned("레포에서 비공개 후보 이름을 하나도 못 뽑았다 — 0 은 «없음» 이 아니라 미측정이다")
|
|
344
|
+
stats = {"files": len(files), "opaque": len(opaque), "compound": len(compound),
|
|
345
|
+
"authors": len(authors), "shingles": len(shingles),
|
|
346
|
+
"truncated": truncated, "from_head": from_head, "binary_skipped": binary}
|
|
347
|
+
return opaque, compound, authors, shingles, stats
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def _variants(n):
|
|
351
|
+
out = [n]
|
|
352
|
+
for suf in ("ies", "es", "s"):
|
|
353
|
+
if n.endswith(suf) and len(n) - len(suf) >= OPAQUE_MIN:
|
|
354
|
+
out.append(n[:-len(suf)] + ("y" if suf == "ies" else ""))
|
|
355
|
+
return out
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def scan_repo_layers(q, inv):
|
|
359
|
+
opaque, compound, authors, shingles, _ = inv
|
|
360
|
+
hits = []
|
|
361
|
+
raw_words = WORD_RE.findall(q)
|
|
362
|
+
split_words = []
|
|
363
|
+
for w in raw_words:
|
|
364
|
+
ps = PART_RE.findall(w)
|
|
365
|
+
split_words.extend(ps if len(ps) > 1 else [w]) # 붙여 쓴 이름(ZqpayClient)은 조각으로
|
|
366
|
+
seen = set()
|
|
367
|
+
# 낱말 경계에 맞춘 이어 붙이기만 본다 — 임의 부분 문자열(«parser splits» 속 rsplit)은 과차단이었다(FoD 실측).
|
|
368
|
+
# 원래 낱말열과 camel 조각 낱말열 둘 다 본다 — 조각만 보면 긴 camel 호스트가 JOIN_WORDS 를 넘어 빠진다(codex R1)
|
|
369
|
+
for words in (raw_words, split_words):
|
|
370
|
+
for i in range(len(words)):
|
|
371
|
+
j = ""
|
|
372
|
+
for k in range(i, min(i + JOIN_WORDS, len(words))):
|
|
373
|
+
j += _norm(words[k])
|
|
374
|
+
if len(j) > JOIN_CHARS:
|
|
375
|
+
break
|
|
376
|
+
for v in _variants(j): # 굴절형(zqpays)도 같은 이름이다(codex R1)
|
|
377
|
+
if v in opaque and v not in seen:
|
|
378
|
+
seen.add(v)
|
|
379
|
+
hits.append(("L2", "opaque" if k == i else "opaque-split", v))
|
|
380
|
+
# 합성 식별자는 «코드 토큰 하나» 로 쓰였을 때만 — 대소문자 · 구분자는 정규화한다(PROCESSPAYMENT · process_payment, codex R1).
|
|
381
|
+
# 띄어 쓴 산문(«process payment»)은 역할 서술이라 통과시킨다
|
|
382
|
+
cnorm = {_norm(c): c for c in compound if len(_norm(c)) >= COMPOUND_MIN}
|
|
383
|
+
for tok in set(IDENT_RE.findall(q)):
|
|
384
|
+
for cand in {tok, *re.split(r"[-.]", tok)}:
|
|
385
|
+
for v in _variants(_norm(cand)):
|
|
386
|
+
if v in cnorm:
|
|
387
|
+
hits.append(("L2f", "compound", cnorm[v])) # 막지 않는다 — flags(사람 확인 화면이 강조)
|
|
388
|
+
break
|
|
389
|
+
ql = " ".join(q.lower().split())
|
|
390
|
+
qwords = set(w.lower() for w in WORD_RE.findall(q))
|
|
391
|
+
for a in authors:
|
|
392
|
+
if re.search(r"(?<![\w@.])" + re.escape(a) + r"(?![\w@])", ql):
|
|
393
|
+
hits.append(("L2", "author", a))
|
|
394
|
+
elif "@" not in a and {w for w in WORD_RE.findall(a) if len(w) >= 2} <= qwords: # 이니셜 · 가운데 글자는 빼고(codex R2)
|
|
395
|
+
hits.append(("L2", "author", a)) # 순서를 바꿔 쓴 이름(«Parkova, Jimin», codex R1)
|
|
396
|
+
toks = TOKEN_RE.findall(q)
|
|
397
|
+
for i in range(len(toks) - SHINGLE + 1):
|
|
398
|
+
if _sha("\x1f".join(toks[i:i + SHINGLE])) in shingles:
|
|
399
|
+
hits.append(("L3", "verbatim", " ".join(toks[i:i + SHINGLE])))
|
|
400
|
+
break
|
|
401
|
+
return hits
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
def live_probe(inv):
|
|
405
|
+
"""계기 생사 — 목록에서 고른 불투명 이름 하나를 대소문자 · 구분자를 바꿔 넣은 문장이 실제로 걸리는가."""
|
|
406
|
+
opaque = inv[0]
|
|
407
|
+
long_ = sorted(o for o in opaque if len(o) >= PROBE_MIN)
|
|
408
|
+
pick = (long_ or sorted(opaque) or [None])[0]
|
|
409
|
+
if pick is None:
|
|
410
|
+
return True, None # 합성만 있는 레포 — 합성 표기 그대로 탐침
|
|
411
|
+
mid = len(pick) // 2
|
|
412
|
+
probe = "how should the %s_%s handle retries" % (pick[:mid].upper(), pick[mid:])
|
|
413
|
+
ok = any(h[0] == "L2" and h[2] == pick for h in scan_repo_layers(probe, inv))
|
|
414
|
+
return ok, pick
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def run_guard(guard, q):
|
|
418
|
+
if not guard or not os.path.isfile(guard):
|
|
419
|
+
raise NotScanned("L1 가드 없음: %s" % guard)
|
|
420
|
+
env = {k: v for k, v in os.environ.items() if k != "OUTBOUND_QUERY_OK"}
|
|
421
|
+
r = subprocess.run(["bash", guard], input=q.encode("utf-8"), capture_output=True, env=env, timeout=120)
|
|
422
|
+
if r.returncode == 0:
|
|
423
|
+
# rc 0 만으로는 «봤다» 가 아니다 — 빈 파일 · 고장 난 가드도 0 을 낸다(codex R2). 가드의 깨끗함 선언을 같이 본다
|
|
424
|
+
if b"outbound clean" not in r.stderr:
|
|
425
|
+
raise NotScanned("L1 가드가 rc 0 인데 깨끗함 선언이 없다 — 가드가 돌았는지 모른다")
|
|
426
|
+
return []
|
|
427
|
+
if r.returncode == 1:
|
|
428
|
+
return [("L1", "operator-literal", None)]
|
|
429
|
+
raise NotScanned("L1 가드가 측정값을 안 냈다(rc=%d)" % r.returncode)
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def ledger_path(arg):
|
|
433
|
+
if arg:
|
|
434
|
+
return arg
|
|
435
|
+
base = os.environ.get("XDG_STATE_HOME") or os.path.join(os.path.expanduser("~"), ".local", "state")
|
|
436
|
+
return os.path.join(base, "fh-abstract-consult", "ledger.jsonl")
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
def ledger_append(path, rec):
|
|
440
|
+
d = os.path.dirname(path)
|
|
441
|
+
if d:
|
|
442
|
+
os.makedirs(d, mode=0o700, exist_ok=True)
|
|
443
|
+
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0o600)
|
|
444
|
+
with os.fdopen(fd, "a", encoding="utf-8") as f:
|
|
445
|
+
f.write(json.dumps(rec, ensure_ascii=False) + "\n")
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
def ledger_read(path):
|
|
449
|
+
if not os.path.isfile(path):
|
|
450
|
+
return []
|
|
451
|
+
out = []
|
|
452
|
+
with open(path, encoding="utf-8") as f:
|
|
453
|
+
for line in f:
|
|
454
|
+
line = line.strip()
|
|
455
|
+
if line:
|
|
456
|
+
out.append(json.loads(line))
|
|
457
|
+
return out
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def cmd_check(a):
|
|
461
|
+
q = open(a.question_file, encoding="utf-8").read() if a.question_file else sys.stdin.read()
|
|
462
|
+
rec = {"ts": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), "id": uuid.uuid4().hex[:12], "event": "check",
|
|
463
|
+
"version": VERSION, "q_sha256": _sha(q), "repo_sha256": _sha(os.path.abspath(a.repo))} # 경로 자체가 이름일 수 있다(codex R1)
|
|
464
|
+
try:
|
|
465
|
+
if not q.strip():
|
|
466
|
+
raise NotScanned("빈 질문")
|
|
467
|
+
words, allow = load_vocab(a.dict, a.allow, use_stdlib=not a.no_stdlib_vocab)
|
|
468
|
+
inv = inventory(a.repo, words, allow, public_vocab(a.public_corpus))
|
|
469
|
+
alive, pick = live_probe(inv)
|
|
470
|
+
if not alive:
|
|
471
|
+
raise NotScanned("계기 생사 실패 — 목록의 이름을 바꿔 넣은 탐침이 안 걸렸다")
|
|
472
|
+
try:
|
|
473
|
+
head = _git(a.repo, "rev-parse", "HEAD").decode().strip()
|
|
474
|
+
except NotScanned:
|
|
475
|
+
head = None
|
|
476
|
+
found = run_guard(a.guard, q) + scan_repo_layers(q, inv)
|
|
477
|
+
hits = [h for h in found if h[0] != "L2f"]
|
|
478
|
+
flags = [h for h in found if h[0] == "L2f"]
|
|
479
|
+
rc = 1 if hits else 0
|
|
480
|
+
rec.update({"verdict": "hit" if hits else "clean", "repo_head": head, "inventory": inv[4],
|
|
481
|
+
"control": {"probe_hit": alive, "probe_sha256": _sha(pick) if pick else None}})
|
|
482
|
+
except NotScanned as e:
|
|
483
|
+
hits, flags, rc = [], [], 3
|
|
484
|
+
rec.update({"verdict": "not-scanned", "reason": str(e)})
|
|
485
|
+
rec["hits"] = [{"layer": l, "kind": k, "sha256": _sha(t) if t else None} for l, k, t in hits]
|
|
486
|
+
rec["flags"] = [{"layer": l, "kind": k, "sha256": _sha(t)} for l, k, t in flags]
|
|
487
|
+
if rc == 0:
|
|
488
|
+
rec["question"] = q # 깨끗한 것만 본문을 남긴다
|
|
489
|
+
if not a.no_ledger:
|
|
490
|
+
try:
|
|
491
|
+
ledger_append(ledger_path(a.ledger), rec)
|
|
492
|
+
except OSError as e:
|
|
493
|
+
print("🚫 원장 기록 실패: %s — 기록 없는 판정은 내지 않는다" % e, file=sys.stderr)
|
|
494
|
+
return 3
|
|
495
|
+
shown = {k: v for k, v in rec.items() if k != "question"}
|
|
496
|
+
shown["hits"] = [{"layer": l, "kind": k, "token": t} for l, k, t in hits] # 로컬 터미널에만 — 원장엔 안 쓴다
|
|
497
|
+
shown["flags"] = [{"layer": l, "kind": k, "token": t} for l, k, t in flags]
|
|
498
|
+
print(json.dumps(shown, ensure_ascii=False, indent=1))
|
|
499
|
+
if rc == 3:
|
|
500
|
+
print("🚫 NOT SCANNED — %s. 미측정은 깨끗함이 아니다." % rec.get("reason"), file=sys.stderr)
|
|
501
|
+
elif rc == 1:
|
|
502
|
+
print("🚫 걸림 %d건 — 이름을 역할 · 유형으로 바꿔 다시 검사하라." % len(hits), file=sys.stderr)
|
|
503
|
+
else:
|
|
504
|
+
print("✅ clean — 보내기 전 사람 확인이 남았다(자동 판정 혼자로는 못 지나간다)%s"
|
|
505
|
+
% (" · 강조할 레포 식별자 %d건(flags)" % len(flags) if flags else ""), file=sys.stderr)
|
|
506
|
+
return rc
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
def _find(recs, cid):
|
|
510
|
+
for r in recs:
|
|
511
|
+
if r.get("event") == "check" and r.get("id") == cid:
|
|
512
|
+
return r
|
|
513
|
+
return None
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
def cmd_decide(a):
|
|
517
|
+
path = ledger_path(a.ledger)
|
|
518
|
+
chk = _find(ledger_read(path), a.id)
|
|
519
|
+
if chk is None:
|
|
520
|
+
print("🚫 원장에 없는 id: %s" % a.id, file=sys.stderr)
|
|
521
|
+
return 1
|
|
522
|
+
if a.decision == "sent" and chk.get("verdict") != "clean":
|
|
523
|
+
print("🚫 판정이 %s 인 질문은 «보냄» 으로 기록할 수 없다 — 고쳐서 다시 검사하라" % chk.get("verdict"), file=sys.stderr)
|
|
524
|
+
return 1
|
|
525
|
+
ledger_append(path, {"ts": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), "event": "decide",
|
|
526
|
+
"id": a.id, "decision": a.decision, "by": a.by})
|
|
527
|
+
return 0
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
def cmd_replay(a):
|
|
531
|
+
path = ledger_path(a.ledger)
|
|
532
|
+
recs = ledger_read(path)
|
|
533
|
+
if _find(recs, a.id) is None:
|
|
534
|
+
print("🚫 원장에 없는 id: %s" % a.id, file=sys.stderr)
|
|
535
|
+
return 1
|
|
536
|
+
if not any(r.get("event") == "decide" and r.get("id") == a.id and r.get("decision") == "sent" for r in recs):
|
|
537
|
+
print("🚫 «보냄» 기록이 없는 질문에는 재현 결과를 붙이지 않는다", file=sys.stderr)
|
|
538
|
+
return 1
|
|
539
|
+
ledger_append(path, {"ts": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), "event": "replay",
|
|
540
|
+
"id": a.id, "test_rc": a.rc})
|
|
541
|
+
return 0
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
def main(argv=None):
|
|
545
|
+
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
|
546
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
547
|
+
c = sub.add_parser("check")
|
|
548
|
+
c.add_argument("--repo", required=True)
|
|
549
|
+
c.add_argument("--question-file")
|
|
550
|
+
c.add_argument("--dict", default="/usr/share/dict/words")
|
|
551
|
+
c.add_argument("--allow")
|
|
552
|
+
c.add_argument("--no-stdlib-vocab", action="store_true",
|
|
553
|
+
help="표준 라이브러리 본문 낱말을 공개 어휘에 넣지 않는다(레인 · 재현용)")
|
|
554
|
+
c.add_argument("--public-corpus", action="append", default=[],
|
|
555
|
+
help="공개 소스 디렉터리(반복 가능) — 여기 나오는 이름은 비공개 실체로 안 친다")
|
|
556
|
+
c.add_argument("--guard", default=os.path.join(HERE, "outbound_query_guard.sh"))
|
|
557
|
+
c.add_argument("--ledger")
|
|
558
|
+
c.add_argument("--no-ledger", action="store_true")
|
|
559
|
+
d = sub.add_parser("decide")
|
|
560
|
+
d.add_argument("--ledger")
|
|
561
|
+
d.add_argument("--id", required=True)
|
|
562
|
+
d.add_argument("--decision", required=True, choices=["sent", "edited", "dropped"])
|
|
563
|
+
d.add_argument("--by", default="operator")
|
|
564
|
+
r = sub.add_parser("replay")
|
|
565
|
+
r.add_argument("--ledger")
|
|
566
|
+
r.add_argument("--id", required=True)
|
|
567
|
+
r.add_argument("--rc", required=True, type=int)
|
|
568
|
+
a = ap.parse_args(argv)
|
|
569
|
+
return {"check": cmd_check, "decide": cmd_decide, "replay": cmd_replay}[a.cmd](a)
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
if __name__ == "__main__":
|
|
573
|
+
sys.exit(main())
|