---
task_id: task-2569
type: plan
scope: task
created: 2026-05-13
updated: 2026-05-13
status: completed
---

# 계획서: task-2569

**task**: task-2569 — finish-task.sh / workspace isolation / task md 보존 시스템 fix
**목표**: task-2568 진행 중 발생한 시스템 손상 (task md 소실, 3-docs 소실, stash 20+ 누적)의 근본 원인을 제거하고 재발 방지 가드를 도입한다.
**승인**: 회장 (drumband@gmail.com) 2026-05-13 task-2569.md 박제
**근거**: memory/tasks/task-2569.md, memory/events/task-2569.codex-gate (Codex 사전 리뷰 결과)

---

## 목표

1. **중앙 protection config** (`memory/specs/protection-list.md`) 도입 — 하드코딩된 분산 protection을 단일 진실 소스로 통합
2. **lock_sha..HEAD 기준 scope guard** 지원 — PR sub-task worktree에서 main 변경까지 scope 오판 방지
3. **dispatch task md 보존 정책** — write 직후 `git update-index --add --intent-to-add`로 untracked cleanup 영향 즉시 차단
4. **cleanup audit log** — 어떤 경로가 어떤 파일을 삭제 후보로 잡았는지 박제
5. **stash lifecycle 가시화** — finish-task.sh 진입/종료 시 stash list 박제
6. **regression test 4종** — RC/AD별 최소 1건씩

## 범위

### 포함 (10 영역)
- RC-1: cleanup-stale-tasks.sh + task-timer.py cleanup audit (영향 검증 — Codex 권고 audit-first)
- RC-2: cleanup-workspace.py / file_cleanup.py protection-list 적용 + dry-run 기본
- RC-3: finish-task.sh stash audit log (외부 stash 누적 박제 + 경고)
- RC-4: dispatch/__init__.py task md write 직후 intent-to-add (overwrite 패턴 자체는 유지, 보존성 강화)
- AD-1~3: pre-push hook + pre_push_guard.py + task_scope.py에 lock_sha..HEAD 지원
- AD-4: memory/specs/protection-list.md 신규 — 단일 protection config
- AD-5: lifecycle audit log 추가 (memory/logs/cleanup-audit.jsonl)
- AD-6: post-merge evidence stale 방지 정책 명시 (실 watcher 수정은 escalate)
- 테스트: regression test 4종

### 제외 (회장 명시 금지 사항 + scope expansion 방지)
- task-2568 PR #117/#118/#119 추가 commit 금지
- worktree_manager.py 대규모 리팩토링 (stash 진짜 원인 가능성은 보고서에 escalate)
- watcher 데몬 (done-watcher.sh) 대규모 수정 — 정책만 명시
- dispatch attempt 별 파일 분리 — intent-to-add로 충분, 분리는 별도 task로 escalate
- anu_v2, .github/workflows, 다른 task의 events/reports (회장 명시 forbidden_paths)

## 위임 계획

- **MT-1 (백엔드/루)**: `memory/specs/protection-list.md` 신규 작성 — 보호 경로 + glob + 사유 명시
- **MT-2 (백엔드/루)**: `scripts/cleanup-workspace.py` 수정 — protection-list 로드 + 기본 dry-run + audit log
- **MT-3 (백엔드/루)**: `scripts/file_cleanup.py` 수정 — protection-list 적용 + audit log
- **MT-4 (백엔드/루)**: `scripts/cleanup-stale-tasks.sh` + `memory/task-timer.py` cleanup 명령 audit log (task md/3-docs 영향 박제)
- **MT-5 (백엔드/루)**: `scripts/finish-task.sh` stash audit log (진입/종료 stash list, 누적 경고)
- **MT-6 (백엔드/루)**: `dispatch/__init__.py` line 2803/3567 task md write 직후 `git update-index --add --intent-to-add` 호출
- **MT-7 (백엔드/루)**: `scripts/pre_push_guard.py` + `scripts/task_scope.py` + `scripts/git-hooks/pre-push`에 lock_sha..HEAD 자동 분기
- **MT-T1~T4 (테스터/모리건)**: regression test 4종 (preservation, stash_lifecycle, scope_guard_lock_sha, cleanup_protection)

## 검증 기준

- protection-list.md 존재 + cleanup 스크립트가 로드: `python3 -c "import sys; sys.path.insert(0,'scripts'); from file_cleanup import FileCleanup"`
- cleanup-workspace.py dry-run 기본: `python3 scripts/cleanup-workspace.py --help | grep -i dry-run`
- dispatch task md intent-to-add: dispatch 실행 후 `git ls-files --others memory/tasks/<task>.md` → 빈 출력 (untracked 아님)
- pre-push lock_sha 분기: lock 파일에 `lock_sha` 키 존재 시 `git diff lock_sha..HEAD` 사용
- regression test 4종 pytest PASS
- 셀프 QC 8항목 PASS + qc_verify.py PASS + 마아트 독립 검증 PASS

## 비고

Codex 사전 리뷰 결과 (memory/events/task-2569.codex-gate) 핵심 통찰:
- RC-1 (cleanup-stale → task md 삭제) 가설은 약함 → audit-first로 좁힘
- RC-3 stash는 `finish-task.sh`에 없음 → 외부 (worktree_manager 등)일 가능성 escalate
- protection은 분산 hardcode 대신 단일 config 권고 → 채택
- scope guard는 lock_sha..HEAD 한 세트 권고 → 채택
- dispatch attempt 분리는 retry 흐름 광범위 영향 → 본 task에서는 intent-to-add만, 분리는 escalate
