@chrono-meta/fh-gate 3.13.0 → 3.14.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 +5 -5
- package/knowledge/shared/harness-core/sonnet_floor_doctrine.md +71 -0
- package/knowledge/shared/learnings/subagent_invocations_log.yaml +88 -0
- package/package.json +6 -1
- package/plugins/fh-commons/.claude-plugin/plugin.json +2 -2
- package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-meta/CHANGELOG.md +50 -0
- package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-preprep/skills/preprep/fixtures/fixture_R3_negative.pptx +0 -0
- package/plugins/fh-preprep/skills/preprep/fixtures/fixture_R3_positive.pptx +0 -0
- package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
- package/scripts/checklist_unblocked_hook.sh +57 -0
- package/scripts/count_check.sh +30 -1
- package/scripts/package_coverage_check.sh +17 -0
- package/scripts/prless_delta_scan.sh +192 -0
- package/scripts/psa_extract_text.py +152 -0
- package/scripts/psa_scan_lib.sh +93 -1
- package/scripts/public_surface_scan_files.sh +26 -1
- package/scripts/selfcheck.sh +23 -0
- package/scripts/session_checklist.py +130 -21
- package/scripts/sim_isolated_run.sh +143 -1
- package/scripts/test_prless_delta_scan_lanes.sh +154 -0
- package/scripts/test_psa_singlefile_lanes.sh +266 -1
- package/scripts/test_sim_isolated_run_lanes.sh +126 -0
- package/templates/settings.SubagentStop.snippet.json +45 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# prless_delta_scan.sh — «커밋은 됐는데 착륙 경로에 안 올라간» 델타를 센다.
|
|
3
|
+
#
|
|
4
|
+
# ## 왜 있나 (2026-09-16 명명 · 2026-09-19 실측 후 배선)
|
|
5
|
+
#
|
|
6
|
+
# 마감 체인 ①-b 는 `gh pr list --author @me --state open` 로 **열린 PR** 을 훑는다.
|
|
7
|
+
# 그 스윕의 정의상 **PR 이 애초에 없는 브랜치는 구조적으로 안 보인다** — 정확한 계기일수록
|
|
8
|
+
# 자기 정의 밖을 안 본다. 실제 피해: PR 없이 26일 떠 있던 브랜치의 수리가 격리된 동안
|
|
9
|
+
# main 은 죽은 추출 패턴을 계속 지시했다(`fh_signal_2026-09-16_prless-branch-blindspot.md`).
|
|
10
|
+
#
|
|
11
|
+
# 🟥 **이 계기는 «세는 것» 이지 «치우는 것» 이 아니다.** 브랜치 삭제는 Destructive-Op 게이트의
|
|
12
|
+
# 관할이고 여기서는 아무것도 지우지 않는다. 출력은 advisory 이며 커밋/푸시를 막지 않는다.
|
|
13
|
+
#
|
|
14
|
+
# ## 🟥 판별의 핵심 — squash 잔재를 «고유 델타» 로 오분류하지 않는 것
|
|
15
|
+
#
|
|
16
|
+
# 이 레포는 squash 머지를 쓴다. 그래서 브랜치의 커밋 해시는 머지 후에도 main 에 **없다** —
|
|
17
|
+
# `git log origin/main..<branch>` 나 `git cherry` 의 per-commit 비교는 이미 착륙한 브랜치를
|
|
18
|
+
# 전부 «미착륙» 으로 보고한다(2026-09-16 실측: `predelete_check.sh` 가 23 중 19 를 REVIEW).
|
|
19
|
+
#
|
|
20
|
+
# 판별자는 **브랜치 델타 «전체» 를 한 장의 패치로 본 patch-id** 다. squash 머지는 정확히 그
|
|
21
|
+
# 한 장을 main 에 심으므로 patch-id 가 일치한다. 실측(2026-09-19, 이 레포):
|
|
22
|
+
#
|
|
23
|
+
# feat/verify-coverage-and-seeded 16 commits ahead · per-commit 15 «미착륙» · 합본 patch-id 일치 → 착륙함
|
|
24
|
+
# bench/f-arm-target 1 commit ahead · per-commit 1 «미착륙» · 합본 patch-id 불일치 → 진짜 고유 델타
|
|
25
|
+
#
|
|
26
|
+
# ⚠️ 한계, 이름으로 남긴다: squash 시 충돌 해소·리베이스가 끼면 합본 patch-id 가 달라져
|
|
27
|
+
# **착륙한 브랜치가 고유 델타로 보고된다**(과탐지 방향). 부족 탐지가 아니라 과탐지로
|
|
28
|
+
# 기울인 것은 의도다 — advisory 이므로 과탐지는 한 줄 더 읽는 비용이고, 미탐지는
|
|
29
|
+
# 이 계기가 존재하는 이유를 없앤다.
|
|
30
|
+
#
|
|
31
|
+
# ## 부재 ≠ 0
|
|
32
|
+
# `gh` 가 없거나 PR 조회가 실패하면 **rc=2 UNMEASURED** 다. 「PR 이 없다 → 전부 고발」 도,
|
|
33
|
+
# 「조회 실패 → 깨끗함」 도 아니다.
|
|
34
|
+
#
|
|
35
|
+
# 사용:
|
|
36
|
+
# bash scripts/prless_delta_scan.sh # origin/main 기준 전수
|
|
37
|
+
# bash scripts/prless_delta_scan.sh --min-age-days 3
|
|
38
|
+
# bash scripts/prless_delta_scan.sh --quiet # 발견만 출력
|
|
39
|
+
#
|
|
40
|
+
# 환경변수(레인/오프라인용):
|
|
41
|
+
# PRLESS_BASE=origin/main 기준 ref
|
|
42
|
+
# PRLESS_PR_JSON=<path> `gh pr list --json number,state,headRefName` 산출을 파일에서 읽는다
|
|
43
|
+
# PRLESS_REPO=<path> 대상 레포(기본: cwd)
|
|
44
|
+
#
|
|
45
|
+
# 종료코드: 0 발견 없음 · 1 발견 있음(advisory) · 2 UNMEASURED/계기 오류
|
|
46
|
+
set -uo pipefail
|
|
47
|
+
|
|
48
|
+
MIN_AGE_DAYS=0
|
|
49
|
+
QUIET=0
|
|
50
|
+
while [ $# -gt 0 ]; do
|
|
51
|
+
case "$1" in
|
|
52
|
+
--min-age-days) MIN_AGE_DAYS="${2:-0}"; shift 2 ;;
|
|
53
|
+
--quiet) QUIET=1; shift ;;
|
|
54
|
+
-h|--help) sed -n '2,45p' "$0"; exit 0 ;;
|
|
55
|
+
*) echo "unknown arg: $1" >&2; exit 2 ;;
|
|
56
|
+
esac
|
|
57
|
+
done
|
|
58
|
+
|
|
59
|
+
REPO="${PRLESS_REPO:-$PWD}"
|
|
60
|
+
cd "$REPO" 2>/dev/null || { echo "🟥 repo 없음: $REPO — 계기 오류" >&2; exit 2; }
|
|
61
|
+
git rev-parse --git-dir >/dev/null 2>&1 || { echo "🟥 git 레포가 아니다: $REPO — 계기 오류" >&2; exit 2; }
|
|
62
|
+
|
|
63
|
+
BASE="${PRLESS_BASE:-origin/main}"
|
|
64
|
+
git rev-parse --verify --quiet "$BASE" >/dev/null || { echo "🟥 기준 ref 없음: $BASE — UNMEASURED" >&2; exit 2; }
|
|
65
|
+
|
|
66
|
+
# ── PR 목록 (없으면 UNMEASURED, 0 아님) ───────────────────────────────────────
|
|
67
|
+
PRJSON=$(mktemp); trap 'rm -f "$PRJSON" "${PIDMAP:-}" "${REFLIST:-}" 2>/dev/null' EXIT
|
|
68
|
+
if [ -n "${PRLESS_PR_JSON:-}" ]; then
|
|
69
|
+
[ -f "$PRLESS_PR_JSON" ] || { echo "🟥 PRLESS_PR_JSON 파일 없음: $PRLESS_PR_JSON — UNMEASURED" >&2; exit 2; }
|
|
70
|
+
cat "$PRLESS_PR_JSON" > "$PRJSON"
|
|
71
|
+
else
|
|
72
|
+
command -v gh >/dev/null 2>&1 || { echo "🟥 gh 없음 — PR 커버리지 UNMEASURED (0 으로 읽지 마라)" >&2; exit 2; }
|
|
73
|
+
if ! gh pr list --state all --limit 2000 --json number,state,headRefName > "$PRJSON" 2>/dev/null; then
|
|
74
|
+
echo "🟥 gh pr list 실패 — UNMEASURED (0 으로 읽지 마라)" >&2; exit 2
|
|
75
|
+
fi
|
|
76
|
+
fi
|
|
77
|
+
# 형식 확인 — 빈 파일/깨진 JSON 을 «PR 0건» 으로 읽지 않는다
|
|
78
|
+
python3 - "$PRJSON" <<'PY' || { echo "🟥 PR 목록 파싱 실패 — UNMEASURED" >&2; exit 2; }
|
|
79
|
+
import json,sys
|
|
80
|
+
d=json.load(open(sys.argv[1]))
|
|
81
|
+
assert isinstance(d,list)
|
|
82
|
+
PY
|
|
83
|
+
|
|
84
|
+
pr_for() { # headRefName -> "#N:STATE" 또는 "NONE"
|
|
85
|
+
python3 - "$1" "$PRJSON" <<'PY'
|
|
86
|
+
import json,sys
|
|
87
|
+
name=sys.argv[1]; d=json.load(open(sys.argv[2]))
|
|
88
|
+
h=[x for x in d if x.get('headRefName')==name]
|
|
89
|
+
print("NONE" if not h else "#%s:%s" % (max(h,key=lambda x:x['number'])['number'], max(h,key=lambda x:x['number'])['state']))
|
|
90
|
+
PY
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
# ── 브랜치 수집 (base/HEAD 계열·gh-pages 제외) ────────────────────────────────
|
|
94
|
+
# 🟥 bash 3.2 (macOS 기본) — `mapfile` 이 없고, `set -u` 에서 빈 배열 "${a[@]}" 는 치명적이다.
|
|
95
|
+
# 그래서 배열이 아니라 임시 파일로 받는다. [[feedback_bash32_empty_array_under_set_u_is_fatal]]
|
|
96
|
+
REFLIST=$(mktemp)
|
|
97
|
+
# 🟥 `(HEAD detached at …)` 를 브랜치로 읽지 않는다 — detached HEAD 에서 `git branch` 가 뱉는
|
|
98
|
+
# 의사 항목이고, 그대로 두면 merge-base 가 안 잡혀 **가짜 UNRELATED_HISTORY 발견**이 된다.
|
|
99
|
+
# (이 계기의 자기 레인이 잡았다 — 2026-09-19, L12 가 앵커다.)
|
|
100
|
+
{ git branch --format='%(refname:short)'; git branch -r --format='%(refname:short)'; } 2>/dev/null \
|
|
101
|
+
| grep -v '^(' \
|
|
102
|
+
| grep -vE '^(origin|gh-pages|origin/gh-pages|origin/HEAD)$' \
|
|
103
|
+
| grep -vxF "${BASE#origin/}" | grep -vxF "$BASE" | sort -u > "$REFLIST"
|
|
104
|
+
REFCOUNT=$(grep -c . "$REFLIST" || true)
|
|
105
|
+
[ "${REFCOUNT:-0}" -gt 0 ] || { echo "ℹ️ 비교할 브랜치 없음 (base=$BASE)"; exit 0; }
|
|
106
|
+
|
|
107
|
+
# ── main 쪽 patch-id 맵을 «한 번만» 만든다 (가장 오래된 merge-base 부터) ───────
|
|
108
|
+
OLDEST=""
|
|
109
|
+
while read -r r; do
|
|
110
|
+
[ -n "$r" ] || continue
|
|
111
|
+
mb=$(git merge-base "$BASE" "$r" 2>/dev/null) || continue
|
|
112
|
+
[ -n "$mb" ] || continue
|
|
113
|
+
if [ -z "$OLDEST" ] || git merge-base --is-ancestor "$mb" "$OLDEST" 2>/dev/null; then OLDEST="$mb"; fi
|
|
114
|
+
done < "$REFLIST"
|
|
115
|
+
PIDMAP=$(mktemp)
|
|
116
|
+
if [ -n "$OLDEST" ]; then
|
|
117
|
+
git log --format=%H "$OLDEST..$BASE" 2>/dev/null | while read -r c; do
|
|
118
|
+
git show "$c" 2>/dev/null | git patch-id --stable 2>/dev/null | cut -d' ' -f1
|
|
119
|
+
done | grep -v '^$' | sort -u > "$PIDMAP"
|
|
120
|
+
fi
|
|
121
|
+
NOW=$(date +%s)
|
|
122
|
+
FINDINGS=0
|
|
123
|
+
printf '%-50s %-7s %-5s %-22s %s\n' BRANCH KIND AGE VERDICT PR
|
|
124
|
+
printf '%-50s %-7s %-5s %-22s %s\n' "$(printf '%.0s-' {1..50})" ------- ----- ---------------------- --
|
|
125
|
+
while read -r r; do
|
|
126
|
+
[ -n "$r" ] || continue
|
|
127
|
+
name="${r#origin/}"
|
|
128
|
+
kind=local; case "$r" in origin/*) kind=remote ;; esac
|
|
129
|
+
mb=$(git merge-base "$BASE" "$r" 2>/dev/null) || mb=""
|
|
130
|
+
ctime=$(git log -1 --format=%ct "$r" 2>/dev/null || echo "$NOW")
|
|
131
|
+
age=$(( (NOW - ctime) / 86400 ))
|
|
132
|
+
|
|
133
|
+
if [ -z "$mb" ]; then
|
|
134
|
+
verdict=UNRELATED_HISTORY
|
|
135
|
+
else
|
|
136
|
+
ahead=$(git rev-list --count "$BASE..$r" 2>/dev/null || echo 0)
|
|
137
|
+
if [ "$ahead" -eq 0 ]; then
|
|
138
|
+
verdict=NO_DELTA
|
|
139
|
+
elif [ "$(git rev-parse "$mb^{tree}")" = "$(git rev-parse "$r^{tree}")" ]; then
|
|
140
|
+
verdict=NO_DELTA
|
|
141
|
+
else
|
|
142
|
+
pid=$(git diff "$mb..$r" 2>/dev/null | git patch-id --stable 2>/dev/null | cut -d' ' -f1)
|
|
143
|
+
if [ -z "$pid" ]; then
|
|
144
|
+
verdict=PATCHID_UNAVAILABLE # 계기 미상 — CLEAN 으로 접지 않는다
|
|
145
|
+
elif grep -qxF "$pid" "$PIDMAP" 2>/dev/null; then
|
|
146
|
+
verdict=SQUASH_IN_BASE # 합본이 base 에 있다 → 착륙함
|
|
147
|
+
else
|
|
148
|
+
# per-commit 도 전부 base 에 있으면 리베이스/체리픽 잔재
|
|
149
|
+
uniq=0
|
|
150
|
+
while read -r c; do
|
|
151
|
+
[ -n "$c" ] || continue
|
|
152
|
+
cp=$(git show "$c" 2>/dev/null | git patch-id --stable 2>/dev/null | cut -d' ' -f1)
|
|
153
|
+
[ -n "$cp" ] && grep -qxF "$cp" "$PIDMAP" 2>/dev/null || uniq=$((uniq+1))
|
|
154
|
+
done < <(git rev-list "$BASE..$r" 2>/dev/null)
|
|
155
|
+
if [ "$uniq" -eq 0 ]; then verdict=COMMITS_IN_BASE; else verdict=UNIQUE_DELTA; fi
|
|
156
|
+
fi
|
|
157
|
+
fi
|
|
158
|
+
fi
|
|
159
|
+
|
|
160
|
+
pr=$(pr_for "$name")
|
|
161
|
+
# 고유 델타일 때만 PR 커버리지를 묻는다
|
|
162
|
+
if [ "$verdict" = "UNIQUE_DELTA" ]; then
|
|
163
|
+
case "$pr" in
|
|
164
|
+
NONE) verdict=DELTA_NO_PR ;;
|
|
165
|
+
*:OPEN) verdict=DELTA_PR_OPEN ;; # ①-b 가 이미 본다
|
|
166
|
+
*:MERGED) verdict=DELTA_AFTER_MERGED_PR ;; # PR 은 머지됐는데 델타가 남았다
|
|
167
|
+
*:CLOSED) verdict=DELTA_PR_CLOSED ;; # 안 머지되고 닫혔다
|
|
168
|
+
esac
|
|
169
|
+
fi
|
|
170
|
+
|
|
171
|
+
case "$verdict" in
|
|
172
|
+
DELTA_NO_PR|DELTA_AFTER_MERGED_PR|DELTA_PR_CLOSED|PATCHID_UNAVAILABLE|UNRELATED_HISTORY)
|
|
173
|
+
if [ "$age" -ge "$MIN_AGE_DAYS" ]; then
|
|
174
|
+
FINDINGS=$((FINDINGS+1))
|
|
175
|
+
printf '🟥 %-47s %-7s %-5s %-22s %s\n' "$r" "$kind" "${age}d" "$verdict" "$pr"
|
|
176
|
+
fi ;;
|
|
177
|
+
*)
|
|
178
|
+
[ "$QUIET" -eq 1 ] || printf ' %-47s %-7s %-5s %-22s %s\n' "$r" "$kind" "${age}d" "$verdict" "$pr" ;;
|
|
179
|
+
esac
|
|
180
|
+
done < "$REFLIST"
|
|
181
|
+
|
|
182
|
+
echo
|
|
183
|
+
if [ "$FINDINGS" -gt 0 ]; then
|
|
184
|
+
echo "🟥 착륙 경로에 없는 델타 $FINDINGS 건 (advisory — 막지 않는다)"
|
|
185
|
+
echo " DELTA_NO_PR PR 이 아예 없다 — ①-b 스윕의 정의 밖"
|
|
186
|
+
echo " DELTA_AFTER_MERGED_PR PR 은 머지됐는데 브랜치에 델타가 남았다(부분 머지)"
|
|
187
|
+
echo " DELTA_PR_CLOSED PR 이 머지 없이 닫혔다 — 의도일 수 있다, 확인은 사람 몫"
|
|
188
|
+
echo " 🟥 처분(삭제)은 이 계기의 일이 아니다 — Destructive-Op 게이트로 가라"
|
|
189
|
+
exit 1
|
|
190
|
+
fi
|
|
191
|
+
echo "✅ 착륙 경로 밖 델타 없음 (base=$BASE · 브랜치 ${REFCOUNT}개)"
|
|
192
|
+
exit 0
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""psa_extract_text.py — emit a file's SCANNABLE TEXT, or refuse.
|
|
3
|
+
|
|
4
|
+
WHY THIS EXISTS (2026-09-19). The public-surface scanners are line/byte matchers. For a container
|
|
5
|
+
format they read the container, not the text: a `.pptx` is a zip of XML, a PDF encodes glyphs. So
|
|
6
|
+
the scan returns "no hits" about bytes it never understood, and on the publish path that reads as
|
|
7
|
+
CLEAN. Measured the day this was written, on the real deposit artifact:
|
|
8
|
+
|
|
9
|
+
paper/forge_harness_v1.0.2.pdf PyMuPDF: <operator-token>=1 <org-token>=1 psa_scan: rc=0 CLEAN
|
|
10
|
+
|
|
11
|
+
🟥 The fix is NOT "skip containers" — skipping is the same false clean with a different name, and
|
|
12
|
+
the challenger round that chose `grep -a` in public_surface_scan_files.sh was right to refuse it.
|
|
13
|
+
The fix is: extract the text where we can, and REFUSE (non-zero) where we cannot. A refusal is a
|
|
14
|
+
verdict the caller can act on; a silent zero is not.
|
|
15
|
+
|
|
16
|
+
PRIOR ART CHECKED (no-reinvention gate, same day). The repo already has an OOXML reader —
|
|
17
|
+
`plugins/fh-preprep/skills/preprep/oox.py` — and it is the WRONG tool here, deliberately so:
|
|
18
|
+
it is a geometry/shape reader for the preprep lanes (slide order, EMU coordinates, paragraph and
|
|
19
|
+
run text) and it reads slides only, as prose. A private token hides in a relationship target, a
|
|
20
|
+
docProps field, a comment or an embedded hyperlink — precisely the parts a prose-and-slides
|
|
21
|
+
extractor drops. This module joins EVERY `.xml`/`.rels` part as raw text for that reason. Two
|
|
22
|
+
different jobs on the same file format; neither should be bent into the other.
|
|
23
|
+
|
|
24
|
+
CONTRACT
|
|
25
|
+
stdout : the file's scannable text (possibly empty for a genuinely empty file)
|
|
26
|
+
exit 0 : text emitted; the caller may scan it and trust a clean result
|
|
27
|
+
exit 3 : CANNOT EXTRACT — the caller must treat this as NOT SCANNED, never as 0 hits
|
|
28
|
+
exit 2 : usage / missing file
|
|
29
|
+
|
|
30
|
+
🟥 exit 3 is the whole point. Every new branch added here must keep the property that an
|
|
31
|
+
unsupported or damaged input leaves through exit 3 and not through exit 0 with empty output.
|
|
32
|
+
"""
|
|
33
|
+
import sys
|
|
34
|
+
import os
|
|
35
|
+
import zipfile
|
|
36
|
+
|
|
37
|
+
# Formats whose bytes ARE their text — passed through unchanged.
|
|
38
|
+
# 🟥 This list is on the SCANNABLE side on purpose: an unfamiliar type falls through to the
|
|
39
|
+
# container branches and then to exit 3, never to a bare "clean". A known-binary list would have
|
|
40
|
+
# the opposite failure direction (everything nobody listed sails past).
|
|
41
|
+
_TEXTISH_SUFFIX = (
|
|
42
|
+
".txt", ".md", ".html", ".htm", ".xml", ".svg", ".json", ".yaml", ".yml",
|
|
43
|
+
".sh", ".bash", ".zsh", ".py", ".js", ".mjs", ".cjs", ".ts", ".tsv", ".csv",
|
|
44
|
+
".toml", ".ini", ".cfg", ".cff", ".rst", ".tex", ".patch", ".diff", ".snippet",
|
|
45
|
+
)
|
|
46
|
+
_OOXML_SUFFIX = (".pptx", ".docx", ".xlsx", ".potx", ".dotx", ".xltx")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _looks_textish(path: str) -> bool:
|
|
50
|
+
"""A file is text if it decodes as UTF-8 and carries no NUL. Suffix is only a fast path.
|
|
51
|
+
|
|
52
|
+
🟥 Suffix alone is not the test — a `.txt` holding binary must not be waved through, and a
|
|
53
|
+
suffix-less text file must not be refused. The decode is the discriminator; the suffix just
|
|
54
|
+
avoids reading big binaries twice.
|
|
55
|
+
"""
|
|
56
|
+
try:
|
|
57
|
+
with open(path, "rb") as fh:
|
|
58
|
+
head = fh.read(65536)
|
|
59
|
+
except OSError:
|
|
60
|
+
return False
|
|
61
|
+
if b"\x00" in head:
|
|
62
|
+
return False
|
|
63
|
+
if path.lower().endswith(_TEXTISH_SUFFIX):
|
|
64
|
+
return True
|
|
65
|
+
try:
|
|
66
|
+
head.decode("utf-8")
|
|
67
|
+
except UnicodeDecodeError:
|
|
68
|
+
return False
|
|
69
|
+
return True
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _ooxml_text(path: str) -> str:
|
|
73
|
+
"""Join every XML part of an OOXML container.
|
|
74
|
+
|
|
75
|
+
We deliberately do NOT parse the XML into prose: a private token can sit in a relationship
|
|
76
|
+
target, a docProps field, a comment, or an embedded hyperlink, and a prose-only extractor
|
|
77
|
+
would miss exactly the places a leak hides. The raw XML text is the safer scan surface.
|
|
78
|
+
"""
|
|
79
|
+
out = []
|
|
80
|
+
with zipfile.ZipFile(path) as zf:
|
|
81
|
+
for name in zf.namelist():
|
|
82
|
+
if name.endswith((".xml", ".rels")):
|
|
83
|
+
out.append(zf.read(name).decode("utf-8", "ignore"))
|
|
84
|
+
return "\n".join(out)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _pdf_text(path: str) -> str:
|
|
88
|
+
try:
|
|
89
|
+
import pymupdf # type: ignore
|
|
90
|
+
except ImportError:
|
|
91
|
+
try:
|
|
92
|
+
import fitz as pymupdf # type: ignore
|
|
93
|
+
except ImportError:
|
|
94
|
+
raise RuntimeError("no PDF text extractor available (pymupdf)")
|
|
95
|
+
with pymupdf.open(path) as doc:
|
|
96
|
+
return "".join(page.get_text() for page in doc)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def main(argv):
|
|
100
|
+
if len(argv) != 2:
|
|
101
|
+
sys.stderr.write("usage: psa_extract_text.py <path>\n")
|
|
102
|
+
return 2
|
|
103
|
+
path = argv[1]
|
|
104
|
+
if not os.path.isfile(path):
|
|
105
|
+
sys.stderr.write("psa_extract_text: not a file: %s\n" % path)
|
|
106
|
+
return 2
|
|
107
|
+
|
|
108
|
+
low = path.lower()
|
|
109
|
+
# 🟥 CONTAINER SUFFIX WINS OVER THE TEXT HEURISTIC — this was a real bug, caught by a fixture
|
|
110
|
+
# whose extraction returned the file's RAW BYTES ("%PDF-1.4 4 0 obj<</Length 55>>stream ...").
|
|
111
|
+
# `_looks_textish` says True for any NUL-free UTF-8-decodable file, and a PDF can easily be
|
|
112
|
+
# NUL-free — measured: a hand-built one AND one written by MuPDF itself were both NUL-free.
|
|
113
|
+
# So those PDFs took the text path, the scanner matched raw bytes, and the encoded text was
|
|
114
|
+
# never read. The real deposit PDF only reached the PDF branch by accident: it happened to
|
|
115
|
+
# contain a NUL. An accident is not a code path.
|
|
116
|
+
if low.endswith(_OOXML_SUFFIX) or low.endswith(".pdf"):
|
|
117
|
+
try:
|
|
118
|
+
text = _ooxml_text(path) if low.endswith(_OOXML_SUFFIX) else _pdf_text(path)
|
|
119
|
+
except Exception as exc: # noqa: BLE001 — every failure leaves through exit 3
|
|
120
|
+
sys.stderr.write("psa_extract_text: CANNOT EXTRACT %s: %s\n" % (path, exc))
|
|
121
|
+
return 3
|
|
122
|
+
# 🟥 EMPTY IS NOT CLEAN. A container that yields zero characters was not read — it was
|
|
123
|
+
# opened and gave nothing, which is the same false clean one layer down. Measured: a
|
|
124
|
+
# malformed PDF returned 0 chars with exit 0, and the caller scanned emptiness and said
|
|
125
|
+
# CLEAN. A real document has text; "0 characters out of a %d-byte container" is a
|
|
126
|
+
# measurement failure, not a result.
|
|
127
|
+
if not text.strip():
|
|
128
|
+
sys.stderr.write(
|
|
129
|
+
"psa_extract_text: CANNOT EXTRACT %s: container yielded no text (%d bytes in)\n"
|
|
130
|
+
% (path, os.path.getsize(path))
|
|
131
|
+
)
|
|
132
|
+
return 3
|
|
133
|
+
sys.stdout.write(text)
|
|
134
|
+
return 0
|
|
135
|
+
|
|
136
|
+
if _looks_textish(path):
|
|
137
|
+
try:
|
|
138
|
+
with open(path, "r", encoding="utf-8", errors="replace") as fh:
|
|
139
|
+
sys.stdout.write(fh.read())
|
|
140
|
+
return 0
|
|
141
|
+
except OSError as exc:
|
|
142
|
+
sys.stderr.write("psa_extract_text: read failed: %s\n" % exc)
|
|
143
|
+
return 3
|
|
144
|
+
|
|
145
|
+
sys.stderr.write(
|
|
146
|
+
"psa_extract_text: CANNOT EXTRACT %s: unsupported non-text format\n" % path
|
|
147
|
+
)
|
|
148
|
+
return 3
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
if __name__ == "__main__":
|
|
152
|
+
sys.exit(main(sys.argv))
|
package/scripts/psa_scan_lib.sh
CHANGED
|
@@ -566,23 +566,115 @@ psa_scan_file() {
|
|
|
566
566
|
echo " ⚠️ MISSING — $1 : NOT SCANNED (unmeasured, not 0 hits)" >&2
|
|
567
567
|
return 3
|
|
568
568
|
fi
|
|
569
|
+
# 🟥 NON-TEXT INPUT IS "NOT SCANNED", NEVER "CLEAN" (2026-09-19).
|
|
570
|
+
# The scan below is line-based (`awk` → pattern match). A PDF, docx, pptx or image is not lines:
|
|
571
|
+
# its text is glyph-subset or zip-compressed, so the patterns match nothing and the file returns
|
|
572
|
+
# rc=0 — a CLEAN verdict about bytes the instrument never read. Measured the day this was added,
|
|
573
|
+
# on the surface this gate exists to protect:
|
|
574
|
+
# paper/forge_harness_v1.0.2.pdf PyMuPDF: <operator-token>=1 <org-token>=1 psa_scan: rc=0 CLEAN
|
|
575
|
+
# synthetic PDF whose text is literally "contact PSABINCANARY here" psa_scan: rc=0 CLEAN
|
|
576
|
+
# the SAME token in a .txt psa_scan: rc=1 HIT
|
|
577
|
+
# The packaging flipped the verdict, not the content. That is
|
|
578
|
+
# [[feedback_not_found_is_not_zero_family]] on an irreversible surface, and the repo already has
|
|
579
|
+
# the correct precedent next door: gate_shape_scan.sh answers UNSCANNABLE and lets exit 3 dominate.
|
|
580
|
+
#
|
|
581
|
+
# Discriminator is a MECHANICAL PROPERTY (a NUL byte anywhere), not an extension list — a list
|
|
582
|
+
# silently passes every format nobody thought of ("목록 = 커버리지"). Calibrated on the real
|
|
583
|
+
# corpus the same day: every .md/.html/.sh here → no NUL · every .pdf here → NUL, and
|
|
584
|
+
# `file --mime-type` agreed on all 9. A UTF-16 text file also lands here; that is the safe
|
|
585
|
+
# direction, since this line-based scan cannot read it correctly either.
|
|
586
|
+
#
|
|
587
|
+
# Failure direction: if `tr` itself fails, the byte counts differ and the file is called
|
|
588
|
+
# UNSCANNABLE. An instrument that breaks must not answer "clean".
|
|
589
|
+
local _psa_bytes _psa_nonul _psa_unscannable="" _psa_why=""
|
|
590
|
+
_psa_bytes=$(wc -c < "$1" 2>/dev/null | tr -d ' ')
|
|
591
|
+
_psa_nonul=$(LC_ALL=C tr -d '\000' < "$1" 2>/dev/null | wc -c 2>/dev/null | tr -d ' ')
|
|
592
|
+
if [ -z "$_psa_bytes" ] || [ -z "$_psa_nonul" ] || [ "$_psa_bytes" != "$_psa_nonul" ]; then
|
|
593
|
+
_psa_unscannable=1; _psa_why="NUL byte present"
|
|
594
|
+
fi
|
|
595
|
+
# 🟥 NUL ALONE IS NOT ENOUGH — cross-family (codex) broke it with execution evidence, reproduced
|
|
596
|
+
# here: a valid PDF with NO NUL byte, whose text sits in a PDF hex string
|
|
597
|
+
# (`<636F6E74616374...>` = "contact PSABINCANARY here"), scanned rc=0 CLEAN. Printability is not
|
|
598
|
+
# readability: the bytes were scannable and the meaning was not.
|
|
599
|
+
#
|
|
600
|
+
# So the second signal is the mime type, and THE LIST IS ON THE SCANNABLE SIDE ON PURPOSE.
|
|
601
|
+
# A "known-binary" list fails OPEN for every format nobody listed; a "known line-scannable" list
|
|
602
|
+
# fails CLOSED — an unfamiliar type becomes UNSCANNABLE, never CLEAN. On an irreversible surface
|
|
603
|
+
# that direction is the whole point, and it is the opposite of the "목록 = 커버리지" defect.
|
|
604
|
+
#
|
|
605
|
+
# Calibrated on this repo's real scan targets the day it was added (397 files): text/* covers
|
|
606
|
+
# shellscript 234 · plain 90 · python 17 · html 13, and the ONLY non-text type that is genuinely
|
|
607
|
+
# line-scannable here is application/json (43). That one exception is listed and justified;
|
|
608
|
+
# every unlisted type is refused.
|
|
609
|
+
if [ -z "$_psa_unscannable" ]; then
|
|
610
|
+
if command -v file >/dev/null 2>&1; then
|
|
611
|
+
local _psa_mime; _psa_mime=$(file --mime-type -b "$1" 2>/dev/null)
|
|
612
|
+
case "$_psa_mime" in
|
|
613
|
+
text/*|application/json|inode/x-empty|"") ;;
|
|
614
|
+
*) _psa_unscannable=1; _psa_why="mime=$_psa_mime is not line-scannable" ;;
|
|
615
|
+
esac
|
|
616
|
+
else
|
|
617
|
+
# 🟥 `file` 부재는 «통과» 가 아니라 «약해진 판별» 이다. NUL 축만 남으므로 위 hex-string PDF
|
|
618
|
+
# 같은 ASCII 컨테이너는 못 잡는다 — 판정에 싣지는 않되 이름으로 남긴다.
|
|
619
|
+
echo " ⚠️ DEGRADED DISCRIMINATOR — 'file' not on PATH; only the NUL-byte axis ran." >&2
|
|
620
|
+
echo " An ASCII-only container (e.g. a PDF whose text is a hex string) will NOT be caught." >&2
|
|
621
|
+
fi
|
|
622
|
+
fi
|
|
569
623
|
# `awk | psa_scan_tagged` hides an awk read failure when the caller has no pipefail: awk fails,
|
|
570
624
|
# psa_scan_tagged sees an empty stream and returns 0 = clean. Materialise the tagged stream first
|
|
571
625
|
# so the read is a checkable step of its own (cross-family round 1).
|
|
626
|
+
# 🟥 REFUSING IS THE FLOOR, NOT THE GOAL. Marking a container UNSCANNABLE is correct but it
|
|
627
|
+
# blocks every release that ships one — and this repo's own doctrine says a gate that always
|
|
628
|
+
# fires trains the override that disarms it. Measured: the npm published set (482 files) ships
|
|
629
|
+
# 2 `.pptx` fixtures, so a bare refusal would block every publish from here on.
|
|
630
|
+
# So we EXTRACT first and only refuse when extraction fails. `psa_extract_text.py` answers
|
|
631
|
+
# exit 0 + text, or exit 3 — never exit 0 with silence.
|
|
632
|
+
# 🟥 `${BASH_SOURCE[0]}` DOES NOT EXIST IN ZSH — the first wiring used it and the extractor
|
|
633
|
+
# silently never fired (this lib is sourced from zsh here, and its own Z-lanes exist because
|
|
634
|
+
# zsh is a supported arm). Resolve by explicit env first, then the repo root, then cwd; an
|
|
635
|
+
# unresolved extractor leaves `_psa_unscannable` set, so the failure direction stays UNSCANNABLE.
|
|
636
|
+
local _psa_src="$1" _psa_xtmp="" _psa_x="${PSA_EXTRACTOR:-}"
|
|
637
|
+
if [ -z "$_psa_x" ]; then
|
|
638
|
+
for _psa_c in \
|
|
639
|
+
"$(git rev-parse --show-toplevel 2>/dev/null)/scripts/psa_extract_text.py" \
|
|
640
|
+
"./scripts/psa_extract_text.py" \
|
|
641
|
+
"$(dirname -- "$0" 2>/dev/null)/psa_extract_text.py"; do
|
|
642
|
+
[ -f "$_psa_c" ] && { _psa_x="$_psa_c"; break; }
|
|
643
|
+
done
|
|
644
|
+
fi
|
|
645
|
+
if [ -n "$_psa_unscannable" ] && [ -n "$_psa_x" ] && [ -f "$_psa_x" ] && command -v python3 >/dev/null 2>&1; then
|
|
646
|
+
_psa_xtmp=$(mktemp 2>/dev/null)
|
|
647
|
+
if [ -n "$_psa_xtmp" ] && python3 "$_psa_x" "$1" > "$_psa_xtmp" 2>/dev/null; then
|
|
648
|
+
_psa_src="$_psa_xtmp"; _psa_unscannable=""; _psa_why=""
|
|
649
|
+
echo " ℹ️ EXTRACTED — $1 : scanned its extracted text, not its raw bytes." >&2
|
|
650
|
+
else
|
|
651
|
+
[ -n "$_psa_xtmp" ] && { rm -f "$_psa_xtmp" || :; _psa_xtmp=""; }
|
|
652
|
+
_psa_why="${_psa_why} · extraction also failed"
|
|
653
|
+
fi
|
|
654
|
+
fi
|
|
572
655
|
local tmpf
|
|
573
656
|
tmpf=$(mktemp 2>/dev/null) || { echo " ⚠️ mktemp failed; NOT SCANNED" >&2; return 3; }
|
|
574
|
-
if ! awk -v P="$1" '{print P "\t" $0}' "$
|
|
657
|
+
if ! awk -v P="$1" '{print P "\t" $0}' "$_psa_src" > "$tmpf" 2>/dev/null; then
|
|
575
658
|
rm -f "$tmpf" || :
|
|
576
659
|
echo " ⚠️ READ FAILED — $1 could not be tagged for scanning; NOT SCANNED" >&2
|
|
577
660
|
return 3
|
|
578
661
|
fi
|
|
579
662
|
if out=$(psa_scan_tagged < "$tmpf"); then rc=0; else rc=$?; fi
|
|
580
663
|
rm -f "$tmpf" || :
|
|
664
|
+
[ -n "$_psa_xtmp" ] && { rm -f "$_psa_xtmp" || :; }
|
|
581
665
|
# Print findings FIRST, verdict second — round 3 caught the previous order suppressing real hits:
|
|
582
666
|
# an incomplete instrument returned 3 and emitted nothing, so a token the loaded patterns DID match
|
|
583
667
|
# was lost. "I could not certify this" and "I saw nothing" are different, and the fix for the second
|
|
584
668
|
# must not create the first. Partial evidence is reported; the verdict still refuses to say clean.
|
|
585
669
|
[ -n "$out" ] && printf '%s\n' "$out"
|
|
670
|
+
if [ -n "$_psa_unscannable" ]; then
|
|
671
|
+
echo " ⚠️ UNSCANNABLE — $1 : not line-scannable (${_psa_why}). NOT SCANNED, not clean." >&2
|
|
672
|
+
echo " This scan reads lines; a PDF/docx/pptx/image keeps most of its text out of reach" >&2
|
|
673
|
+
echo " (glyph subsetting, zip/flate streams). Any hit printed above is PARTIAL — it is what" >&2
|
|
674
|
+
echo " happened to sit in readable bytes, not the file's text. Extract the text and scan" >&2
|
|
675
|
+
echo " that, or clear it by a manual-equivalent pass. Never read this as 0 hits." >&2
|
|
676
|
+
return 3
|
|
677
|
+
fi
|
|
586
678
|
if [ -n "$_incomplete" ]; then
|
|
587
679
|
echo " ⚠️ INCOMPLETE PATTERN INSTRUMENT — $_incomplete : verdict is NOT SCANNED (any hits above are partial)" >&2
|
|
588
680
|
return 3
|
|
@@ -175,6 +175,30 @@ while IFS= read -r f; do
|
|
|
175
175
|
$f"
|
|
176
176
|
continue
|
|
177
177
|
fi
|
|
178
|
+
# 🟥 CONTAINER FORMATS: the `grep -a` below reads BYTES. For a `.pptx` (zip of XML) or a `.pdf`
|
|
179
|
+
# (glyph-encoded) those bytes are not the document's text, so the loop matches nothing and the
|
|
180
|
+
# file counts as clean. Measured 2026-09-19 on the real artifact: the deposit PDF carries
|
|
181
|
+
# two operator-private tokens, and this scanner said CLEAN. The npm set ships 2 `.pptx`.
|
|
182
|
+
# ⇒ extract first, scan the extracted text, and count a FAILED extraction as UNSCANNED —
|
|
183
|
+
# which the block at the end already turns into a fail-closed publish refusal.
|
|
184
|
+
# 🟥 Refusing containers outright was the first design and it is wrong: it would block every
|
|
185
|
+
# release that ships one, and this repo's doctrine says a gate that always fires trains the
|
|
186
|
+
# override that disarms it. Extraction is what keeps the refusal rare enough to mean something.
|
|
187
|
+
scanpath="$path"; _xtmp=""
|
|
188
|
+
case "$(printf '%s' "$f" | tr 'A-Z' 'a-z')" in
|
|
189
|
+
*.pptx|*.docx|*.xlsx|*.potx|*.dotx|*.xltx|*.pdf)
|
|
190
|
+
_xtmp=$(mktemp 2>/dev/null)
|
|
191
|
+
if [ -n "$_xtmp" ] && command -v python3 >/dev/null 2>&1 \
|
|
192
|
+
&& python3 "$REPO_ROOT/scripts/psa_extract_text.py" "$path" > "$_xtmp" 2>/dev/null; then
|
|
193
|
+
scanpath="$_xtmp"
|
|
194
|
+
else
|
|
195
|
+
[ -n "$_xtmp" ] && rm -f "$_xtmp"
|
|
196
|
+
_xtmp=""
|
|
197
|
+
UNSCANNED=$((UNSCANNED+1)); UNSCANNED_LIST="$UNSCANNED_LIST
|
|
198
|
+
$f (container: text extraction failed)"
|
|
199
|
+
continue
|
|
200
|
+
fi ;;
|
|
201
|
+
esac
|
|
178
202
|
while IFS=$'\t' read -r sev regex; do
|
|
179
203
|
[ -z "$regex" ] && continue
|
|
180
204
|
case "$sev" in \#*) continue;; esac
|
|
@@ -194,8 +218,9 @@ while IFS= read -r f; do
|
|
|
194
218
|
LEAK=1
|
|
195
219
|
# -a forces every published file to scan as TEXT (challenger S1): -I skipped binary-classified
|
|
196
220
|
# files, so a token in an SVG / null-byte file (docs/pillars.svg ships) would slip unscanned.
|
|
197
|
-
done <<< "$(grep -aoiE "$regex" "$
|
|
221
|
+
done <<< "$(grep -aoiE "$regex" "$scanpath" 2>/dev/null | sort -u || true)"
|
|
198
222
|
done <<< "$PSA_STREAM"
|
|
223
|
+
[ -n "$_xtmp" ] && { rm -f "$_xtmp"; _xtmp=""; }
|
|
199
224
|
done <<< "$FILES"
|
|
200
225
|
|
|
201
226
|
# 🟥 «스캔 못 한 파일»은 «깨끗한 파일»이 아니다. 발행 목록에 있는데 읽지 못했으면
|
package/scripts/selfcheck.sh
CHANGED
|
@@ -661,6 +661,8 @@ for _pair in \
|
|
|
661
661
|
"scripts/destructive_pre_gate.sh|scripts/test_destructive_pre_gate_lanes.sh" \
|
|
662
662
|
"templates/.git-hooks/pre-push|scripts/test_prepush_destructive_lanes.sh" \
|
|
663
663
|
"templates/.git-hooks/pre-push|scripts/test_prepush_destructive_liveness.sh" \
|
|
664
|
+
`# ── 증거 vs 판정 토큰 충돌(2026-09-19). SUBJECT 는 훅이 아니라 «되돌림 프로브 자신»이다 — 이 레인이 재는 것은 게이트의 동작이 아니라 그 프로브의 «출력 계약»(자기가 authored 한 줄에만 ❌ 를 쓴다)이고, 이 집계기가 ❌ 로 실패를 판정하므로 둘이 같은 채널을 공유한다. 실측: run 35426860480 의 로그를 사람이 두 번 연속 오귀속했다 ──` \
|
|
665
|
+
"scripts/test_prepush_destructive_liveness.sh|scripts/test_liveness_echo_token_lanes.sh" \
|
|
664
666
|
"templates/.git-hooks/pre-push|scripts/test_push_zone_lanes.sh" \
|
|
665
667
|
"scripts/push_zone_check.sh|scripts/test_push_zone_lanes.sh" \
|
|
666
668
|
"scripts/session_close_check.sh|scripts/test_push_zone_lanes.sh" \
|
|
@@ -693,6 +695,12 @@ for _pair in \
|
|
|
693
695
|
"scripts/fixture_guard_lib.sh|scripts/test_fixture_guard_lanes.sh" \
|
|
694
696
|
"scripts/stray_path_scan.sh|scripts/test_stray_path_lanes.sh" \
|
|
695
697
|
"scripts/session_close_check.sh|scripts/test_stray_path_lanes.sh" \
|
|
698
|
+
`# 티키타카 채점기 (2026-09-19 신설) — 다중턴 sim 의 «수렴/반영» 을 채점한다. 러너(--turns)는 있었고 채점기가 0줄이었다.` \
|
|
699
|
+
"scripts/tikitaka_score.py|scripts/test_tikitaka_score_lanes.sh" \
|
|
700
|
+
`# 체크리스트 unblocked (2026-09-19 신설) — 막혀 있던 행의 블로커가 DONE 이 됐는데 그 행이 안 움직였나.
|
|
701
|
+
# 운영자 지적: «내 발화가 도중에 열화되었다 … 테스트 한 차례 끝날 때마다 들여다봐야 할 것 같다».
|
|
702
|
+
# SUBJECT 를 session_checklist.py 로 잡는다 — 이 레인이 재는 것은 그 도구의 판정이다.` \
|
|
703
|
+
"scripts/session_checklist.py|scripts/test_checklist_unblocked_lanes.sh" \
|
|
696
704
|
"templates/.git-hooks/pre-commit|scripts/test_hook_leg_wiring_lanes.sh" \
|
|
697
705
|
".claude/soul_tenets.txt|scripts/test_marker_soul_tenet_lanes.sh" \
|
|
698
706
|
"docs/map/fh_assets.architecture.json|scripts/test_fh_map_paths_lanes.sh" \
|
|
@@ -1423,6 +1431,21 @@ else
|
|
|
1423
1431
|
fail=1
|
|
1424
1432
|
fi
|
|
1425
1433
|
|
|
1434
|
+
# prless_delta_scan lanes — «커밋은 됐는데 착륙 경로에 안 올라간» 델타를 세는 advisory 계기.
|
|
1435
|
+
# 🟥 레인의 하중선은 **음성 컨트롤**이다: 이 레포는 squash 머지를 쓰므로 순진한 per-commit 비교는
|
|
1436
|
+
# 이미 착륙한 브랜치를 «미착륙» 으로 읽는다(2026-09-19 실측: naive 33/40 · git cherry 17/40 ·
|
|
1437
|
+
# 이 계기 10/40). 양성만 있는 레인은 «전부 고발하는 계기» 도 통과시킨다.
|
|
1438
|
+
if [ -f scripts/prless_delta_scan.sh ]; then
|
|
1439
|
+
if [ -f scripts/test_prless_delta_scan_lanes.sh ]; then
|
|
1440
|
+
if ! bash scripts/test_prless_delta_scan_lanes.sh; then
|
|
1441
|
+
fail=1
|
|
1442
|
+
fi
|
|
1443
|
+
else
|
|
1444
|
+
echo "FAIL test_prless_delta_scan_lanes.sh: prless_delta_scan.sh present but its anchor is missing"
|
|
1445
|
+
fail=1
|
|
1446
|
+
fi
|
|
1447
|
+
fi
|
|
1448
|
+
|
|
1426
1449
|
# temper_check lanes — 🟥 `templates/temper_check.sh` 는 게이트체인 7경로 중 **유일하게 실행 레인이
|
|
1427
1450
|
# 0** 이었다(2026-09-14 frontier-digest 후보 #1 → 독립 재현으로 참 판정). 참조 6곳이 전부 비실행
|
|
1428
1451
|
# 이었고, 그중 하나가 **바로 이 파일의 `bash -n` 목록**이다 — 즉 selfcheck 자신이 «구문 검사» 를
|