merge: PR #29을 합친 검사 브랜치에 넣는다
This commit is contained in:
@@ -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 <desktop 호스트> …`로 pnpm·`ci:gate`·`verify.sh`·vitest·playwright·`node scripts/…`를 돌린 명령, 또는 `scripts/verify.sh`를 `docs`·`hooks` 밖 단계로(`--on here` 없이) 돌린 명령.
|
||||
- N5가 세지 않는 파일(노트북에서 확인되는 것): `.claude/`, `scripts/hooks/`, `scripts/tests/`, `scripts/check-work-docs.py`, `docs/ledger/`, `CLAUDE.md`, `src/**/AGENTS.md`·`CLAUDE.md`. 이것들은 `scripts/verify.sh docs`·`hooks`가 노트북에서 본다.
|
||||
- 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`·`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/<session_id>.json`이다(git이 무시한다).
|
||||
- 권한 쪽 차단: `.claude/settings.json`의 `permissions.deny`가 실제 `.env`·`.env.local`·`.env.*.local`·`.env.<mode>` 읽기·쓰기를 막는다. `.env.example`은 막지 않는다.
|
||||
|
||||
|
||||
+70
-18
@@ -70,21 +70,32 @@ DOC_CHECK = ("scripts/check-work-docs.py",)
|
||||
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, Claude
|
||||
# settings, CLAUDE.md and the folder rule books under src/ (scripts/check-work-docs.py checks them). Everything else is checked by gates that need pnpm.
|
||||
# Laptop-checkable on their own: the hooks and their tests, the work-manual checker, the ledger and the
|
||||
# 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/"),
|
||||
re.compile(r"^scripts/hooks/"),
|
||||
re.compile(r"^scripts/tests/"),
|
||||
re.compile(r"^\.claude/(?!.*\.md$)"),
|
||||
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"^CLAUDE\.md$"),
|
||||
re.compile(r"^src/(?:.+/)?(?:AGENTS|CLAUDE)\.md$"),
|
||||
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/")
|
||||
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 …`, `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"}
|
||||
ASSIGNMENT = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*=")
|
||||
STEP_WORD = re.compile(r"^[a-z][a-z0-9-]*$")
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
@@ -277,20 +288,61 @@ 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 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)
|
||||
|
||||
|
||||
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):
|
||||
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 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,30 @@ 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",
|
||||
# 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)
|
||||
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",
|
||||
@@ -244,13 +268,22 @@ class TurnEndNudgeTest(RepositoryTestCase):
|
||||
self.assertIsNotNone(self.stop())
|
||||
|
||||
def test_files_the_laptop_checks_do_not_need_the_desktop(self) -> None:
|
||||
for path in (".claude/rules/x.md", "scripts/hooks/hooks.py", "scripts/tests/test_x.py", "CLAUDE.md",
|
||||
"docs/ledger/estimates.jsonl", "scripts/check-work-docs.py", "src/adapters/AGENTS.md",
|
||||
"src/features/CLAUDE.md"):
|
||||
for path in (".claude/settings.json", "scripts/hooks/hooks.py", "scripts/tests/test_x.py",
|
||||
"docs/ledger/estimates.jsonl", "scripts/check-work-docs.py"):
|
||||
self.repo.write(path, "x\n")
|
||||
run_event("post-edit", self.repo.payload(path))
|
||||
self.assertIsNone(self.stop())
|
||||
|
||||
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",
|
||||
# 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())
|
||||
|
||||
def test_a_new_edit_after_the_reminder_reminds_again(self) -> None:
|
||||
self.edit("src/domain/order.ts", "export const a = 4;\n")
|
||||
self.stop()
|
||||
|
||||
Reference in New Issue
Block a user