# DIRECT_SPAWN_HYBRID_IMPLEMENTATION_READINESS_PACKET (구현 준비도 설계 only — 구현/PR/canary/실행 0)

작성: 2026-06-09 KST / ANU 직접 / base CODE=origin/main 51b3a420
상태: `DIRECT_SPAWN_HYBRID_IMPLEMENTATION_READINESS_PENDING_ACTIVE_FALSE`
목적: 옵션 ii(direct spawn + cron-history owner-proof anchor) 구현 준비도 — argv/key/lifecycle/fail-closed/scope/cleanup/검증 설계. 구현·실행은 회장 별도 승인.

## ★ 핵심 메커니즘 발견 (read-only)
- cokacdir 에 **`--message`** 플래그 존재("Send message to AI", `--output-last-message` 동반 가능). = `--cron`(scheduler_loop 종속) 과 달리 **AI 세션에 직접/동기 메시지 주입** 경로.
- → direct spawn = `cokacdir --message "<prompt>" --chat <id> --key <ANU_KEY>` 로 scheduler_loop 우회(동기 spawn 후보). **단 동기·activity-independent 여부는 canary 검증 대상**(15).

## 16 항목

### 1. direct spawn 이 호출할 실제 명령/argv 구조
- `cokacdir --message "<scope-limited wake prompt>" --chat 6937032012 --key <sealed ANU key>` [+ `--output-last-message`(ack 회수) / isolated 모드].
- launch_wake 의 `subprocess.run(argv)` 재사용 — argv 구성만 `--cron`→`--message` 분기. (현 launcher single-responsibility 유지.)

