From 8105e00ceb59a73e96ad2bd45d2ece0c8fe5fb16 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 00:06:49 +0900 Subject: [PATCH] =?UTF-8?q?fix(hooks):=20ssh=20=EC=98=B5=EC=85=98=20?= =?UTF-8?q?=EA=B0=92=EA=B3=BC=20bash=20=EC=8B=A4=ED=96=89=EC=9D=84=20?= =?UTF-8?q?=EC=84=B8=EA=B3=A0=20=EB=AA=A8=EB=93=88=20README=EB=A5=BC=20des?= =?UTF-8?q?ktop=20=ED=8C=8C=EC=9D=BC=EB=A1=9C=20=EC=84=BC=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 앞 두 커밋 뒤 확인 리뷰가 퇴행 하나와 빠진 곳 하나를 찾았다. - 실행 판정을 다시 쓰면서 ssh 뒤 `-`로 시작하는 낱말만 뺐다. 값을 받는 옵션 (`ssh -o BatchMode=yes desktop …`, `ssh -p 22 desktop …`)은 그 값을 호스트로 읽어 desktop 실행으로 세지 않는다. `bash scripts/verify.sh merge`도 첫 낱말이 verify.sh가 아니라 세지 않는다. origin/main 판은 셋 다 셌다. - 노트북 파일에서 문서를 뺀 것이 `.claude/`뿐이다. `scripts/hooks/README.md`와 `docs/ledger/README.md`도 desktop `verify:documentation`이 읽는다. 고른 방법: ssh 뒤 옵션은 값을 받는 것(-o -p -i -l -J -F 등)이면 다음 낱말까지 건너뛰고 남은 첫 낱말을 호스트로 본다. bash·sh를 감싸는 낱말에 더한다. scripts/hooks/·scripts/tests/·docs/ledger/ 패턴에서도 `.md`를 뺀다. README 문장을 같이 고친다. 검증: python3 -m unittest discover -s scripts/tests 74개 통과(노트북). 새 경우 다섯(bash, ssh -o, ssh -p, 두 README)이 고치기 전 코드에서 실패했다. Refs: 1112/08-04, 1112/08-09 --- scripts/hooks/README.md | 4 ++-- scripts/hooks/hooks.py | 34 +++++++++++++++++++++++----------- scripts/tests/test_hooks.py | 10 ++++++++-- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/scripts/hooks/README.md b/scripts/hooks/README.md index 6b125d34..1197c975 100644 --- a/scripts/hooks/README.md +++ b/scripts/hooks/README.md @@ -25,8 +25,8 @@ Bash 직후 ──> post-bash ──> desktop에서 pnpm·게이트를 돌 | N2 | 같은 때, `*.md` | `scripts/check-work-docs.py`를 돌린다(작업 매뉴얼의 분량·이력 ID·뼈대·상대 링크) | 실패 줄. 고친 문서를 가리키는 줄이 있으면 그것만 | | N5 | Stop | 이 세션에서 desktop만 확인할 수 있는 파일(아래 밖의 모든 파일)을 고친 뒤 desktop 실행이 없으면 턴을 한 번 막고 이유를 준다 | `decision: block`, 다음 편집 전까지 한 번 | -- N5가 "desktop 실행"으로 치는 것: `ssh …`로 pnpm·`ci:gate`·`verify.sh`·vitest·playwright·`node scripts/…`를 돌린 명령(로그를 읽기만 하는 `cat`·`grep`·`tail` 등은 빼고), 또는 `scripts/verify.sh`를 명령으로 `docs`·`hooks` 밖 단계로(`--on here`·`--dry-run` 없이) 돌린 명령. 앞의 `VAR=값`과 `timeout`·`nohup` 같은 감싸는 낱말은 건너뛴다. `verify.sh`를 읽는 명령(`sed`, `grep`, `git log -- scripts/verify.sh`)은 세지 않는다. -- N5가 세지 않는 파일(노트북에서 확인되는 것): `.claude/`의 문서 밖 파일(설정·훅 상태), `scripts/hooks/`, `scripts/tests/`, `scripts/check-work-docs.py`, `docs/ledger/`. 이것들은 `scripts/verify.sh docs`·`hooks`가 노트북에서 본다. `CLAUDE.md`, `src/**/AGENTS.md`·`CLAUDE.md`, `.claude/**/*.md`는 desktop `verify:documentation`도 보므로 센다. +- N5가 "desktop 실행"으로 치는 것: `ssh …`로 pnpm·`ci:gate`·`verify.sh`·vitest·playwright·`node scripts/…`를 돌린 명령(로그를 읽기만 하는 `cat`·`grep`·`tail` 등은 빼고), 또는 `scripts/verify.sh`를 명령으로 `docs`·`hooks` 밖 단계로(`--on here`·`--dry-run` 없이) 돌린 명령. 앞의 `VAR=값`과 `timeout`·`nohup`·`bash` 같은 감싸는 낱말, ssh 옵션과 그 값(`-o BatchMode=yes`, `-p 22`)은 건너뛴다. `verify.sh`를 읽는 명령(`sed`, `grep`, `git log -- scripts/verify.sh`)은 세지 않는다. +- N5가 세지 않는 파일(노트북에서 확인되는 것): `.claude/`의 설정·훅 상태, `scripts/hooks/`·`scripts/tests/`의 코드, `scripts/check-work-docs.py`, `docs/ledger/`의 장부. 이것들은 `scripts/verify.sh docs`·`hooks`가 노트북에서 본다. 그 폴더의 문서(`.md`)와 `CLAUDE.md`, `src/**/AGENTS.md`·`CLAUDE.md`는 desktop `verify:documentation`도 보므로 센다. - N5가 기억하는 것은 `.claude/hook-state/.json`이다(git이 무시한다). - 권한 쪽 차단: `.claude/settings.json`의 `permissions.deny`가 실제 `.env`·`.env.local`·`.env.*.local`·`.env.` 읽기·쓰기를 막는다. `.env.example`은 막지 않는다. diff --git a/scripts/hooks/hooks.py b/scripts/hooks/hooks.py index 6ddeb4f5..03dc4a63 100755 --- a/scripts/hooks/hooks.py +++ b/scripts/hooks/hooks.py @@ -71,23 +71,26 @@ DOC_TIMEOUT = 20 # --- N5: an edit that only the desktop can check, until a desktop run -------------------------------------- # Laptop-checkable on their own: the hooks and their tests, the work-manual checker, the ledger and the -# Claude settings outside its documents. Everything else is checked by gates that need pnpm, documents -# included: verify:documentation reads CLAUDE.md, the folder rule books under src/ and .claude/**/*.md -# too (1112/08-04). +# Claude settings, documents left out. Everything else is checked by gates that need pnpm, documents +# included: verify:documentation reads CLAUDE.md, the folder rule books under src/, .claude/**/*.md and +# the module READMEs of scripts/hooks/ and docs/ledger/ too (1112/08-04). LAPTOP_ONLY = ( re.compile(r"^\.claude/(?!.*\.md$)"), - re.compile(r"^scripts/hooks/"), - re.compile(r"^scripts/tests/"), + re.compile(r"^scripts/hooks/(?!.*\.md$)"), + re.compile(r"^scripts/tests/(?!.*\.md$)"), re.compile(r"^scripts/check-work-docs\.py$"), - re.compile(r"^docs/ledger/"), + re.compile(r"^docs/ledger/(?!.*\.md$)"), ) DESKTOP_HOST = re.compile(r"desktop") DESKTOP_WORK = re.compile(r"\b(?:pnpm|ci:gate|verify\.sh|vitest|playwright)\b|\bnode\s+scripts/") LAPTOP_STAGES = {"docs", "hooks"} # 1112/08-09. One command of a shell line: what follows ;, &&, ||, |, ( or a newline. COMMAND_SEPARATOR = re.compile(r"&&|\|\||;|\||\(|\)|\n") -# Words that run the next command: `timeout 900 scripts/verify.sh …`. -WRAPPERS = {"timeout": 1, "nohup": 0, "setsid": 0, "env": 0, "time": 0, "exec": 0} +# Words that run the next command: `timeout 900 scripts/verify.sh …`, `bash scripts/verify.sh …`. +WRAPPERS = {"timeout": 1, "nohup": 0, "setsid": 0, "env": 0, "time": 0, "exec": 0, "bash": 0, "sh": 0} +# ssh options that take the next word as their value (`ssh -o BatchMode=yes desktop …`). +SSH_VALUE_OPTIONS = {"-B", "-b", "-c", "-D", "-E", "-e", "-F", "-I", "-i", "-J", "-L", "-l", "-m", "-O", + "-o", "-P", "-p", "-Q", "-R", "-S", "-W", "-w"} # A remote command made only of these reads logs; it runs nothing. READ_ONLY = {"cat", "grep", "tail", "head", "less", "ls", "sed", "awk", "wc", "find", "stat", "echo", "printf", "date", "uptime", "ps", "test", "true", "for", "do", "done", "if", "then", "fi"} @@ -305,6 +308,16 @@ def command_words(segment: str) -> list[str]: return words +def ssh_host_and_remote(words: list[str]) -> tuple[str | None, str]: + """The host and the remote command of the words after `ssh`, its options and their values skipped.""" + position = 0 + while position < len(words) and words[position].startswith("-"): + position += 2 if words[position] in SSH_VALUE_OPTIONS else 1 + if position >= len(words): + return None, "" + return words[position], " ".join(words[position + 1:]) + + def runs_only_reads(remote: str) -> bool: segments = [command_words(part) for part in COMMAND_SEPARATOR.split(remote)] return all(not words or words[0] in READ_ONLY for words in segments) @@ -319,9 +332,8 @@ def ran_on_desktop(command: str) -> bool: words = split_words(command) for position, word in enumerate(words): if word.endswith("ssh"): - rest = [w for w in words[position + 1:] if not w.startswith("-")] - hosts, remote = rest[:1], " ".join(rest[1:]) - if (any(DESKTOP_HOST.search(host) for host in hosts) and DESKTOP_WORK.search(remote) + host, remote = ssh_host_and_remote(words[position + 1:]) + if (host is not None and DESKTOP_HOST.search(host) and DESKTOP_WORK.search(remote) and not runs_only_reads(remote)): return True for segment in COMMAND_SEPARATOR.split(command): diff --git a/scripts/tests/test_hooks.py b/scripts/tests/test_hooks.py index e109318d..ac1563e9 100644 --- a/scripts/tests/test_hooks.py +++ b/scripts/tests/test_hooks.py @@ -248,7 +248,11 @@ class TurnEndNudgeTest(RepositoryTestCase): def test_a_wrapped_desktop_step_counts(self) -> None: for command in ("timeout 900 scripts/verify.sh exec --log x -- node scripts/run-vitest.ts run tests/unit/a.test.ts", - "VERIFY_SNAPSHOT=1 scripts/verify.sh merge --log r9"): + "VERIFY_SNAPSHOT=1 scripts/verify.sh merge --log r9", + # round9 confirm review: a shell that runs the script, and ssh options with a value. + "bash scripts/verify.sh merge --log r9", + "ssh -o BatchMode=yes desktop 'cd ~/workspace/x && corepack pnpm -s lint'", + "ssh -p 22 desktop 'corepack pnpm -s lint'"): with self.subTest(command=command): self.edit("src/domain/order.ts", "export const a = 6;\n") self.bash(command) @@ -273,7 +277,9 @@ class TurnEndNudgeTest(RepositoryTestCase): def test_living_instruction_documents_need_the_desktop(self) -> None: # 1112/08-04. verify:documentation, a desktop gate, checks these documents too. for path in (".claude/rules/x.md", ".claude/skills/fe-x/SKILL.md", "CLAUDE.md", - "src/adapters/AGENTS.md", "src/features/CLAUDE.md"): + "src/adapters/AGENTS.md", "src/features/CLAUDE.md", + # round9 confirm review: living module READMEs beside laptop-checked files. + "scripts/hooks/README.md", "docs/ledger/README.md"): with self.subTest(path=path): self.edit(path, "x\n") self.assertIsNotNone(self.stop())