fix(hooks): verify.sh를 읽거나 dry-run만 한 명령을 desktop 실행으로 세지 않는다
편집 훅 N5는 desktop에서만 확인되는 파일을 고친 뒤 desktop 실행이 없으면 턴 끝에 한 번 알린다. 그런데 명령 안에 `scripts/verify.sh` 글자만 있어도 뒤 낱말을 단계로 보고 실행으로 셌다. `sed -n 1,80p scripts/verify.sh && ls`, `grep … scripts/verify.sh config/ci/gates.json`, `git log -- scripts/verify.sh docs/work`, `scripts/verify.sh merge --dry-run`, 로그를 읽기만 하는 `ssh desktop 'cat …log | grep vitest'`가 모두 알림을 지웠다. README는 "돌린 명령"만 센다고 적는다. 고른 방법: 명령줄을 ;·&&·||·|·( 로 나눠 한 명령씩 본다. 앞의 VAR=값과 timeout·nohup 같은 감싸는 낱말을 건너뛴 첫 낱말이 verify.sh이고, 다음 낱말이 단계 이름 꼴이며 docs·hooks가 아니고, --dry-run·--on here가 없을 때만 센다. ssh는 원격 명령이 읽기 명령(cat·grep·tail 등)뿐이면 세지 않는다. 버린 대안: config/ci/gates.json의 stage id를 읽어 대조하기(시험 repo와 다른 checkout에서도 같은 목록을 읽어야 한다. exec·gate·script도 단계 자리에 온다). 위험·한계: 처음 보는 감싸는 낱말(예: `flock <파일> scripts/verify.sh`)은 실행으로 세지 않아 알림이 한 번 더 뜬다. 막지는 않는다. 검증: python3 -m unittest discover -s scripts/tests 74개 통과(노트북). 새 시험 다섯 경우가 고치기 전 코드에서 실패했다. Refs: 1112/08-09
This commit is contained in:
@@ -25,7 +25,7 @@ Bash 직후 ──> post-bash ──> desktop에서 pnpm·게이트를 돌
|
||||
| N2 | 같은 때, `*.md` | `scripts/check-work-docs.py`를 돌린다(작업 매뉴얼의 분량·이력 ID·뼈대·상대 링크) | 실패 줄. 고친 문서를 가리키는 줄이 있으면 그것만 |
|
||||
| N5 | Stop | 이 세션에서 desktop만 확인할 수 있는 파일(아래 밖의 모든 파일)을 고친 뒤 desktop 실행이 없으면 턴을 한 번 막고 이유를 준다 | `decision: block`, 다음 편집 전까지 한 번 |
|
||||
|
||||
- N5가 "desktop 실행"으로 치는 것: `ssh <desktop 호스트> …`로 pnpm·`ci:gate`·`verify.sh`·vitest·playwright·`node scripts/…`를 돌린 명령, 또는 `scripts/verify.sh`를 `docs`·`hooks` 밖 단계로(`--on here` 없이) 돌린 명령.
|
||||
- N5가 "desktop 실행"으로 치는 것: `ssh <desktop 호스트> …`로 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가 기억하는 것은 `.claude/hook-state/<session_id>.json`이다(git이 무시한다).
|
||||
- 권한 쪽 차단: `.claude/settings.json`의 `permissions.deny`가 실제 `.env`·`.env.local`·`.env.*.local`·`.env.<mode>` 읽기·쓰기를 막는다. `.env.example`은 막지 않는다.
|
||||
|
||||
+50
-10
@@ -83,8 +83,16 @@ LAPTOP_ONLY = (
|
||||
)
|
||||
DESKTOP_HOST = re.compile(r"desktop")
|
||||
DESKTOP_WORK = re.compile(r"\b(?:pnpm|ci:gate|verify\.sh|vitest|playwright)\b|\bnode\s+scripts/")
|
||||
VERIFY = re.compile(r"(?:^|[\s;&|(])(?:\./)?scripts/verify\.sh\s+(\S+)(.*)")
|
||||
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}
|
||||
# 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"}
|
||||
ASSIGNMENT = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*=")
|
||||
STEP_WORD = re.compile(r"^[a-z][a-z0-9-]*$")
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
@@ -277,20 +285,52 @@ def needs_desktop(path: str) -> bool:
|
||||
return not any(pattern.search(path) for pattern in LAPTOP_ONLY)
|
||||
|
||||
|
||||
def ran_on_desktop(command: str) -> bool:
|
||||
"""An `ssh <desktop> …` running pnpm or a gate, or scripts/verify.sh with a stage that goes there."""
|
||||
def split_words(text: str) -> list[str]:
|
||||
try:
|
||||
words = shlex.split(command)
|
||||
return shlex.split(text)
|
||||
except ValueError:
|
||||
words = command.split()
|
||||
return text.split()
|
||||
|
||||
|
||||
def command_words(segment: str) -> list[str]:
|
||||
"""The words of one command, its leading `VAR=value` and wrapper words dropped."""
|
||||
words = split_words(segment)
|
||||
while words:
|
||||
if ASSIGNMENT.match(words[0]):
|
||||
words = words[1:]
|
||||
elif words[0] in WRAPPERS:
|
||||
words = words[1 + WRAPPERS[words[0]]:]
|
||||
else:
|
||||
break
|
||||
return words
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def ran_on_desktop(command: str) -> bool:
|
||||
"""An `ssh <desktop> …` running pnpm or a gate, or scripts/verify.sh running a step that goes there.
|
||||
|
||||
1112/08-09. Reading verify.sh (`sed`, `grep`, `git log -- scripts/verify.sh`), `--dry-run` and
|
||||
an ssh that only reads logs run nothing on the desktop.
|
||||
"""
|
||||
words = split_words(command)
|
||||
for position, word in enumerate(words):
|
||||
if word.endswith("ssh"):
|
||||
hosts = [w for w in words[position + 1:position + 5] if not w.startswith("-")][:2]
|
||||
if any(DESKTOP_HOST.search(host) for host in hosts) and DESKTOP_WORK.search(command):
|
||||
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)
|
||||
and not runs_only_reads(remote)):
|
||||
return True
|
||||
for match in VERIFY.finditer(command):
|
||||
stage, rest = match.group(1), match.group(2)
|
||||
if stage not in LAPTOP_STAGES and not re.search(r"--on\s+here\b", rest):
|
||||
for segment in COMMAND_SEPARATOR.split(command):
|
||||
words = command_words(segment)
|
||||
if len(words) < 2 or not re.search(r"(?:^|/)scripts/verify\.sh$", words[0]):
|
||||
continue
|
||||
step, flags = words[1], words[2:]
|
||||
if (STEP_WORD.match(step) and step not in LAPTOP_STAGES and "--dry-run" not in flags
|
||||
and not re.search(r"--on\s+here\b", " ".join(flags))):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@@ -234,6 +234,26 @@ class TurnEndNudgeTest(RepositoryTestCase):
|
||||
self.bash(command)
|
||||
self.assertIsNone(self.stop())
|
||||
|
||||
def test_reading_verify_sh_or_a_dry_run_does_not_count(self) -> None:
|
||||
# 1112/08-09. Only a command that runs a desktop step clears the reminder.
|
||||
for command in ("scripts/verify.sh merge --dry-run",
|
||||
"sed -n 1,80p scripts/verify.sh && ls",
|
||||
"grep -n foo scripts/verify.sh config/ci/gates.json",
|
||||
"git log -- scripts/verify.sh docs/work",
|
||||
"ssh desktop 'cat /tmp/claude-gates/x/FE-GATE-005.log | grep vitest'"):
|
||||
with self.subTest(command=command):
|
||||
self.edit("src/domain/order.ts", "export const a = 5;\n")
|
||||
self.bash(command)
|
||||
self.assertIsNotNone(self.stop())
|
||||
|
||||
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"):
|
||||
with self.subTest(command=command):
|
||||
self.edit("src/domain/order.ts", "export const a = 6;\n")
|
||||
self.bash(command)
|
||||
self.assertIsNone(self.stop())
|
||||
|
||||
def test_laptop_commands_and_other_hosts_do_not_count(self) -> None:
|
||||
for command in ("corepack pnpm lint", "ssh build-box 'corepack pnpm lint'", "scripts/verify.sh docs",
|
||||
"scripts/verify.sh hooks", "scripts/verify.sh gate FE-GATE-005 --on here",
|
||||
|
||||
Reference in New Issue
Block a user