### 2. key 전달 방식과 raw key 노출 방지
- `--key`=subprocess argv flag 로만 전달(현 launch_wake 와 동일). **로그/ledger/마커에 key literal 0**(LaunchRecord=argv_len only, PR#196 owner_key 제거). prompt body 에도 owner_key 0.
- ★ cokacdir schedule_history 미경유(--message 는 schedule 아님) → 이전 once-schedule prompt 적재 경로와 무관. 단 --message 가 다른 로그에 prompt/key 적재하는지 별도 확인(구현 전 read-only).

### 3. S owner-proof anchor 생성/검증/cleanup lifecycle
- (생성) wake 처리 직전 `cokacdir --cron "[owner-proof anchor 실행금지]" --at <먼미래> --key <ANU>` → S id.
- (검증) `resolve_authoritative_owner(S, RealCokacdirCronHistoryProbe())` = OWNER_ANU 확인 후에만 --message spawn.
- (cleanup) spawn 직후/완료 후 즉시 `cron-remove S` → 잔존 0. **anchor 수명 = 단일 wake 처리 한정(초~분).**

### 4. S 가 fire 되지 않도록 보장
- S `--at` = **먼 미래(+1d↑)** → scheduler due 도달 전. + **짧은 수명 즉시 cron-remove**(due 도달 한참 전 제거). 이중 보장. (canary 실증: +1d S 전부 미발사.)

### 5. resolve_authoritative_owner(S)=OWNER_ANU 실패 시 fail-closed
- OWNER_ANU 아님(NOT_ANU/QUERY_FAILED/PENDING) → **direct spawn 0**(launch 미실행) + 안전 abort + S cleanup. = 현 verify_collector_authoritative fail-closed 재사용.

### 6. non-ANU / stale / missing S 케이스 처리
- non-ANU(타 key 소유): cron-history "access denied/not found" → OWNER_NOT_ANU → spawn 0.
- stale(오래된 envelope): envelope staleness gate(verify 단계) → REJECT → spawn 0.
- missing(S id 없음/조회 실패): OWNER_QUERY_FAILED → fail-closed spawn 0.
- → 모든 비정상 = **spawn 0**(보수).

### 7. dedupe ledger 와 duplicate spawn 방지
- pickup_once 의 dedupe ledger((task_id, sha256)) fail-closed 재사용. direct spawn 직전 dedupe 확인 → 중복 result = SKIP_DEDUPE spawn 0. + done marker. **real spawn 1회 idempotent.**

### 8. spawned session prompt 최소화
- envelope-only prompt(task_id/result_path/report_path/sha256/collector_role/chat_id/canonical_root, **owner_key 0**) + CANARY/scope directive. 자유 지시문 금지(현 _build_envelope_prompt 재사용).

### 9. spawned session 권한/행동 제한
- (a) prompt scope 화이트리스트 (b) collector 범위=단일 result.json (c) callback enforcement(owner-pin) 유지 (d) raw key hygiene (e) forbidden 행동(canonical reset/clean/stash/dispatch/PR/merge/.done) 금지 명시.

### 10. PreToolUse hook 적용 범위
- spawned 세션에 **PreToolUse hook**: forbidden 명령(git reset/clean/stash -u/checkout -f, dispatch, gh pr, .done 생성, .env.keys read) 차단. 적용 = direct-spawn 세션 settings(isolated). ★ 구현 시 hook 결선 검증(작동 실패 시 spawn 거부).

### 11. canonical write 최대 1건 enforcement
- 머신러리(launcher) canonical write 0. spawned collector = 단일 task scope guard(해당 result/report/callback artifact 한정). canary ≤1 ack marker. **초과 감지 = post-spawn audit + HOLD.** (PreToolUse hook 으로 canonical 광역 write 차단 보강.)

### 12. legacy result.json / production queue 스캔 0 보장
- direct spawn 도 scan_once(root=대상, paths=[단일 result]) 경유 → canonical events 광역 비스캔. legacy 128 무변동. production queue 미터치.

### 13. rollback / cleanup / orphan process 처리
- S cron-remove(잔존 0). --message spawn 세션 = cokacdir 가 관리하는 세션 → 종료 확인(cron-history/process). **orphan**: --message 가 백그라운드 세션 남기면 감지(process scan)·정리. dedupe/done idempotent. temp/CODE 격리(canary). 실패 시 abort + 상태 복원.

### 14. regression / dry-run 검증 계획
- regression: ① OWNER_ANU 미확인→spawn 0 ② 비-ANU/stale/missing→spawn 0 ③ dedupe 중복→spawn 0 ④ scope/PreToolUse hook forbidden 차단 ⑤ argv/prompt raw key 0 ⑥ 머신러리 canonical write 0 ⑦ --message argv 구조 정합(--key flag·prompt body).
- dry-run: direct-launcher dry_run=True → 실 --message 미실행 + owner-proof/dedupe/scope 경로만(isolated temp).

### 15. real canary 재검증 조건
- 구현+PR merge 후 1회(반복 금지): ① `cokacdir --message` direct spawn 이 **quiet window 에서 inbound 없이 즉시 spawn**(activity-independent 실증) ② OWNER_ANU 검증 통과 ③ CANARY_ACK 수신 ④ ack 외 행동 0(read-only 탐색 허용·canonical write 0) ⑤ canonical write ≤1 ⑥ S 미발사·cleanup ⑦ duplicate 0 ⑧ raw key 0. → 충족 시 activity-independent fire VERIFIED.

### 16. production activation 전 남은 gate
1. direct-spawn(--message) activity-independent 실증(15).
2. --message 가 prompt/key 를 어떤 로그에 적재하는지 hygiene 확인(raw key 0).
3. owner-proof 보존 + self-collector 아님 최종 확인.
4. scope/hook/canonical write 상한 검증.
5. duplicate 0 + idempotent.
6. detection 트리거 결선(systemd path) 결정.
7. real wake activation 승인(ACTIVE flag/epoch) — 회장.
8. legacy 128 NOOP 재확인.

## 미해결 open question (구현 전 read-only 확인 필요)
- (a) `--message` 가 동기/activity-independent spawn 인가(canary 전 strings/문서 추가 확인).
- (b) `--message` 의 prompt/key 로그 적재 여부(hygiene).
- (c) `--message` inline vs isolated 모드 — wake 는 isolated 적합.

## 구현 범위 (회장 승인 후 별도 task)
- locus: `anu_pickup_wake_launcher.py`(--message direct 경로 추가, --cron 분기) + owner-proof 재사용 + PreToolUse hook settings. 신규 owner 로직 0. expected_files 최소(launcher + hook/settings + regression + report). 난이도 중-고(거버넌스·hook 결선).

## capability matrix
- direct_spawn_mechanism = COKACDIR_MESSAGE_FLAG_CANDIDATE (미검증 동기성).
- direct_spawn_hybrid = IMPLEMENTATION_READINESS_DESIGN (미구현).
- wake_fire_activity_independence = NOT_YET_VERIFIED.
- ACTIVE=false / production_activation_gate = HARD BLOCK.

## 금지 (현재)
production activation / ACTIVE=true / systemd 설치 / daemon restart / 추가 canary 실행 / production queue 처리 / direct spawn 구현 / PR 생성. **준비도 설계 packet 까지만.**

## 판정
- **DIRECT_SPAWN_HYBRID_IMPLEMENTATION_READINESS_PACKET_READY**. direct spawn = `cokacdir --message`(scheduler 우회 후보) + owner-proof = cron-history anchor S + fail-closed + scope/hook/dedupe. open question(a)(b)(c) 구현 전 read-only 확인 필요. 구현/canary = 회장 별도 승인.
