Discovery — diff 범위: 인벤토리를 diff-rank-input으로 생성한다. 0단계 diffRankInput.kind로
명령을 고른다. 인자는 두 경로가 같다(npm 0.7.0이 Python 스크립트를 지우고 Node 헬퍼로 옮겼다,
상류 05cceee24 #1432).
# kind = python (npm 0.6.0 이하) — refs (커밋/브랜치)
env -i <trusted_child_env> <python_command> <plugin_dir>/scripts/generate_rank_input.py make-diff-rank-input --repo <repo_root> --base <base> --mode revisions --head <head> --out <scan_dir>/artifacts/02_discovery/rank_input.jsonl
# kind = python — working-tree (로컬 패치)
env -i <trusted_child_env> <python_command> <plugin_dir>/scripts/generate_rank_input.py make-diff-rank-input --repo <repo_root> --base <base> --mode local-patch --out <scan_dir>/artifacts/02_discovery/rank_input.jsonl
# kind = node-helper (npm 0.7.0) — refs
env -i <trusted_child_env> CODEX_MCP_NODE_PATH=<node> <security_md_launcher> --helper make-diff-rank-input --repo <repo_root> --base <base> --mode revisions --head <head> --out <scan_dir>/artifacts/02_discovery/rank_input.jsonl
# kind = node-helper — working-tree
env -i <trusted_child_env> CODEX_MCP_NODE_PATH=<node> <security_md_launcher> --helper make-diff-rank-input --repo <repo_root> --base <base> --mode local-patch --out <scan_dir>/artifacts/02_discovery/rank_input.jsonl
이어서 리뷰 입력을 파생한다(필수 호출). 0단계 copyDeepReviewInput.kind로 명령을 고른다. 인자는 같다.
# kind = python (npm 0.2.0 이하)
env -i <trusted_child_env> <python_command> <plugin_dir>/scripts/generate_rank_input.py copy-deep-review-input --rank-input <scan_dir>/artifacts/02_discovery/rank_input.jsonl --out <scan_dir>/artifacts/02_discovery/deep_review_input.jsonl
# kind = node-helper (npm 0.3.0 이후 — Python 하위 명령은 지워졌다, 상류 #839)
env -i <trusted_child_env> CODEX_MCP_NODE_PATH=<node> <security_md_launcher> --helper copy-deep-review-input --rank-input <scan_dir>/artifacts/02_discovery/rank_input.jsonl --out <scan_dir>/artifacts/02_discovery/deep_review_input.jsonl
Node 헬퍼는 make-diff-rank-input이 만든 행(path·area·preview)을 그대로 받는다. 행을 손으로
만들거나 고치지 않는다. 두 경로 모두 랭킹 입력의 모든 행을 같은 순서로 옮긴다(repro-u4.sh L2).
이 두 단계(make-diff-rank-input → copy-deep-review-input)의 상류 서술은 npm 0.7.0
skills/security-scan/references/scan-artifacts-and-ledger.md의 "Changed-file Worklist" 절이다("Standalone Diff
Worklists and Artifacts" — 레거시 diff 경로 전용으로 다시 쓰였다). 그 절의 MCP 저장 도구 지시는 P6-KTD8에 따라
적용하지 않는다.
diff 범위 인벤토리(in_scope_files.txt)도 상류 인벤토리 도우미로 만든다. 0단계 inScopeInventory.kind로
명령을 고른다. Phase 1의 rg --files 전체 목록을 쓰면 안 된다(범위가 저장소 전체가 된다):
# kind = python (npm 0.6.0 이하) — refs
env -i <trusted_child_env> <python_command> <plugin_dir>/scripts/generate_in_scope_files.py --repo <repo_root> --scope . --diff-base <base> --diff-head <head> --diff-mode revisions --out <scan_dir>/artifacts/02_discovery/in_scope_files.txt
# kind = python — working-tree
env -i <trusted_child_env> <python_command> <plugin_dir>/scripts/generate_in_scope_files.py --repo <repo_root> --scope . --diff-base <base> --diff-mode local-patch --out <scan_dir>/artifacts/02_discovery/in_scope_files.txt
# kind = node-helper (npm 0.7.0) — refs
env -i <trusted_child_env> CODEX_MCP_NODE_PATH=<node> <security_md_launcher> --helper generate-in-scope-files --repo <repo_root> --scope . --diff-base <base> --diff-head <head> --diff-mode revisions --out <scan_dir>/artifacts/02_discovery/in_scope_files.txt
# kind = node-helper — working-tree
env -i <trusted_child_env> CODEX_MCP_NODE_PATH=<node> <security_md_launcher> --helper generate-in-scope-files --repo <repo_root> --scope . --diff-base <base> --diff-mode local-patch --out <scan_dir>/artifacts/02_discovery/in_scope_files.txt
Node 헬퍼의 런처·env -i·CODEX_MCP_NODE_PATH는 Phase 1 SKILL.md 0단계 3번과 같다(P6-KTD6). 두 경로의
출력 집합은 같다(repro-u4.sh I 블록, 0.6.0·0.7.0 실측). 성공 출력은 인벤토리가 Recorded N in-scope files.,
랭킹 입력이 Wrote N rows to <경로>다.
셸에 보간하는 모든 값은 인용본을 쓴다 — <trusted_child_env> =
trustedChildEnvShell, 나머지 경로는 shellQuoted.*(repoRoot·scanDir·
pluginRoot·pythonPath·trustedPathEnv). 이중인용은 $()를 막지 못하고 이
값들의 출처는 미신뢰 환경이다(실측으로 mkdir -p "<scan_dir>/…"와
PATH="<pathEnv>" 둘 다 명령 치환이 실행됐다). 그리고 인용본을 다시 "…"로
감싸지 말 것 — 그러면 단일인용이 리터럴이 되고 $()는 그대로 확장돼 인용이
무효가 된다(실측). 위 명령형처럼 자리표시자는 맨몸으로 쓴다. 정본 근거는
Phase 1 SKILL.md 2단계.
RIPGREP_CONFIG_PATH=는 diff 경로에서는 실효가 없다 — diff 모드는 git만 쓰고 rg를
타지 않는다(실측: 오염된 설정에서도, PATH에 rg가 아예 없어도 결과가 같다. npm 0.7.0 Node 헬퍼도
diff 경로에서는 git diff·git ls-files만 부른다). 전체 스캔
인벤토리 호출과 형태를 맞춰 두는 방어 조치이며, 근거는 Phase 1 SKILL.md 2단계가 정본이다.
PATH는 <trusted_child_env> 안에 이미 있다. trustedChildEnvShell의 PATH는 bootstrap의
trustedPathEnv(대상 저장소 내부 항목을 제거한 PATH)이고 PYTHONDONTWRITEBYTECODE=1도 들어 있다.
그래서 위 diff 명령형에는 PATH=를 따로 붙이지 않는다. $PATH를 이어 붙이거나 env -i 밖에서 호출하지
않는다. diff 모드는 ripgrep을 쓰지 않으므로 --require-search는 붙이지 않지만, diff 인벤토리와 랭킹
입력이 git을 PATH에서 해석해 cwd=대상 저장소로 실행하므로 정화된 PATH가 필요하다. 원시 $PATH를 물려주면 대상
저장소가 커밋한 ./node_modules/.bin/git이 실행된다(실측). 전체 스캔과 같은 이유이며 정본
서술은 Phase 1 SKILL.md 2단계에 있다(P5-KTD2).
diff 인벤토리에 들어가는 파일(npm 0.4.0~0.7.0). diff 인벤토리와 diff 랭킹 입력은 같은 규칙을
쓴다(repro-u4.sh I 블록).
- 바이너리가 아닌 변경 파일 전부다. 파일 이름·확장자·디렉터리로 거르지 않는다(상류
skills/security-diff-scan/SKILL.md: "changed text files regardless of filename, extension, or
directory"). 그래서 .github/dependabot.yml·notes.txt도 들어간다. 바이너리 판정은 내용(NUL 바이트)
으로 하므로 .py 확장자라도 바이너리면 빠진다(repro-u4.sh I17~I20). 삭제된 파일은 base 쪽 내용으로
판정해 들어간다. 커밋 diff는 head 커밋의 blob으로, 로컬 패치는 워킹트리 파일로 판정하고 심링크는
뺀다. npm 0.5.1부터는 .git·.svn 아래 경로도 뺀다(#1552). 로컬 패치의 변경이 .svn 아래뿐이면
인벤토리가 비고 "빈 인벤토리" 분기로 간다.
- 이전 규칙(npm 0.2.0 이하): 확장자를
rank_preview.TEXT_CODE_EXTENSIONS로 거르고(0.2.0에서
.hh·.hxx·.ejs·.erb·.phtml·.vy까지), .github는 workflows/*만 남겼다. 이 집합과 제외
규칙은 npm 0.3.0(#1347)에서 지워졌다. 같은 diff라도 0.2.0과 0.4.0의 커버리지 분모가 다르다.
- 상류는 경로가 아니라 동작과 도달성으로 보안 관련성을 판단하라고 쓴다(빌드·배포·CI 사용 포함).
목록에 든 문서·설정 파일도 리뷰 대상이며, 보안과 무관하면 리뷰 로그에
reviewed로 남긴다.
- diff에 이름에
\n·\r이 든 경로가 있으면 인벤토리가
Git changes contain a path that cannot fit in the file inventory로 실패한다. 이 동작은
0.1.25에도 있었다. 그 경로는 Phase 1 SKILL.md 2단계의 탐색 명령(<스코프>는 .)으로 찾아
사용자에게 보여 준다. 이름을 바꾸기 전에는 이 diff를 스캔할 수 없다.
인벤토리의 변경 파일만 리뷰한다. 점검 항목은 Phase 1 2단계 2번과 같다(npm 0.10.0부터 references/baseline-auditor.md·
references/focused-investigator.md 포함). 후보는 Phase 1 2단계 5번의 정규화 명령(candidateNormalizer.kind로
고름)으로 단일 원장에 병합하되, diff 스캔은 --allow-missing-in-scope를 반드시 붙인다. 두 경로 모두
이 인자를 받는다:
# kind = python (npm 0.1.32 이하)
PYTHONDONTWRITEBYTECODE=1 <python_command> <plugin_dir>/scripts/normalize_candidates.py --input <raw1.jsonl> [...] --out <scan_dir>/artifacts/02_discovery/candidate_ledger.jsonl --repo-root <repo_root> --in-scope-files <scan_dir>/artifacts/02_discovery/in_scope_files.txt --allow-missing-in-scope
# kind = node-helper (npm 0.2.0부터)
env -i <trusted_child_env> CODEX_MCP_NODE_PATH=<node> <security_md_launcher> --helper normalize-candidates --input <raw1.jsonl> [...] --out <scan_dir>/artifacts/02_discovery/candidate_ledger.jsonl --repo-root <repo_root> --in-scope-files <scan_dir>/artifacts/02_discovery/in_scope_files.txt --allow-missing-in-scope
diff 인벤토리에는 삭제된 경로가 포함되며(예: git rm 된 파일), 이 플래그가 없으면
정규화가 exit 2로 실패한다(실측). 문구는 npm 0.1.32 이하 Python이 in-scope file row N: [Errno 2] No such file or directory: '<경로>', npm 0.2.0 Node 헬퍼가 in-scope file row N: ENOENT: no such file or directory, realpath '<경로>'다(npm 0.4.0·0.7.0도 같다). 플래그를 붙여도
후보 location 파일의 실존 검사는 그대로 수행된다.
삭제된 파일에 대한 finding 처리: head 시점에 존재하지 않는 경로만 locations에 갖는
finding은 coverage_reconcile.py가 거부한다("소스 루트 하위에 존재하지 않습니다" — 플러그인
finalizer 자체는 통과시키지만 우리 정산 게이트가 더 엄격하다, 실측). 그런 후보는 finding 대신
coverage.deferred(또는 not_applicable 서피스)로 기록하고 삭제 사실을 사유에 적는다.
review_log에는 base 시점에서 읽었음을 남긴다.