from pathlib import Path import re,json,hashlib,unicodedata as U,xml.etree.ElementTree as ET root=Path.cwd(); norm=lambda x:U.normalize('NFC',str(x)); sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest() keys=['손해배상건청구','손해배상기청구','손해배상산청구','손해배상언청구','손해배상의청구'] base=next(p for p in root.iterdir() if norm(p.name)=='1_사건종류_추가') beta=next(p for p in root.iterdir() if norm(p.name)=='1. 베타 0.5 다듬기') fmt=beta/'output_format_v1.txt'; prompt=next(p for p in beta.iterdir() if norm(p.name)=='prompt_v2재작성_1.txt') outdir=next(p for p in beta.iterdir() if norm(p.name)=='청구취지작성규칙문서정리') registry=root/'case_kind_registry.json'; reg=json.loads(registry.read_text()); xml=ET.fromstring(fmt.read_text()) req=[] def xmlwalk(e,x): if e.text and e.text.strip():req.append({'id':f'F{len(req)+1:03}', 'xpath':x,'text':e.text.strip()}) for k,v in e.attrib.items():req.append({'id':f'F{len(req)+1:03}', 'xpath':x+'/@'+k,'text':v}) counts={} for c in e: counts[c.tag]=counts.get(c.tag,0)+1;xmlwalk(c,x+'/'+c.tag+f'[{counts[c.tag]}]') xmlwalk(xml,'/output_format') for key in keys: p=next(p for p in base.rglob('*v2.md') if norm(p.name)==f'청구취지작성규칙_{key}_v2.md') matches=[(i,o['사건 종류']) for i,o in enumerate(reg) if ''.join(c for c in norm(o.get('사건 종류','')).strip() if U.category(c)[0] in 'LN')==key]; assert len(matches)==1 idx,display=matches[0]; w=root/'tmp'/f'규칙문서재작성_{key}_20260928_batch15b';w.mkdir(exist_ok=True) dest=outdir/f'청구취지작성규칙_{key}_beta_0.8.md' ident={'display_name':display,'registry_position':f'$[{idx}]','case_key':key,'source':str(p),'source_title':p.read_text().splitlines()[0],'output':str(dest),'output_title':f'# {display} — 청구취지 작성 규칙'} (w/'identity.json').write_text(json.dumps(ident,ensure_ascii=False,indent=2)) inputs=[{'path':str(q),'bytes':q.stat().st_size,'sha256':sha(q)} for q in [p,registry,fmt,prompt]] (w/'inputs.json').write_text(json.dumps(inputs,ensure_ascii=False,indent=2));(w/'source.snapshot.md').write_bytes(p.read_bytes()) (w/'format_requirements.json').write_text(json.dumps(req,ensure_ascii=False,indent=2)) plan='''# 손해배상 5건 독립 재작성 실행계획 ## Objective 건·기·산·언·의 각 v2를 해당 사건만의 beta_0.8로 재작성한다. ## Deliverables 각 지정 최종 Markdown 및 사건별 tmp 보존·형식·참조·변경·시나리오 대장. ## Scope and Non-Scope 법률 내용은 각 지정 v2만 사용. 외부 URL·v1·PDF 접근, 원본 수정, 커밋 제외. ## Known Inputs case_kind_registry.json, 각 사건의 1_사건종류_추가 하위 v2, 재작성 프롬프트 및 출력 형식 XML. ## Material Assumptions Unicode NFC 동등 경로만 대응. 원문 확인 상태는 승계 기록이다. ## Questions That Could Change the Outcome 현재 없음. 기존 출력 충돌은 작업본 보존으로 처리. ## Workstreams and Dependencies 각 사건 입력 고정 → 내용 분해 → 구조·상태 변환 → 종합 검증 1회 → 지적 수정 → 저장 확인. ## Source and Tool Plan 로컬 UTF-8 텍스트와 안전한 Python 파일 API만 사용. ## Validation Plan 사건별 양방향 내용·형식·참조·시나리오 종합 검증 각 1회. 수정 후 영향 범위만 확인. ## Approval Boundaries 기존 출력이 다르면 덮어쓰지 않는다. ## Progress - [x] 5건 원문 전문과 형식 XML 읽기 - [x] 입력 해시·사건 동일성 고정 - [ ] 재작성 - [ ] 1회 검증 및 수정 - [ ] 저장 확인 ## Decision Log | 단계 | 결정 | 근거 | 결과 | |---|---|---|---| | 설계 | 미확인 안전값을 제거하고 원래 대안은 자료상 근거가 있는 후보로 보존 | 형식 §1·§7 | 법적 전제 삭제 없이 상태 전환 | ## Evidence Ledger | 주장 | 근거 | 상태 | |---|---|---| | 사건별 법적 내용 | 해당 v2 | 원문 승계, 법률 원문 재검증 안 함 | ## Risks and Failure Modes 원문 내부 모순·미검증 승격, 주문에 설명 혼입, 광범위 출력 게이트를 점검한다. ## Results and Residual Uncertainty 작업 중. 실제 LLM 실행·법률 원문 재검증 제외. ''' (root/'tmp/damages_b_20260928/ExecPlan.md').write_text(plan) print('inputs fixed',len(req),'format requirements')