(function (root) { 'use strict'; const statuses = ['todo', 'doing', 'done', 'blocked']; function initial(plan) { return { schemaVersion: 1, planVersion: plan.planVersion, selected: [...plan.defaultSelected], settingsSelected: [], status: {}, notes: '', updatedAt: null }; } function validatePlan(plan) { const map = new Map(plan.features.map(f => [f.id, f])); if (map.size !== plan.features.length) throw new Error('중복 기능 ID'); const visiting = new Set(), visited = new Set(); function visit(id) { if (!map.has(id)) throw new Error('없는 선행 기능: ' + id); if (visiting.has(id)) throw new Error('순환 의존성: ' + id); if (visited.has(id)) return; visiting.add(id); map.get(id).dependencies.forEach(visit); visiting.delete(id); visited.add(id); } plan.features.forEach(f => visit(f.id)); return true; } function closure(plan, ids) { const map = new Map(plan.features.map(f => [f.id, f])); const seen = new Set(); function visit(id) { if (!map.has(id)) throw new Error('알 수 없는 기능 ID: ' + id); if (seen.has(id)) return; seen.add(id); map.get(id).dependencies.forEach(visit); } ids.forEach(visit); return plan.features.filter(f => seen.has(f.id)).map(f => f.id); } function normalize(plan, raw) { if (!raw || typeof raw !== 'object' || raw.schemaVersion !== 1 || (raw.planVersion !== plan.planVersion && !(plan.compatiblePlanVersions||[]).includes(raw.planVersion))) throw new Error('이 설계 버전과 일치하는 JSON을 선택하세요.'); if (!Array.isArray(raw.selected) || raw.selected.some(x => typeof x !== 'string')) throw new Error('선택 목록이 올바르지 않습니다.'); if (typeof raw.notes !== 'string' || raw.notes.length > 5000) throw new Error('메모는 5,000자 이하여야 합니다.'); if (!raw.status || typeof raw.status !== 'object' || Array.isArray(raw.status)) throw new Error('상태 정보가 올바르지 않습니다.'); const result = initial(plan); result.selected = closure(plan, raw.selected); result.notes = raw.notes; const settingMap = new Map((plan.settings?.settings||[]).map(s=>[s.id,s])); const picked=raw.settingsSelected===undefined?[]:raw.settingsSelected; if(!Array.isArray(picked)||picked.some(id=>typeof id!=='string'||!settingMap.has(id))) throw new Error('설정 옵션 목록이 올바르지 않습니다.'); result.settingsSelected=[...new Set(picked)]; result.selected=closure(plan,[...result.selected,...result.settingsSelected.map(id=>settingMap.get(id).feature)]); const ids = new Set(plan.features.map(f => f.id)); for (const [id, value] of Object.entries(raw.status)) { if (!ids.has(id) || !statuses.includes(value)) throw new Error('알 수 없는 기능 또는 상태: ' + id); result.status[id] = value; } result.updatedAt = typeof raw.updatedAt === 'string' ? raw.updatedAt : null; return result; } function toggle(plan, state, id, on) { if (!plan.features.some(f => f.id === id)) throw new Error('없는 기능'); const selected = new Set(state.selected); if (on) return { ...state, selected: closure(plan, [...selected, id]) }; selected.delete(id); let changed = true; while (changed) { changed = false; for (const f of plan.features) { if (selected.has(f.id) && f.dependencies.some(d => !selected.has(d))) { selected.delete(f.id); changed = true; } } } return { ...state, selected: plan.features.filter(f => selected.has(f.id)).map(f => f.id), settingsSelected:(state.settingsSelected||[]).filter(id=>selected.has(plan.settings.settings.find(s=>s.id===id)?.feature)) }; } function addScope(plan, state, ids) { return { ...state, selected: closure(plan, [...state.selected, ...ids]) }; } function summary(plan, state) { const selected = plan.features.filter(f => state.selected.includes(f.id)); const done = selected.filter(f => state.status[f.id] === 'done'); const inconsistent = done.filter(f => f.dependencies.some(d => state.status[d] !== 'done')); const ready = selected.filter(f => (state.status[f.id] || 'todo') !== 'done' && state.status[f.id] !== 'blocked' && f.dependencies.every(d => state.status[d] === 'done')); return { selected, done, inconsistent, ready, blocked: selected.filter(f => state.status[f.id] === 'blocked'), percent: selected.length ? Math.round(100 * done.length / selected.length) : 0 }; } function brief(plan, state, development) { const s = summary(plan, state); if (!s.selected.length) return '개발 범위가 비어 있습니다. 기능을 먼저 선택하세요.'; const lines = [ '# notParsec 개발 착수 지시', '', '설계 버전: ' + plan.planVersion, '작업 폴더: D:\\SoftwareDev\\notParsec', '우선 기준: AGENTS.md, design/PARSEC_PARITY.ko.md, design/parity-policy.json, design/NEXT_PARITY_IMPLEMENTATION.md', '근거 문서: design/ARCHITECTURE.ko.md, design/CONTROL_SERVER.ko.md, design/UI_TEXT_AUDIT.ko.md, design/SETTINGS_AND_RECOVERY.ko.md, design/plan-data.json', '', '개인용·비공개·비배포 Parsec 재현 프로그램을 Rust 중심으로 구현해줘.', ...(plan.parityPolicy?.handoffRules || []), '사용자 계정 가입·로그인·로그아웃은 구현하지 않는다. 접속 대상 PC별 비밀번호를 매 연결마다 입력하고 host가 검증한 뒤에만 영상·입력을 허용한다. 연결 관리 서버는 Ubuntu에서 실행한다.', '현재 QUIC 인증·egui GUI·서버 API는 기존 구현이다. 원본과의 일치나 예외 범위를 확인한 뒤 사용하고 자체 선택을 원본 아키텍처로 취급하지 않는다.', '아래 선택은 이번 작업 묶음이다. 최종 목표는 확인 가능한 원본 전체이며 미선택/MVP는 최종 제외 사유가 아니다. 확인된 구조 불일치의 교정을 우선한다.', '공개 코드뿐 아니라 디컴파일 기반 복구 C/Rust 로직도 범위에 포함한다. 원본 hash·함수 주소·추정 타입·이용 조건·검증 상태를 기록하고, 검증한 로직부터 자체 모듈로 통합해줘.', '원본 DLL 로딩이나 미검증 의사 코드의 즉시 링크를 기능 구현 완료로 취급하지 말고, Parsec의 계정/구독 검사를 변경하는 작업으로 대체하지 않는다.', '하드웨어를 요구하는 검증은 mock/단일 PC 시험으로 완료 처리하지 말고 미검증 조건을 기록해줘.', '기존 구현은 design/development-status.json과 VERIFICATION.md의 근거를 먼저 확인해 중복 작업을 피한다. 매 개발 작업 후 해당 기능의 구현·검증·통합 상태, 남은 작업, 근거와 확인일을 갱신하고 python design/build_plan.py로 HTML을 다시 생성해줘.', 'F44/F45는 원본 대응 부품 조사다. 다른 제품으로의 전환이나 새로운 사용자 기능 도입을 허용하지 않는다.', '', '선택 ID: ' + state.selected.join(', '), '기록상 완료: ' + (s.done.map(f => f.id).join(', ') || '없음'), '착수 가능한 항목: ' + (s.ready.map(f => f.id).join(', ') || '없음 — 선행 상태 또는 차단 사유 확인'), '차단 표시: ' + (s.blocked.map(f => f.id).join(', ') || '없음'), '완료 표시는 사용자 기록이므로 실제 코드·시험 근거를 확인할 것.', '' ]; if (development) { lines.push('구현 기록 기준: ' + development.updatedAt + ' / ' + development.revision, development.summary); for (const f of s.selected.filter(f => development.features[f.id]?.state !== 'todo')) { const r = development.features[f.id]; lines.push('구현 기록 ' + f.id + ': ' + r.state + ' — ' + r.summary, '원본 대조: ' + (r.parity?.status || 'unreviewed'), '남은 작업: ' + r.remaining.join(' / ')); } lines.push('위 구현 기록은 사용자 수동 상태와 별도이며 최신 코드·시험 결과로 확인할 것.', ''); } if ((plan.serverPlan?.featureIds||[]).some(id => state.selected.includes(id))) lines.push( '연결 관리 서버는 선택된 F71–F79와 CONTROL_SERVER.ko.md의 API·DB·권한·WSS·ticket·운영 계약에 따라 Rust로 구현한다.', '홈서버 공인 IP·UDP 포트포워딩 가능 조건을 사용한다. F32 자동 NAT와 F33 relay는 선택됐을 때 구현하며, 명시 endpoint/개인 VPN 경로만으로 먼저 통합 시험할 수 있다.', '서버의 실제 두 PC·외부 회선 시험과 백업 복원 결과를 별도로 보고하고 API mock 성공만으로 F79를 완료 표시하지 않는다.', ''); if (s.inconsistent.length) lines.push('선행 기능 미완료인데 완료로 기록된 항목: ' + s.inconsistent.map(f => f.id).join(', '), ''); for (const phase of plan.phases) { const list = s.selected.filter(f => f.phase === phase.id); if (!list.length) continue; lines.push('## ' + phase.id + ' ' + phase.title, ''); for (const f of list) { lines.push('- [' + (state.status[f.id] === 'done' ? 'x' : ' ') + '] ' + f.id + ' ' + f.title, ' 상태: ' + (state.status[f.id] || 'todo') + '; 선행: ' + (f.dependencies.join(', ') || '없음'), ' 역할: ' + f.description, ' 완료 기준: ' + f.acceptance.join(' / ')); } lines.push(''); } if (state.notes.trim()) lines.push('## 추가 요구사항', '', state.notes.trim(), ''); const options=(plan.settings?.settings||[]).filter(s=>(state.settingsSelected||[]).includes(s.id)); if(options.length){lines.push('## 명시적으로 선택한 설정·감사 항목', '');for(const o of options)lines.push('- '+o.id+' — '+o.label+' / '+o.feature+' / '+o.handling+' / '+o.description);lines.push('원본 static default와 실제 유효값을 구분하고, unsupported/내부 상태도 묵살하지 말고 판정해줘.','');} lines.push('각 마일스톤이 끝나면 실제 완료한 ID, 검증 결과, 아직 미검증인 장치·조건을 보고해줘.'); return lines.join('\n'); } const api = { initial, normalize, closure, toggle, addScope, summary, brief, validatePlan, statuses }; if (typeof module !== 'undefined' && module.exports) module.exports = api; root.PlanCore = api; })(globalThis);